Index: include/llvm/DebugInfo/DWARF/DWARFVerifier.h =================================================================== --- include/llvm/DebugInfo/DWARF/DWARFVerifier.h +++ include/llvm/DebugInfo/DWARF/DWARFVerifier.h @@ -50,14 +50,16 @@ /// \param Offset A reference to the offset start of the unit. The offset will /// be updated to point to the next unit in .debug_info /// \param UnitIndex The index of the unit to be verified + /// \param UnitType A reference to the type of the unit /// \param isUnitDWARF64 A reference to a flag that shows whether the unit is /// in 64-bit format. /// /// \returns true if the header is verified successfully, false otherwise. bool verifyUnitHeader(const DWARFDataExtractor DebugInfoData, - uint32_t *Offset, unsigned UnitIndex, + uint32_t *Offset, unsigned UnitIndex, uint8_t &UnitType, bool &isUnitDWARF64); + bool verifyUnitContents(DWARFUnit Unit); /// Verifies the attribute's DWARF attribute and its value. /// /// This function currently checks for: @@ -102,14 +104,6 @@ public: DWARFVerifier(raw_ostream &S, DWARFContext &D) : OS(S), DCtx(D) {} - /// Verify the unit header chain in the .debug_info section. - /// - /// Any errors are reported to the stream that this object was - /// constructed with. - /// - /// \returns true if the unit header chain verifies successfully, false - /// otherwise. - bool handleDebugInfoUnitHeaderChain(); /// Verify the information in the .debug_info section. /// /// Any errors are reported to the stream that was this object was Index: lib/DebugInfo/DWARF/DWARFContext.cpp =================================================================== --- lib/DebugInfo/DWARF/DWARFContext.cpp +++ lib/DebugInfo/DWARF/DWARFContext.cpp @@ -414,8 +414,6 @@ bool DWARFContext::verify(raw_ostream &OS, DIDumpType DumpType) { bool Success = true; DWARFVerifier verifier(OS, *this); - if (!verifier.handleDebugInfoUnitHeaderChain()) - Success = false; if (DumpType == DIDT_All || DumpType == DIDT_Info) { if (!verifier.handleDebugInfo()) Success = false; Index: lib/DebugInfo/DWARF/DWARFVerifier.cpp =================================================================== --- lib/DebugInfo/DWARF/DWARFVerifier.cpp +++ lib/DebugInfo/DWARF/DWARFVerifier.cpp @@ -25,10 +25,10 @@ using namespace object; bool DWARFVerifier::verifyUnitHeader(const DWARFDataExtractor DebugInfoData, - uint32_t *Offset, unsigned UnitIndex, - bool &isUnitDWARF64) { + uint32_t *Offset, unsigned UnitIndex, + uint8_t &UnitType, bool &isUnitDWARF64) { uint32_t AbbrOffset, Length; - uint8_t AddrSize = 0, UnitType = 0; + uint8_t AddrSize = 0; uint16_t Version; bool Success = true; @@ -86,20 +86,68 @@ return Success; } -bool DWARFVerifier::handleDebugInfoUnitHeaderChain() { +bool DWARFVerifier::verifyUnitContents(DWARFUnit Unit) { + unsigned NumDies = Unit.getNumDIEs(); + for (unsigned I = 0; I < NumDies; ++I) { + auto Die = Unit.getDIEAtIndex(I); + const auto Tag = Die.getTag(); + if (Tag == DW_TAG_null) + continue; + for (auto AttrValue : Die.attributes()) { + verifyDebugInfoAttribute(Die, AttrValue); + verifyDebugInfoForm(Die, AttrValue); + } + } + return NumDebugInfoErrors == 0; +} + +bool DWARFVerifier::handleDebugInfo() { OS << "Verifying .debug_info Unit Header Chain...\n"; + NumDebugInfoErrors = 0; + DWARFDataExtractor DebugInfoData(DCtx.getInfoSection(), DCtx.isLittleEndian(), 0); - uint32_t Offset = 0, UnitIdx = 0; + uint32_t OffsetStart = 0, Offset = 0, UnitIdx = 0; + uint8_t UnitType = 0; bool isUnitDWARF64 = false; bool Success = true; bool hasDIE = DebugInfoData.isValidOffset(Offset); while (hasDIE) { - if (!verifyUnitHeader(DebugInfoData, &Offset, UnitIdx, isUnitDWARF64)) { + if (!verifyUnitHeader(DebugInfoData, &Offset, UnitIdx, UnitType, isUnitDWARF64)) { Success = false; if (isUnitDWARF64) break; + } else { + std::unique_ptr Unit; + switch (UnitType) { + case dwarf::DW_UT_type: + case dwarf::DW_UT_split_type: { + DWARFUnitSection TUSection{}; + Unit.reset(new DWARFTypeUnit( + DCtx, DCtx.getInfoSection(), DCtx.getDebugAbbrev(), + &DCtx.getRangeSection(), DCtx.getStringSection(), + DCtx.getStringOffsetSection(), &DCtx.getAppleObjCSection(), + DCtx.getLineSection(), DCtx.isLittleEndian(), false, TUSection, + nullptr)); + break; + } + case dwarf::DW_UT_skeleton: + case dwarf::DW_UT_split_compile: + case dwarf::DW_UT_compile: + case dwarf::DW_UT_partial: + default: { + DWARFUnitSection CUSection{}; + Unit.reset(new DWARFCompileUnit( + DCtx, DCtx.getInfoSection(), DCtx.getDebugAbbrev(), + &DCtx.getRangeSection(), DCtx.getStringSection(), + DCtx.getStringOffsetSection(), &DCtx.getAppleObjCSection(), + DCtx.getLineSection(), DCtx.isLittleEndian(), false, CUSection, + nullptr)); + } + } + Unit->extract(DebugInfoData, &OffsetStart); + Success = verifyUnitContents(*Unit); } hasDIE = DebugInfoData.isValidOffset(Offset); ++UnitIdx; @@ -108,7 +156,8 @@ OS << "Warning: .debug_info is empty.\n"; Success = true; } - return Success; + verifyDebugInfoReferences(); + return (Success && NumDebugInfoErrors == 0); } void DWARFVerifier::verifyDebugInfoAttribute(const DWARFDie &Die, @@ -244,26 +293,6 @@ } } -bool DWARFVerifier::handleDebugInfo() { - NumDebugInfoErrors = 0; - OS << "Verifying .debug_info...\n"; - for (const auto &CU : DCtx.compile_units()) { - unsigned NumDies = CU->getNumDIEs(); - for (unsigned I = 0; I < NumDies; ++I) { - auto Die = CU->getDIEAtIndex(I); - const auto Tag = Die.getTag(); - if (Tag == DW_TAG_null) - continue; - for (auto AttrValue : Die.attributes()) { - verifyDebugInfoAttribute(Die, AttrValue); - verifyDebugInfoForm(Die, AttrValue); - } - } - } - verifyDebugInfoReferences(); - return NumDebugInfoErrors == 0; -} - void DWARFVerifier::verifyDebugLineStmtOffsets() { std::map StmtListToDie; for (const auto &CU : DCtx.compile_units()) {