27 using namespace dwarf;
32 auto Begin = Ranges.begin();
33 auto End = Ranges.end();
37 if (Pos->intersects(R))
41 if (Iter->intersects(R))
46 Ranges.insert(Pos, R);
52 auto End = Children.end();
53 auto Iter = Children.begin();
55 if (Iter->intersects(RI))
60 return Children.end();
66 if (Ranges.empty() || RHS.
Ranges.empty())
71 auto End = Ranges.end();
72 auto Iter = findRange(RHS.
Ranges.front());
76 for (
const auto &R : RHS.
Ranges) {
78 if (Iter->contains(R))
89 if (Ranges.empty() || RHS.
Ranges.empty())
92 auto End = Ranges.end();
93 auto Iter = findRange(RHS.
Ranges.front());
94 for (
const auto &R : RHS.
Ranges) {
97 if (R.HighPC <= Iter->LowPC)
100 if (Iter->intersects(R))
111 uint8_t &
UnitType,
bool &isUnitDWARF64) {
113 uint8_t AddrSize = 0;
117 bool ValidLength =
false;
118 bool ValidVersion =
false;
119 bool ValidAddrSize =
false;
120 bool ValidType =
true;
121 bool ValidAbbrevOffset =
true;
124 Length = DebugInfoData.
getU32(Offset);
125 if (Length == UINT32_MAX) {
126 isUnitDWARF64 =
true;
128 "Unit[%d] is in 64-bit DWARF format; cannot verify from this point.\n",
132 Version = DebugInfoData.
getU16(Offset);
136 AddrSize = DebugInfoData.
getU8(Offset);
137 AbbrOffset = DebugInfoData.
getU32(Offset);
141 AbbrOffset = DebugInfoData.
getU32(Offset);
142 AddrSize = DebugInfoData.
getU8(Offset);
145 if (!DCtx.getDebugAbbrev()->getAbbreviationDeclarationSet(AbbrOffset))
146 ValidAbbrevOffset =
false;
148 ValidLength = DebugInfoData.
isValidOffset(OffsetStart + Length + 3);
150 ValidAddrSize = AddrSize == 4 || AddrSize == 8;
151 if (!ValidLength || !ValidVersion || !ValidAddrSize || !ValidAbbrevOffset ||
154 error() <<
format(
"Units[%d] - start offset: 0x%08x \n", UnitIndex,
157 note() <<
"The length for this unit is too " 158 "large for the .debug_info provided.\n";
160 note() <<
"The 16 bit unit header version is not valid.\n";
162 note() <<
"The unit type encoding is not valid.\n";
163 if (!ValidAbbrevOffset)
164 note() <<
"The offset into the .debug_abbrev section is " 167 note() <<
"The address size is unsupported.\n";
169 *Offset = OffsetStart + Length + 4;
173 unsigned DWARFVerifier::verifyUnitContents(
DWARFUnit &
Unit) {
174 unsigned NumUnitErrors = 0;
176 for (
unsigned I = 0;
I < NumDies; ++
I) {
179 if (Die.getTag() == DW_TAG_null)
182 bool HasTypeAttr =
false;
183 for (
auto AttrValue : Die.attributes()) {
184 NumUnitErrors += verifyDebugInfoAttribute(Die, AttrValue);
185 NumUnitErrors += verifyDebugInfoForm(Die, AttrValue);
186 HasTypeAttr |= (AttrValue.Attr == DW_AT_type);
189 if (!HasTypeAttr && (Die.getTag() == DW_TAG_formal_parameter ||
190 Die.getTag() == DW_TAG_variable ||
191 Die.getTag() == DW_TAG_array_type)) {
193 <<
" is missing type attribute:\n";
197 NumUnitErrors += verifyDebugInfoCallSite(Die);
202 error() <<
"Compilation unit without DIE.\n";
204 return NumUnitErrors;
208 error() <<
"Compilation unit root DIE is not a unit DIE: " 217 <<
") do not match.\n";
222 NumUnitErrors += verifyDieRanges(Die, RI);
224 return NumUnitErrors;
227 unsigned DWARFVerifier::verifyDebugInfoCallSite(
const DWARFDie &Die) {
228 if (Die.
getTag() != DW_TAG_call_site)
233 if (Curr.
getTag() == DW_TAG_inlined_subroutine) {
234 error() <<
"Call site entry nested within inlined subroutine:";
241 error() <<
"Call site entry not nested within a valid subprogram:";
247 Curr.
find({DW_AT_call_all_calls, DW_AT_call_all_source_calls,
248 DW_AT_call_all_tail_calls});
250 error() <<
"Subprogram with call site entry has no DW_AT_call attribute:";
259 unsigned DWARFVerifier::verifyAbbrevSection(
const DWARFDebugAbbrev *Abbrev) {
260 unsigned NumErrors = 0;
264 for (
auto AbbrDecl : *AbbrDecls) {
266 for (
auto Attribute : AbbrDecl.attributes()) {
268 if (!Result.second) {
269 error() <<
"Abbreviation declaration contains multiple " 281 OS <<
"Verifying .debug_abbrev...\n";
287 if (noDebugAbbrev && noDebugAbbrevDWO) {
291 unsigned NumErrors = 0;
293 NumErrors += verifyAbbrevSection(DCtx.getDebugAbbrev());
295 if (!noDebugAbbrevDWO)
296 NumErrors += verifyAbbrevSection(DCtx.getDebugAbbrevDWO());
297 return NumErrors == 0;
300 unsigned DWARFVerifier::verifyUnitSection(
const DWARFSection &S,
304 unsigned NumDebugInfoErrors = 0;
305 uint32_t OffsetStart = 0, Offset = 0, UnitIdx = 0;
307 bool isUnitDWARF64 =
false;
308 bool isHeaderChainValid =
true;
314 if (!verifyUnitHeader(DebugInfoData, &Offset, UnitIdx, UnitType,
316 isHeaderChainValid =
false;
321 Header.
extract(DCtx, DebugInfoData, &OffsetStart, SectionKind);
324 case dwarf::DW_UT_type:
325 case dwarf::DW_UT_split_type: {
326 Unit = TypeUnitVector.
addUnit(llvm::make_unique<DWARFTypeUnit>(
334 case dwarf::DW_UT_skeleton:
335 case dwarf::DW_UT_split_compile:
336 case dwarf::DW_UT_compile:
337 case dwarf::DW_UT_partial:
340 Unit = CompileUnitVector.
addUnit(llvm::make_unique<DWARFCompileUnit>(
350 NumDebugInfoErrors += verifyUnitContents(*Unit);
355 if (UnitIdx == 0 && !hasDIE) {
356 warn() <<
"Section is empty.\n";
357 isHeaderChainValid =
true;
359 if (!isHeaderChainValid)
360 ++NumDebugInfoErrors;
361 NumDebugInfoErrors += verifyDebugInfoReferences();
362 return NumDebugInfoErrors;
367 unsigned NumErrors = 0;
369 OS <<
"Verifying .debug_info Unit Header Chain...\n";
374 OS <<
"Verifying .debug_types Unit Header Chain...\n";
378 return NumErrors == 0;
381 unsigned DWARFVerifier::verifyDieRanges(
const DWARFDie &Die,
383 unsigned NumErrors = 0;
389 if (!RangesOrError) {
420 if (!IsObjectFile || IsMachOObject || Die.
getTag() != DW_TAG_compile_unit) {
421 for (
auto Range : Ranges) {
422 if (!Range.valid()) {
424 error() <<
"Invalid address range " << Range <<
"\n";
429 const auto IntersectingRange = RI.
insert(Range);
430 if (IntersectingRange != RI.
Ranges.end()) {
432 error() <<
"DIE has overlapping address ranges: " << Range <<
" and " 433 << *IntersectingRange <<
"\n";
440 const auto IntersectingChild = ParentRI.
insert(RI);
441 if (IntersectingChild != ParentRI.
Children.end()) {
443 error() <<
"DIEs have overlapping address ranges:";
445 dump(IntersectingChild->Die) <<
'\n';
449 bool ShouldBeContained = !Ranges.empty() && !ParentRI.
Ranges.empty() &&
450 !(Die.
getTag() == DW_TAG_subprogram &&
451 ParentRI.
Die.
getTag() == DW_TAG_subprogram);
452 if (ShouldBeContained && !ParentRI.
contains(RI)) {
454 error() <<
"DIE address ranges are not contained in its parent's ranges:";
456 dump(Die, 2) <<
'\n';
461 NumErrors += verifyDieRanges(Child, RI);
466 unsigned DWARFVerifier::verifyDebugInfoAttribute(
const DWARFDie &Die,
468 unsigned NumErrors = 0;
471 error() << TitleMsg <<
'\n';
476 const auto Attr = AttrValue.
Attr;
482 ReportError(
"DW_AT_ranges offset is beyond .debug_ranges bounds:");
485 ReportError(
"DIE has invalid DW_AT_ranges encoding:");
487 case DW_AT_stmt_list:
491 ReportError(
"DW_AT_stmt_list offset is beyond .debug_line bounds: " +
495 ReportError(
"DIE has invalid DW_AT_stmt_list encoding:");
497 case DW_AT_location: {
507 ReportError(
"DIE contains invalid DWARF expression:");
514 if (
auto DebugLoc = DCtx.getDebugLoc())
515 if (
auto LocList =
DebugLoc->getLocationListAtOffset(*LocOffset))
516 for (
const auto &Entry : LocList->Entries)
517 VerifyLocationExpr({Entry.Loc.data(), Entry.Loc.size()});
521 case DW_AT_specification:
522 case DW_AT_abstract_origin: {
524 auto DieTag = Die.
getTag();
525 auto RefTag = ReferencedDie.getTag();
526 if (DieTag == RefTag)
528 if (DieTag == DW_TAG_inlined_subroutine && RefTag == DW_TAG_subprogram)
530 if (DieTag == DW_TAG_variable && RefTag == DW_TAG_member)
534 " that points to DIE with " 535 "incompatible tag " +
554 unsigned DWARFVerifier::verifyDebugInfoForm(
const DWARFDie &Die,
558 unsigned NumErrors = 0;
565 case DW_FORM_ref_udata: {
570 auto CUSize = DieCU->getNextUnitOffset() - DieCU->getOffset();
572 if (CUOffset >= CUSize) {
575 <<
format(
"0x%08" PRIx64, CUOffset)
576 <<
" is invalid (must be less than CU size of " 577 <<
format(
"0x%08" PRIx32, CUSize) <<
"):\n";
578 Die.
dump(OS, 0, DumpOpts);
583 ReferenceToDIEOffsets[*RefVal].insert(Die.
getOffset());
588 case DW_FORM_ref_addr: {
594 if (*RefVal >= DieCU->getInfoSection().Data.size()) {
596 error() <<
"DW_FORM_ref_addr offset beyond .debug_info " 602 ReferenceToDIEOffsets[*RefVal].insert(Die.
getOffset());
612 error() <<
"DW_FORM_strp offset beyond .debug_str bounds:\n";
621 case DW_FORM_strx4: {
625 if (!DieCU->getStringOffsetsTableContribution()) {
628 <<
" used without a valid string offsets table:\n";
633 unsigned ItemSize = DieCU->getDwarfStringOffsetsByteSize();
636 (uint64_t)DieCU->getStringOffsetsBase() +
Index * ItemSize;
640 <<
format(
"%" PRIu64,
Index) <<
", which is too large:\n";
645 uint64_t StringOffset = *DieCU->getStringOffsetSectionItem(
Index);
650 <<
", but the referenced string" 651 " offset is beyond .debug_str bounds:\n";
662 unsigned DWARFVerifier::verifyDebugInfoReferences() {
665 OS <<
"Verifying .debug_info references...\n";
666 unsigned NumErrors = 0;
667 for (
auto Pair : ReferenceToDIEOffsets) {
668 auto Die = DCtx.getDIEForOffset(Pair.first);
672 error() <<
"invalid DIE reference " <<
format(
"0x%08" PRIx64, Pair.first)
673 <<
". Offset is in between DIEs:\n";
674 for (
auto Offset : Pair.second)
675 dump(DCtx.getDIEForOffset(Offset)) <<
'\n';
681 void DWARFVerifier::verifyDebugLineStmtOffsets() {
682 std::map<uint64_t, DWARFDie> StmtListToDie;
683 for (
const auto &
CU : DCtx.compile_units()) {
684 auto Die =
CU->getUnitDIE();
689 if (!StmtSectionOffset)
691 const uint32_t LineTableOffset = *StmtSectionOffset;
692 auto LineTable = DCtx.getLineTableForUnit(
CU.get());
693 if (LineTableOffset < DCtx.getDWARFObj().getLineSection().Data.size()) {
695 ++NumDebugLineErrors;
696 error() <<
".debug_line[" <<
format(
"0x%08" PRIx32, LineTableOffset)
697 <<
"] was not able to be parsed for CU:\n";
703 assert(LineTable ==
nullptr);
708 auto Iter = StmtListToDie.find(LineTableOffset);
709 if (Iter != StmtListToDie.end()) {
710 ++NumDebugLineErrors;
711 error() <<
"two compile unit DIEs, " 712 <<
format(
"0x%08" PRIx32, Iter->second.getOffset()) <<
" and " 714 <<
", have the same DW_AT_stmt_list section offset:\n";
720 StmtListToDie[LineTableOffset] = Die;
724 void DWARFVerifier::verifyDebugLineRows() {
725 for (
const auto &
CU : DCtx.compile_units()) {
726 auto Die =
CU->getUnitDIE();
727 auto LineTable = DCtx.getLineTableForUnit(
CU.get());
734 uint32_t MaxFileIndex = LineTable->Prologue.FileNames.size();
735 uint32_t MaxDirIndex = LineTable->Prologue.IncludeDirectories.size();
738 for (
const auto &FileName : LineTable->Prologue.FileNames) {
740 if (FileName.DirIdx > MaxDirIndex) {
741 ++NumDebugLineErrors;
742 error() <<
".debug_line[" 745 <<
"].prologue.file_names[" << FileIndex
746 <<
"].dir_idx contains an invalid index: " << FileName.DirIdx
751 std::string FullPath;
752 const bool HasFullPath = LineTable->getFileNameByIndex(
753 FileIndex,
CU->getCompilationDir(),
755 assert(HasFullPath &&
"Invalid index?");
757 auto It = FullPathMap.
find(FullPath);
758 if (It == FullPathMap.
end())
759 FullPathMap[FullPath] = FileIndex;
760 else if (It->second != FileIndex) {
761 warn() <<
".debug_line[" 764 <<
"].prologue.file_names[" << FileIndex
765 <<
"] is a duplicate of file_names[" << It->second <<
"]\n";
772 uint64_t PrevAddress = 0;
774 for (
const auto &Row : LineTable->Rows) {
776 if (Row.Address < PrevAddress) {
777 ++NumDebugLineErrors;
778 error() <<
".debug_line[" 781 <<
"] row[" << RowIndex
782 <<
"] decreases in address from previous row:\n";
786 LineTable->Rows[RowIndex - 1].dump(OS);
792 if (Row.File > MaxFileIndex) {
793 ++NumDebugLineErrors;
794 error() <<
".debug_line[" 797 <<
"][" << RowIndex <<
"] has invalid file index " << Row.File
798 <<
" (valid values are [1," << MaxFileIndex <<
"]):\n";
806 PrevAddress = Row.Address;
814 : OS(S), DCtx(D), DumpOpts(
std::move(DumpOpts)), IsObjectFile(
false),
815 IsMachOObject(
false) {
817 IsObjectFile =
F->isRelocatableObject();
818 IsMachOObject =
F->isMachO();
823 NumDebugLineErrors = 0;
824 OS <<
"Verifying .debug_line...\n";
825 verifyDebugLineStmtOffsets();
826 verifyDebugLineRows();
827 return NumDebugLineErrors == 0;
830 unsigned DWARFVerifier::verifyAppleAccelTable(
const DWARFSection *AccelSection,
833 unsigned NumErrors = 0;
838 OS <<
"Verifying " << SectionName <<
"...\n";
841 if (!AccelSectionData.isValidOffset(AccelTable.getSizeHdr())) {
842 error() <<
"Section is too small to fit a section header.\n";
847 if (
Error E = AccelTable.extract()) {
848 error() <<
toString(std::move(
E)) <<
'\n';
853 uint32_t NumBuckets = AccelTable.getNumBuckets();
854 uint32_t NumHashes = AccelTable.getNumHashes();
857 AccelTable.getSizeHdr() + AccelTable.getHeaderDataLength();
858 uint32_t HashesBase = BucketsOffset + NumBuckets * 4;
859 uint32_t OffsetsBase = HashesBase + NumHashes * 4;
860 for (
uint32_t BucketIdx = 0; BucketIdx < NumBuckets; ++BucketIdx) {
861 uint32_t HashIdx = AccelSectionData.getU32(&BucketsOffset);
862 if (HashIdx >= NumHashes && HashIdx != UINT32_MAX) {
863 error() <<
format(
"Bucket[%d] has invalid hash index: %u.\n", BucketIdx,
868 uint32_t NumAtoms = AccelTable.getAtomsDesc().size();
870 error() <<
"No atoms: failed to read HashData.\n";
873 if (!AccelTable.validateForms()) {
874 error() <<
"Unsupported form: failed to read HashData.\n";
878 for (
uint32_t HashIdx = 0; HashIdx < NumHashes; ++HashIdx) {
879 uint32_t HashOffset = HashesBase + 4 * HashIdx;
880 uint32_t DataOffset = OffsetsBase + 4 * HashIdx;
881 uint32_t Hash = AccelSectionData.getU32(&HashOffset);
882 uint32_t HashDataOffset = AccelSectionData.getU32(&DataOffset);
883 if (!AccelSectionData.isValidOffsetForDataOfSize(HashDataOffset,
885 error() <<
format(
"Hash[%d] has invalid HashData offset: 0x%08x.\n",
886 HashIdx, HashDataOffset);
895 while ((StrpOffset = AccelSectionData.getU32(&HashDataOffset)) != 0) {
897 AccelSectionData.getU32(&HashDataOffset);
898 for (
uint32_t HashDataIdx = 0; HashDataIdx < NumHashDataObjects;
900 std::tie(Offset, Tag) = AccelTable.readAtoms(HashDataOffset);
904 NumBuckets ? (Hash % NumBuckets) : UINT32_MAX;
905 StringOffset = StrpOffset;
906 const char *
Name = StrData->
getCStr(&StringOffset);
911 "%s Bucket[%d] Hash[%d] = 0x%08x " 913 "DIE[%d] = 0x%08x is not a valid DIE offset for \"%s\".\n",
914 SectionName, BucketIdx, HashIdx, Hash, StringCount, StrpOffset,
915 HashDataIdx, Offset, Name);
920 if ((Tag != dwarf::DW_TAG_null) && (Die.
getTag() !=
Tag)) {
922 <<
" in accelerator table does not match Tag " 943 CUMap[
CU->getOffset()] = NotIndexed;
945 unsigned NumErrors = 0;
947 if (NI.getCUCount() == 0) {
948 error() <<
formatv(
"Name Index @ {0:x} does not index any CU\n",
955 auto Iter = CUMap.
find(Offset);
957 if (Iter == CUMap.
end()) {
959 "Name Index @ {0:x} references a non-existing CU @ {1:x}\n",
960 NI.getUnitOffset(),
Offset);
965 if (Iter->second != NotIndexed) {
966 error() <<
formatv(
"Name Index @ {0:x} references a CU @ {1:x}, but " 967 "this CU is already indexed by Name Index @ {2:x}\n",
968 NI.getUnitOffset(),
Offset, Iter->second);
971 Iter->second = NI.getUnitOffset();
975 for (
const auto &KV : CUMap) {
976 if (KV.second == NotIndexed)
977 warn() <<
formatv(
"CU @ {0:x} not covered by any Name Index\n", KV.first);
991 : Bucket(Bucket),
Index(Index) {}
992 bool operator<(
const BucketInfo &RHS)
const {
return Index < RHS.Index; };
997 warn() <<
formatv(
"Name Index @ {0:x} does not contain a hash table.\n",
1004 std::vector<BucketInfo> BucketStarts;
1009 error() <<
formatv(
"Bucket {0} of Name Index @ {1:x} contains invalid " 1010 "value {2}. Valid range is [0, {3}].\n",
1016 BucketStarts.emplace_back(Bucket, Index);
1036 for (
const BucketInfo &
B : BucketStarts) {
1043 if (
B.Index > NextUncovered) {
1044 error() <<
formatv(
"Name Index @ {0:x}: Name table entries [{1}, {2}] " 1045 "are not covered by the hash table.\n",
1063 "Name Index @ {0:x}: Bucket {1} is not empty but points to a " 1064 "mismatched hash value {2:x} (belonging to bucket {3}).\n",
1080 error() <<
formatv(
"Name Index @ {0:x}: String ({1}) at index {2} " 1081 "hashes to {3:x}, but " 1082 "the Name Index hash is {4:x}\n",
1090 NextUncovered =
std::max(NextUncovered, Idx);
1095 unsigned DWARFVerifier::verifyNameIndexAttribute(
1099 if (FormName.
empty()) {
1100 error() <<
formatv(
"NameIndex @ {0:x}: Abbreviation {1:x}: {2} uses an " 1101 "unknown form: {3}.\n",
1107 if (AttrEnc.
Index == DW_IDX_type_hash) {
1108 if (AttrEnc.
Form != dwarf::DW_FORM_data8) {
1110 "NameIndex @ {0:x}: Abbreviation {1:x}: DW_IDX_type_hash " 1111 "uses an unexpected form {2} (should be {3}).\n",
1120 struct FormClassTable {
1125 static constexpr FormClassTable Table[] = {
1133 auto Iter =
find_if(TableRef, [AttrEnc](
const FormClassTable &
T) {
1134 return T.Index == AttrEnc.
Index;
1136 if (Iter == TableRef.
end()) {
1137 warn() <<
formatv(
"NameIndex @ {0:x}: Abbreviation {1:x} contains an " 1138 "unknown index attribute: {2}.\n",
1144 error() <<
formatv(
"NameIndex @ {0:x}: Abbreviation {1:x}: {2} uses an " 1145 "unexpected form {3} (expected form class {4}).\n",
1147 AttrEnc.
Form, Iter->ClassName);
1156 warn() <<
formatv(
"Name Index @ {0:x}: Verifying indexes of type units is " 1157 "not currently supported.\n",
1162 unsigned NumErrors = 0;
1165 if (TagName.
empty()) {
1166 warn() <<
formatv(
"NameIndex @ {0:x}: Abbreviation {1:x} references an " 1167 "unknown tag: {2}.\n",
1171 for (
const auto &AttrEnc : Abbrev.Attributes) {
1172 if (!Attributes.insert(AttrEnc.
Index).second) {
1173 error() <<
formatv(
"NameIndex @ {0:x}: Abbreviation {1:x} contains " 1174 "multiple {2} attributes.\n",
1179 NumErrors += verifyNameIndexAttribute(NI, Abbrev, AttrEnc);
1182 if (NI.
getCUCount() > 1 && !Attributes.count(dwarf::DW_IDX_compile_unit)) {
1183 error() <<
formatv(
"NameIndex @ {0:x}: Indexing multiple compile units " 1184 "and abbreviation {1:x} has no {2} attribute.\n",
1186 dwarf::DW_IDX_compile_unit);
1189 if (!Attributes.count(dwarf::DW_IDX_die_offset)) {
1191 "NameIndex @ {0:x}: Abbreviation {1:x} has no {2} attribute.\n",
1200 bool IncludeLinkageName =
true) {
1204 else if (DIE.
getTag() == dwarf::DW_TAG_namespace)
1207 if (IncludeLinkageName) {
1209 if (Result.
empty() || Result[0] != Str)
1217 unsigned DWARFVerifier::verifyNameIndexEntries(
1227 "Name Index @ {0:x}: Unable to get string associated with name {1}.\n",
1233 unsigned NumErrors = 0;
1234 unsigned NumEntries = 0;
1238 for (; EntryOr; ++NumEntries, EntryID = NextEntryID,
1239 EntryOr = NI.
getEntry(&NextEntryID)) {
1240 uint32_t CUIndex = *EntryOr->getCUIndex();
1242 error() <<
formatv(
"Name Index @ {0:x}: Entry @ {1:x} contains an " 1243 "invalid CU index ({2}).\n",
1249 uint64_t DIEOffset = CUOffset + *EntryOr->getDIEUnitOffset();
1252 error() <<
formatv(
"Name Index @ {0:x}: Entry @ {1:x} references a " 1253 "non-existing DIE @ {2:x}.\n",
1259 error() <<
formatv(
"Name Index @ {0:x}: Entry @ {1:x}: mismatched CU of " 1260 "DIE @ {2:x}: index - {3:x}; debug_info - {4:x}.\n",
1265 if (DIE.
getTag() != EntryOr->tag()) {
1266 error() <<
formatv(
"Name Index @ {0:x}: Entry @ {1:x}: mismatched Tag of " 1267 "DIE @ {2:x}: index - {3}; debug_info - {4}.\n",
1275 error() <<
formatv(
"Name Index @ {0:x}: Entry @ {1:x}: mismatched Name " 1276 "of DIE @ {2:x}: index - {3}; debug_info - {4}.\n",
1278 make_range(EntryNames.begin(), EntryNames.end()));
1286 error() <<
formatv(
"Name Index @ {0:x}: Name {1} ({2}) is " 1287 "not associated with any entries.\n",
1293 <<
formatv(
"Name Index @ {0:x}: Name {1} ({2}): {3}\n",
1306 auto ContainsInterestingOperators = [&](
StringRef D) {
1312 Op.
getCode() == DW_OP_form_tls_address ||
1313 Op.
getCode() == DW_OP_GNU_push_tls_address);
1319 if (ContainsInterestingOperators(
toStringRef(*Expr)))
1325 DebugLoc->getLocationListAtOffset(*Offset)) {
1327 return ContainsInterestingOperators({E.Loc.data(), E.Loc.size()});
1336 unsigned DWARFVerifier::verifyNameIndexCompleteness(
1344 if (Die.
find(DW_AT_declaration))
1354 auto IncludeLinkageName = Die.
getTag() == DW_TAG_subprogram ||
1355 Die.
getTag() == DW_TAG_inlined_subroutine;
1356 auto EntryNames =
getNames(Die, IncludeLinkageName);
1357 if (EntryNames.empty())
1369 case DW_TAG_compile_unit:
1375 case DW_TAG_formal_parameter:
1376 case DW_TAG_template_value_parameter:
1377 case DW_TAG_template_type_parameter:
1378 case DW_TAG_GNU_template_parameter_pack:
1379 case DW_TAG_GNU_template_template_param:
1389 case DW_TAG_enumerator:
1394 case DW_TAG_imported_declaration:
1400 case DW_TAG_subprogram:
1401 case DW_TAG_inlined_subroutine:
1404 {DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges, DW_AT_entry_pc}))
1413 case DW_TAG_variable:
1424 unsigned NumErrors = 0;
1428 return E.getDIEUnitOffset() == DieUnitOffset;
1430 error() <<
formatv(
"Name Index @ {0:x}: Entry for DIE @ {1:x} ({2}) with " 1431 "name {3} missing.\n",
1440 unsigned DWARFVerifier::verifyDebugNames(
const DWARFSection &AccelSection,
1442 unsigned NumErrors = 0;
1444 DCtx.isLittleEndian(), 0);
1447 OS <<
"Verifying .debug_names...\n";
1451 if (
Error E = AccelTable.extract()) {
1456 NumErrors += verifyDebugNamesCULists(AccelTable);
1457 for (
const auto &NI : AccelTable)
1458 NumErrors += verifyNameIndexBuckets(NI, StrData);
1459 for (
const auto &NI : AccelTable)
1460 NumErrors += verifyNameIndexAbbrevs(NI);
1465 for (
const auto &NI : AccelTable)
1467 NumErrors += verifyNameIndexEntries(NI, NTE);
1472 for (
const std::unique_ptr<DWARFUnit> &U : DCtx.compile_units()) {
1474 AccelTable.getCUNameIndex(U->getOffset())) {
1475 auto *
CU = cast<DWARFCompileUnit>(U.get());
1477 NumErrors += verifyNameIndexCompleteness(
DWARFDie(
CU, &Die), *NI);
1486 unsigned NumErrors = 0;
1495 ".apple_namespaces");
1502 return NumErrors == 0;
1512 Die.
dump(OS, indent, DumpOpts);
A list of locations that contain one variable.
static bool isMatchingUnitTypeAndTag(uint8_t UnitType, dwarf::Tag Tag)
DWARFUnit * getDwarfUnit() const
uint32_t getEntryOffset() const
Returns the offset of the first Entry in the list.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
virtual void forEachTypesSections(function_ref< void(const DWARFSection &)> F) const
dwarf::Attribute Attr
The attribute enumeration of this attribute.
This class represents lattice values for constants.
const DWARFDebugLoc * getDebugLoc()
Get a pointer to the parsed DebugLoc object.
virtual StringRef getAbbrevSection() const
uint32_t getUnitOffset() const
bool isSubprogramDIE() const
Returns true if DIE represents a subprogram (not inlined).
bool isUnitType(uint8_t UnitType)
DWARFDie getDIEForOffset(uint32_t Offset)
Get a DIE given an exact offset.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
static raw_ostream & error()
Convenience method for printing "error: " to stderr.
This class holds an abstract representation of an Accelerator Table, consisting of a sequence of buck...
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
bool handleDebugLine()
Verify the information in the .debug_line section.
virtual const DWARFSection & getLocSection() const
iterator find(StringRef Key)
auto formatv(const char *Fmt, Ts &&... Vals) -> formatv_object< decltype(std::make_tuple(detail::build_format_adapter(std::forward< Ts >(Vals))...))>
static raw_ostream & warning()
Convenience method for printing "warning: " to stderr.
DWARFDie getAttributeValueAsReferencedDie(dwarf::Attribute Attr) const
Extract the specified attribute from this DIE as the referenced DIE.
static SmallVector< StringRef, 2 > getNames(const DWARFDie &DIE, bool IncludeLinkageName=true)
This class represents an Operation in the Expression.
Base class for error info classes.
void dump(raw_ostream &OS, unsigned indent=0, DIDumpOptions DumpOpts=DIDumpOptions()) const
Dump the DIE and all of its attributes to the supplied stream.
virtual StringRef getAbbrevDWOSection() const
Abbreviation describing the encoding of Name Index entries.
virtual void forEachInfoSections(function_ref< void(const DWARFSection &)> F) const
virtual const DWARFSection & getAppleTypesSection() const
bool handleDebugInfo()
Verify the information in the .debug_info and .debug_types sections.
DWARFFormValue Value
The form and value for this attribute.
amdgpu Simplify well known AMD library false Value Value const Twine & Name
std::string toString(Error E)
Write all error messages (if any) in E to a string.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
unsigned getNumCompileUnits()
Get the number of compile units in this context.
unit_iterator_range compile_units()
Get compile units in this context.
StringRef FormEncodingString(unsigned Encoding)
DWARFUnit * addUnit(std::unique_ptr< DWARFUnit > Unit)
Add an existing DWARFUnit to this UnitVector.
static bool isVariableIndexable(const DWARFDie &Die, DWARFContext &DCtx)
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly...
A single location within a location list.
static raw_ostream & note()
Convenience method for printing "note: " to stderr.
Tagged union holding either a T or a Error.
Index attribute and its encoding.
uint32_t getOffset() const
Get the absolute offset into the debug info or types section.
uint8_t getAddressByteSize() const
std::set< DieRangeInfo > Children
Sorted DWARFAddressRangeInfo.
unsigned getNumDIEs()
Returns the number of DIEs in the unit.
uint32_t getLocalTUCount() const
std::vector< DWARFAddressRange > Ranges
Sorted DWARFAddressRanges.
Encapsulates a DWARF attribute value and all of the data required to describe the attribute value...
StringRef AttributeString(unsigned Attribute)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
const DenseSet< Abbrev, AbbrevMapInfo > & getAbbrevs() const
auto lower_bound(R &&Range, ForwardIt I) -> decltype(adl_begin(Range))
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
Represents a single accelerator table within the Dwarf 5 .debug_names section.
uint32_t getBucketArrayEntry(uint32_t Bucket) const
Reads an entry in the Bucket Array for the given Bucket.
uint16_t getVersion() const
uint32_t getNameCount() const
Analysis containing CSE Info
iterator find(const_arg_type_t< KeyT > Val)
Container for dump options that control which debug information will be dumped.
Optional< uint64_t > toSectionOffset(const Optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an section offset.
virtual const DWARFSection & getAppleObjCSection() const
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
void array_pod_sort(IteratorTy Start, IteratorTy End)
array_pod_sort - This sorts an array with the specified start and end extent.
Utility class that carries the DWARF compile/type unit and the debug info entry in an object...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
DWARF v5-specific implementation of an Accelerator Entry.
This implements the Apple accelerator table format, a precursor of the DWARF 5 accelerator table form...
uint32_t getForeignTUCount() const
virtual const DWARFSection & getStringOffsetSection() const
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
A structured debug information entry.
std::pair< iterator, bool > insert(const ValueT &V)
Optional< DWARFFormValue > findRecursively(ArrayRef< dwarf::Attribute > Attrs) const
Extract the first value of any attribute in Attrs from this DIE and recurse into any DW_AT_specificat...
bool handleDebugAbbrev()
Verify the information in any of the following sections, if available: .debug_abbrev, debug_abbrev.dwo.
NameTableEntry getNameTableEntry(uint32_t Index) const
Reads an entry in the Name Table for the given Index.
A class that keeps the address range information for a single DIE.
const DWARFAbbreviationDeclarationSet * getAbbreviationDeclarationSet(uint64_t CUAbbrOffset) const
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly...
uint32_t getHashArrayEntry(uint32_t Index) const
Reads an entry in the Hash Array for the given Index.
bool contains(const DieRangeInfo &RHS) const
Return true if ranges in this object contains all ranges within RHS.
SectionKind - This is a simple POD value that classifies the properties of a section.
virtual StringRef getStringSection() const
void reserve(size_type NumEntries)
Grow the densemap so that it can contain at least NumEntries items before resizing again...
uint32_t getBucketCount() const
auto find_if(R &&Range, UnaryPredicate P) -> decltype(adl_begin(Range))
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly...
Expected< Entry > getEntry(uint32_t *Offset) const
std::vector< DWARFAddressRange >::const_iterator address_range_iterator
StringRef toStringRef(bool B)
Construct a string ref from a boolean.
void consumeError(Error Err)
Consume a Error without doing anything.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
UnitType
Constants for unit types in DWARF v5.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
const char * getString() const
Return the string referenced by this name table entry or nullptr if the string offset is not valid...
.debug_names section consists of one or more units.
void handleAllErrors(Error E, HandlerTs &&... Handlers)
Behaves the same as handleErrors, except that by contract all errors must be handled by the given han...
DWARFDie getUnitDIE(bool ExtractUnitDIEOnly=true)
const char * getName(DINameKind Kind) const
Return the DIE name resolving DW_AT_sepcification or DW_AT_abstract_origin references if necessary...
A single entry in the Name Table (Dwarf 5 sect.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
uint32_t caseFoldingDjbHash(StringRef Buffer, uint32_t H=5381)
Computes the Bernstein hash after folding the input according to the Dwarf 5 standard case folding ru...
address_range_iterator insert(const DWARFAddressRange &R)
Inserts the address range.
DWARFContext This data structure is the top level entity that deals with dwarf debug information pars...
uint32_t getIndex() const
Return the index of this name in the parent Name Index.
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static void dumpTableHeader(raw_ostream &OS)
Describe a collection of units.
Implements a dense probed hash-table based set with some number of buckets stored inline...
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
StringRef UnitTypeString(unsigned)
Error returned by NameIndex::getEntry to report it has reached the end of the entry list...
virtual const DWARFSection & getAppleNamespacesSection() const
virtual const DWARFSection & getLineSection() const
bool intersects(const DieRangeInfo &RHS) const
Return true if any range in this object intersects with any range in RHS.
StringRef TagString(unsigned Tag)
virtual const DWARFSection & getDebugNamesSection() const
static bool isSupportedVersion(unsigned version)
DWARFDie getDIEAtIndex(unsigned Index)
Return the DIE object at the given index.
void emplace_back(ArgTypes &&... Args)
dwarf::Tag getTag() const
LLVM_NODISCARD bool empty() const
bool handleAccelTables()
Verify the information in accelerator tables, if they exist.
virtual const DWARFSection & getAppleNamesSection() const
uint32_t getOffset() const
Expected< DWARFAddressRangesVector > getAddressRanges() const
Get the address ranges for this DIE.
std::set< DieRangeInfo >::const_iterator die_range_info_iterator
bool isLittleEndian() const
const DWARFObject & getDWARFObj() const
virtual const DWARFSection & getRangeSection() const
uint8_t getUnitType() const
uint32_t getCUCount() const
uint32_t Code
Abbreviation code.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
virtual const object::ObjectFile * getFile() const
bool operator<(int64_t V1, const APSInt &V2)
Optional< DWARFFormValue > find(dwarf::Attribute Attr) const
Extract the specified attribute from this DIE.
std::vector< DWARFAddressRange > DWARFAddressRangesVector
DWARFAddressRangesVector - represents a set of absolute address ranges.
DWARFDebugInfoEntry - A DIE with only the minimum required data.
Lightweight error class with error context and mandatory checking.
DWARFVerifier(raw_ostream &S, DWARFContext &D, DIDumpOptions DumpOpts=DIDumpOptions::getForSingleDIE())
This class implements an extremely fast bulk output stream that can only output to a stream...
StringRef - Represent a constant reference to a string, i.e.
static void LLVM_ATTRIBUTE_NORETURN ReportError(uint32_t StartOffset, const char *ErrorMsg)
uint32_t getCUOffset(uint32_t CU) const
Reads offset of compilation unit CU. CU is 0-based.
iterator_range< ValueIterator > equal_range(StringRef Key) const
Look up all entries in this Name Index matching Key.
DWARFDie getParent() const
Get the parent of this DIE object.
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.