26 using namespace dwarf;
31 auto Begin = Ranges.begin();
32 auto End = Ranges.end();
36 if (Pos->intersects(R))
37 return std::move(Pos);
40 if (Iter->intersects(R))
41 return std::move(Iter);
45 Ranges.insert(Pos, R);
51 auto End = Children.end();
52 auto Iter = Children.begin();
54 if (Iter->intersects(RI))
59 return Children.end();
63 auto I1 = Ranges.begin(), E1 = Ranges.end();
70 bool Covered = I1->LowPC <= R.
LowPC;
79 if (R.
LowPC < I1->HighPC)
87 auto I1 = Ranges.begin(), E1 = Ranges.end();
89 while (I1 != E1 && I2 != E2) {
90 if (I1->intersects(*I2))
92 if (I1->LowPC < I2->LowPC)
101 uint64_t *
Offset,
unsigned UnitIndex,
102 uint8_t &
UnitType,
bool &isUnitDWARF64) {
103 uint64_t AbbrOffset, Length;
104 uint8_t AddrSize = 0;
108 bool ValidLength =
false;
109 bool ValidVersion =
false;
110 bool ValidAddrSize =
false;
111 bool ValidType =
true;
112 bool ValidAbbrevOffset =
true;
114 uint64_t OffsetStart = *
Offset;
118 isUnitDWARF64 =
true;
133 if (!DCtx.getDebugAbbrev()->getAbbreviationDeclarationSet(AbbrOffset))
134 ValidAbbrevOffset =
false;
136 ValidLength = DebugInfoData.
isValidOffset(OffsetStart + Length + 3);
138 ValidAddrSize = AddrSize == 4 || AddrSize == 8;
139 if (!ValidLength || !ValidVersion || !ValidAddrSize || !ValidAbbrevOffset ||
142 error() <<
format(
"Units[%d] - start offset: 0x%08" PRIx64
" \n", UnitIndex,
145 note() <<
"The length for this unit is too " 146 "large for the .debug_info provided.\n";
148 note() <<
"The 16 bit unit header version is not valid.\n";
150 note() <<
"The unit type encoding is not valid.\n";
151 if (!ValidAbbrevOffset)
152 note() <<
"The offset into the .debug_abbrev section is " 155 note() <<
"The address size is unsupported.\n";
157 *
Offset = OffsetStart + Length + (isUnitDWARF64 ? 12 : 4);
161 unsigned DWARFVerifier::verifyUnitContents(
DWARFUnit &Unit) {
162 unsigned NumUnitErrors = 0;
164 for (
unsigned I = 0;
I < NumDies; ++
I) {
167 if (Die.getTag() == DW_TAG_null)
170 for (
auto AttrValue : Die.attributes()) {
171 NumUnitErrors += verifyDebugInfoAttribute(Die, AttrValue);
172 NumUnitErrors += verifyDebugInfoForm(Die, AttrValue);
175 NumUnitErrors += verifyDebugInfoCallSite(Die);
180 error() <<
"Compilation unit without DIE.\n";
182 return NumUnitErrors;
186 error() <<
"Compilation unit root DIE is not a unit DIE: " 195 <<
") do not match.\n";
203 error() <<
"Skeleton compilation unit has children.\n";
208 NumUnitErrors += verifyDieRanges(Die, RI);
210 return NumUnitErrors;
213 unsigned DWARFVerifier::verifyDebugInfoCallSite(
const DWARFDie &Die) {
214 if (Die.
getTag() != DW_TAG_call_site && Die.
getTag() != DW_TAG_GNU_call_site)
219 if (Curr.
getTag() == DW_TAG_inlined_subroutine) {
220 error() <<
"Call site entry nested within inlined subroutine:";
227 error() <<
"Call site entry not nested within a valid subprogram:";
233 Curr.
find({DW_AT_call_all_calls, DW_AT_call_all_source_calls,
234 DW_AT_call_all_tail_calls, DW_AT_GNU_all_call_sites,
235 DW_AT_GNU_all_source_call_sites,
236 DW_AT_GNU_all_tail_call_sites});
238 error() <<
"Subprogram with call site entry has no DW_AT_call attribute:";
247 unsigned DWARFVerifier::verifyAbbrevSection(
const DWARFDebugAbbrev *Abbrev) {
248 unsigned NumErrors = 0;
252 for (
auto AbbrDecl : *AbbrDecls) {
254 for (
auto Attribute : AbbrDecl.attributes()) {
256 if (!Result.second) {
257 error() <<
"Abbreviation declaration contains multiple " 269 OS <<
"Verifying .debug_abbrev...\n";
272 unsigned NumErrors = 0;
274 NumErrors += verifyAbbrevSection(DCtx.getDebugAbbrev());
276 NumErrors += verifyAbbrevSection(DCtx.getDebugAbbrevDWO());
278 return NumErrors == 0;
281 unsigned DWARFVerifier::verifyUnitSection(
const DWARFSection &S,
285 unsigned NumDebugInfoErrors = 0;
286 uint64_t OffsetStart = 0,
Offset = 0, UnitIdx = 0;
288 bool isUnitDWARF64 =
false;
289 bool isHeaderChainValid =
true;
295 if (!verifyUnitHeader(DebugInfoData, &
Offset, UnitIdx, UnitType,
297 isHeaderChainValid =
false;
302 Header.
extract(DCtx, DebugInfoData, &OffsetStart, SectionKind);
305 case dwarf::DW_UT_type:
306 case dwarf::DW_UT_split_type: {
307 Unit = TypeUnitVector.
addUnit(std::make_unique<DWARFTypeUnit>(
315 case dwarf::DW_UT_skeleton:
316 case dwarf::DW_UT_split_compile:
317 case dwarf::DW_UT_compile:
318 case dwarf::DW_UT_partial:
321 Unit = CompileUnitVector.
addUnit(std::make_unique<DWARFCompileUnit>(
331 NumDebugInfoErrors += verifyUnitContents(*Unit);
336 if (UnitIdx == 0 && !hasDIE) {
337 warn() <<
"Section is empty.\n";
338 isHeaderChainValid =
true;
340 if (!isHeaderChainValid)
341 ++NumDebugInfoErrors;
342 NumDebugInfoErrors += verifyDebugInfoReferences();
343 return NumDebugInfoErrors;
348 unsigned NumErrors = 0;
350 OS <<
"Verifying .debug_info Unit Header Chain...\n";
355 OS <<
"Verifying .debug_types Unit Header Chain...\n";
359 return NumErrors == 0;
362 unsigned DWARFVerifier::verifyDieRanges(
const DWARFDie &Die,
364 unsigned NumErrors = 0;
370 if (!RangesOrError) {
401 if (!IsObjectFile || IsMachOObject || Die.
getTag() != DW_TAG_compile_unit) {
402 for (
auto Range : Ranges) {
403 if (!Range.valid()) {
405 error() <<
"Invalid address range " << Range <<
"\n";
410 const auto IntersectingRange = RI.
insert(Range);
411 if (IntersectingRange != RI.
Ranges.end()) {
413 error() <<
"DIE has overlapping address ranges: " << Range <<
" and " 414 << *IntersectingRange <<
"\n";
421 const auto IntersectingChild = ParentRI.
insert(RI);
422 if (IntersectingChild != ParentRI.
Children.end()) {
424 error() <<
"DIEs have overlapping address ranges:";
426 dump(IntersectingChild->Die) <<
'\n';
430 bool ShouldBeContained = !Ranges.empty() && !ParentRI.
Ranges.empty() &&
431 !(Die.
getTag() == DW_TAG_subprogram &&
432 ParentRI.
Die.
getTag() == DW_TAG_subprogram);
433 if (ShouldBeContained && !ParentRI.
contains(RI)) {
435 error() <<
"DIE address ranges are not contained in its parent's ranges:";
437 dump(Die, 2) <<
'\n';
442 NumErrors += verifyDieRanges(Child, RI);
447 unsigned DWARFVerifier::verifyDebugInfoAttribute(
const DWARFDie &Die,
449 unsigned NumErrors = 0;
452 error() << TitleMsg <<
'\n';
457 const auto Attr = AttrValue.
Attr;
463 ReportError(
"DW_AT_ranges offset is beyond .debug_ranges bounds:");
466 ReportError(
"DIE has invalid DW_AT_ranges encoding:");
468 case DW_AT_stmt_list:
472 ReportError(
"DW_AT_stmt_list offset is beyond .debug_line bounds: " +
476 ReportError(
"DIE has invalid DW_AT_stmt_list encoding:");
478 case DW_AT_location: {
479 if (
Expected<std::vector<DWARFLocationExpression>> Loc =
482 for (
const auto &
Entry : *Loc) {
489 if (Error || !Expression.verify(U))
490 ReportError(
"DIE contains invalid DWARF expression:");
496 case DW_AT_specification:
497 case DW_AT_abstract_origin: {
499 auto DieTag = Die.
getTag();
500 auto RefTag = ReferencedDie.getTag();
501 if (DieTag == RefTag)
503 if (DieTag == DW_TAG_inlined_subroutine && RefTag == DW_TAG_subprogram)
505 if (DieTag == DW_TAG_variable && RefTag == DW_TAG_member)
508 if (DieTag == DW_TAG_GNU_call_site && RefTag == DW_TAG_subprogram)
512 " that points to DIE with " 513 "incompatible tag " +
532 unsigned DWARFVerifier::verifyDebugInfoForm(
const DWARFDie &Die,
536 unsigned NumErrors = 0;
543 case DW_FORM_ref_udata: {
548 auto CUSize = DieCU->getNextUnitOffset() - DieCU->getOffset();
550 if (CUOffset >= CUSize) {
553 <<
format(
"0x%08" PRIx64, CUOffset)
554 <<
" is invalid (must be less than CU size of " 555 <<
format(
"0x%08" PRIx64, CUSize) <<
"):\n";
556 Die.
dump(OS, 0, DumpOpts);
561 ReferenceToDIEOffsets[*RefVal].insert(Die.
getOffset());
566 case DW_FORM_ref_addr: {
572 if (*RefVal >= DieCU->getInfoSection().Data.size()) {
574 error() <<
"DW_FORM_ref_addr offset beyond .debug_info " 580 ReferenceToDIEOffsets[*RefVal].insert(Die.
getOffset());
590 error() <<
"DW_FORM_strp offset beyond .debug_str bounds:\n";
599 case DW_FORM_strx4: {
603 if (!DieCU->getStringOffsetsTableContribution()) {
606 <<
" used without a valid string offsets table:\n";
611 unsigned ItemSize = DieCU->getDwarfStringOffsetsByteSize();
614 (uint64_t)DieCU->getStringOffsetsBase() +
Index * ItemSize;
618 <<
format(
"%" PRIu64,
Index) <<
", which is too large:\n";
623 uint64_t StringOffset = *DieCU->getStringOffsetSectionItem(
Index);
628 <<
", but the referenced string" 629 " offset is beyond .debug_str bounds:\n";
640 unsigned DWARFVerifier::verifyDebugInfoReferences() {
643 OS <<
"Verifying .debug_info references...\n";
644 unsigned NumErrors = 0;
645 for (
const std::pair<
const uint64_t, std::set<uint64_t>> &Pair :
646 ReferenceToDIEOffsets) {
647 if (DCtx.getDIEForOffset(Pair.first))
650 error() <<
"invalid DIE reference " <<
format(
"0x%08" PRIx64, Pair.first)
651 <<
". Offset is in between DIEs:\n";
652 for (
auto Offset : Pair.second)
659 void DWARFVerifier::verifyDebugLineStmtOffsets() {
660 std::map<uint64_t, DWARFDie> StmtListToDie;
661 for (
const auto &
CU : DCtx.compile_units()) {
662 auto Die =
CU->getUnitDIE();
667 if (!StmtSectionOffset)
669 const uint64_t LineTableOffset = *StmtSectionOffset;
670 auto LineTable = DCtx.getLineTableForUnit(
CU.get());
671 if (LineTableOffset < DCtx.getDWARFObj().getLineSection().Data.size()) {
673 ++NumDebugLineErrors;
674 error() <<
".debug_line[" <<
format(
"0x%08" PRIx64, LineTableOffset)
675 <<
"] was not able to be parsed for CU:\n";
681 assert(LineTable ==
nullptr);
686 auto Iter = StmtListToDie.find(LineTableOffset);
687 if (Iter != StmtListToDie.end()) {
688 ++NumDebugLineErrors;
689 error() <<
"two compile unit DIEs, " 690 <<
format(
"0x%08" PRIx64, Iter->second.getOffset()) <<
" and " 692 <<
", have the same DW_AT_stmt_list section offset:\n";
698 StmtListToDie[LineTableOffset] = Die;
702 void DWARFVerifier::verifyDebugLineRows() {
703 for (
const auto &
CU : DCtx.compile_units()) {
704 auto Die =
CU->getUnitDIE();
705 auto LineTable = DCtx.getLineTableForUnit(
CU.get());
712 uint32_t MaxDirIndex = LineTable->Prologue.IncludeDirectories.size();
715 for (
const auto &FileName : LineTable->Prologue.FileNames) {
717 if (FileName.DirIdx > MaxDirIndex) {
718 ++NumDebugLineErrors;
719 error() <<
".debug_line[" 722 <<
"].prologue.file_names[" << FileIndex
723 <<
"].dir_idx contains an invalid index: " << FileName.DirIdx
728 std::string FullPath;
729 const bool HasFullPath = LineTable->getFileNameByIndex(
730 FileIndex,
CU->getCompilationDir(),
732 assert(HasFullPath &&
"Invalid index?");
734 auto It = FullPathMap.
find(FullPath);
735 if (It == FullPathMap.
end())
736 FullPathMap[FullPath] = FileIndex;
737 else if (It->second != FileIndex) {
738 warn() <<
".debug_line[" 741 <<
"].prologue.file_names[" << FileIndex
742 <<
"] is a duplicate of file_names[" << It->second <<
"]\n";
749 uint64_t PrevAddress = 0;
751 for (
const auto &Row : LineTable->Rows) {
753 if (Row.Address.Address < PrevAddress) {
754 ++NumDebugLineErrors;
755 error() <<
".debug_line[" 758 <<
"] row[" << RowIndex
759 <<
"] decreases in address from previous row:\n";
763 LineTable->Rows[RowIndex - 1].dump(OS);
769 if (!LineTable->hasFileAtIndex(Row.File)) {
770 ++NumDebugLineErrors;
771 bool isDWARF5 = LineTable->Prologue.getVersion() >= 5;
772 error() <<
".debug_line[" 775 <<
"][" << RowIndex <<
"] has invalid file index " << Row.File
776 <<
" (valid values are [" << (isDWARF5 ?
"0," :
"1,")
777 << LineTable->Prologue.FileNames.size()
778 << (isDWARF5 ?
")" :
"]") <<
"):\n";
786 PrevAddress = Row.Address.Address;
794 : OS(S), DCtx(D), DumpOpts(
std::move(DumpOpts)), IsObjectFile(
false),
795 IsMachOObject(
false) {
797 IsObjectFile =
F->isRelocatableObject();
798 IsMachOObject =
F->isMachO();
803 NumDebugLineErrors = 0;
804 OS <<
"Verifying .debug_line...\n";
805 verifyDebugLineStmtOffsets();
806 verifyDebugLineRows();
807 return NumDebugLineErrors == 0;
810 unsigned DWARFVerifier::verifyAppleAccelTable(
const DWARFSection *AccelSection,
813 unsigned NumErrors = 0;
818 OS <<
"Verifying " << SectionName <<
"...\n";
821 if (!AccelSectionData.isValidOffset(AccelTable.getSizeHdr())) {
822 error() <<
"Section is too small to fit a section header.\n";
827 if (
Error E = AccelTable.extract()) {
828 error() <<
toString(std::move(
E)) <<
'\n';
833 uint32_t NumBuckets = AccelTable.getNumBuckets();
834 uint32_t NumHashes = AccelTable.getNumHashes();
836 uint64_t BucketsOffset =
837 AccelTable.getSizeHdr() + AccelTable.getHeaderDataLength();
838 uint64_t HashesBase = BucketsOffset + NumBuckets * 4;
839 uint64_t OffsetsBase = HashesBase + NumHashes * 4;
840 for (
uint32_t BucketIdx = 0; BucketIdx < NumBuckets; ++BucketIdx) {
841 uint32_t HashIdx = AccelSectionData.getU32(&BucketsOffset);
842 if (HashIdx >= NumHashes && HashIdx != UINT32_MAX) {
843 error() <<
format(
"Bucket[%d] has invalid hash index: %u.\n", BucketIdx,
848 uint32_t NumAtoms = AccelTable.getAtomsDesc().size();
850 error() <<
"No atoms: failed to read HashData.\n";
853 if (!AccelTable.validateForms()) {
854 error() <<
"Unsupported form: failed to read HashData.\n";
858 for (
uint32_t HashIdx = 0; HashIdx < NumHashes; ++HashIdx) {
859 uint64_t HashOffset = HashesBase + 4 * HashIdx;
860 uint64_t DataOffset = OffsetsBase + 4 * HashIdx;
861 uint32_t Hash = AccelSectionData.getU32(&HashOffset);
862 uint64_t HashDataOffset = AccelSectionData.getU32(&DataOffset);
863 if (!AccelSectionData.isValidOffsetForDataOfSize(HashDataOffset,
865 error() <<
format(
"Hash[%d] has invalid HashData offset: " 866 "0x%08" PRIx64
".\n",
867 HashIdx, HashDataOffset);
872 uint64_t StringOffset;
876 while ((StrpOffset = AccelSectionData.getU32(&HashDataOffset)) != 0) {
878 AccelSectionData.getU32(&HashDataOffset);
879 for (
uint32_t HashDataIdx = 0; HashDataIdx < NumHashDataObjects;
881 std::tie(Offset, Tag) = AccelTable.readAtoms(&HashDataOffset);
885 NumBuckets ? (Hash % NumBuckets) : UINT32_MAX;
886 StringOffset = StrpOffset;
887 const char *
Name = StrData->
getCStr(&StringOffset);
892 "%s Bucket[%d] Hash[%d] = 0x%08x " 893 "Str[%u] = 0x%08" PRIx64
" DIE[%d] = 0x%08" PRIx64
" " 894 "is not a valid DIE offset for \"%s\".\n",
895 SectionName, BucketIdx, HashIdx, Hash, StringCount, StrpOffset,
896 HashDataIdx, Offset, Name);
901 if ((Tag != dwarf::DW_TAG_null) && (Die.
getTag() !=
Tag)) {
903 <<
" in accelerator table does not match Tag " 924 CUMap[
CU->getOffset()] = NotIndexed;
926 unsigned NumErrors = 0;
928 if (NI.getCUCount() == 0) {
929 error() <<
formatv(
"Name Index @ {0:x} does not index any CU\n",
935 uint64_t
Offset = NI.getCUOffset(
CU);
936 auto Iter = CUMap.
find(Offset);
938 if (Iter == CUMap.
end()) {
940 "Name Index @ {0:x} references a non-existing CU @ {1:x}\n",
941 NI.getUnitOffset(),
Offset);
946 if (Iter->second != NotIndexed) {
947 error() <<
formatv(
"Name Index @ {0:x} references a CU @ {1:x}, but " 948 "this CU is already indexed by Name Index @ {2:x}\n",
949 NI.getUnitOffset(),
Offset, Iter->second);
952 Iter->second = NI.getUnitOffset();
956 for (
const auto &KV : CUMap) {
957 if (KV.second == NotIndexed)
958 warn() <<
formatv(
"CU @ {0:x} not covered by any Name Index\n", KV.first);
972 : Bucket(Bucket),
Index(Index) {}
973 bool operator<(
const BucketInfo &RHS)
const {
return Index < RHS.Index; }
978 warn() <<
formatv(
"Name Index @ {0:x} does not contain a hash table.\n",
985 std::vector<BucketInfo> BucketStarts;
990 error() <<
formatv(
"Bucket {0} of Name Index @ {1:x} contains invalid " 991 "value {2}. Valid range is [0, {3}].\n",
997 BucketStarts.emplace_back(Bucket, Index);
1017 for (
const BucketInfo &
B : BucketStarts) {
1024 if (
B.Index > NextUncovered) {
1025 error() <<
formatv(
"Name Index @ {0:x}: Name table entries [{1}, {2}] " 1026 "are not covered by the hash table.\n",
1044 "Name Index @ {0:x}: Bucket {1} is not empty but points to a " 1045 "mismatched hash value {2:x} (belonging to bucket {3}).\n",
1061 error() <<
formatv(
"Name Index @ {0:x}: String ({1}) at index {2} " 1062 "hashes to {3:x}, but " 1063 "the Name Index hash is {4:x}\n",
1071 NextUncovered =
std::max(NextUncovered, Idx);
1076 unsigned DWARFVerifier::verifyNameIndexAttribute(
1080 if (FormName.
empty()) {
1081 error() <<
formatv(
"NameIndex @ {0:x}: Abbreviation {1:x}: {2} uses an " 1082 "unknown form: {3}.\n",
1088 if (AttrEnc.
Index == DW_IDX_type_hash) {
1089 if (AttrEnc.
Form != dwarf::DW_FORM_data8) {
1091 "NameIndex @ {0:x}: Abbreviation {1:x}: DW_IDX_type_hash " 1092 "uses an unexpected form {2} (should be {3}).\n",
1101 struct FormClassTable {
1106 static constexpr FormClassTable Table[] = {
1114 auto Iter =
find_if(TableRef, [AttrEnc](
const FormClassTable &
T) {
1115 return T.Index == AttrEnc.
Index;
1117 if (Iter == TableRef.
end()) {
1118 warn() <<
formatv(
"NameIndex @ {0:x}: Abbreviation {1:x} contains an " 1119 "unknown index attribute: {2}.\n",
1125 error() <<
formatv(
"NameIndex @ {0:x}: Abbreviation {1:x}: {2} uses an " 1126 "unexpected form {3} (expected form class {4}).\n",
1128 AttrEnc.
Form, Iter->ClassName);
1137 warn() <<
formatv(
"Name Index @ {0:x}: Verifying indexes of type units is " 1138 "not currently supported.\n",
1143 unsigned NumErrors = 0;
1146 if (TagName.
empty()) {
1147 warn() <<
formatv(
"NameIndex @ {0:x}: Abbreviation {1:x} references an " 1148 "unknown tag: {2}.\n",
1152 for (
const auto &AttrEnc : Abbrev.Attributes) {
1153 if (!Attributes.insert(AttrEnc.
Index).second) {
1154 error() <<
formatv(
"NameIndex @ {0:x}: Abbreviation {1:x} contains " 1155 "multiple {2} attributes.\n",
1160 NumErrors += verifyNameIndexAttribute(NI, Abbrev, AttrEnc);
1163 if (NI.
getCUCount() > 1 && !Attributes.count(dwarf::DW_IDX_compile_unit)) {
1164 error() <<
formatv(
"NameIndex @ {0:x}: Indexing multiple compile units " 1165 "and abbreviation {1:x} has no {2} attribute.\n",
1167 dwarf::DW_IDX_compile_unit);
1170 if (!Attributes.count(dwarf::DW_IDX_die_offset)) {
1172 "NameIndex @ {0:x}: Abbreviation {1:x} has no {2} attribute.\n",
1181 bool IncludeLinkageName =
true) {
1185 else if (DIE.
getTag() == dwarf::DW_TAG_namespace)
1188 if (IncludeLinkageName) {
1190 if (Result.
empty() || Result[0] != Str)
1198 unsigned DWARFVerifier::verifyNameIndexEntries(
1208 "Name Index @ {0:x}: Unable to get string associated with name {1}.\n",
1214 unsigned NumErrors = 0;
1215 unsigned NumEntries = 0;
1217 uint64_t NextEntryID = EntryID;
1219 for (; EntryOr; ++NumEntries, EntryID = NextEntryID,
1220 EntryOr = NI.
getEntry(&NextEntryID)) {
1221 uint32_t CUIndex = *EntryOr->getCUIndex();
1223 error() <<
formatv(
"Name Index @ {0:x}: Entry @ {1:x} contains an " 1224 "invalid CU index ({2}).\n",
1230 uint64_t DIEOffset = CUOffset + *EntryOr->getDIEUnitOffset();
1233 error() <<
formatv(
"Name Index @ {0:x}: Entry @ {1:x} references a " 1234 "non-existing DIE @ {2:x}.\n",
1240 error() <<
formatv(
"Name Index @ {0:x}: Entry @ {1:x}: mismatched CU of " 1241 "DIE @ {2:x}: index - {3:x}; debug_info - {4:x}.\n",
1246 if (DIE.
getTag() != EntryOr->tag()) {
1247 error() <<
formatv(
"Name Index @ {0:x}: Entry @ {1:x}: mismatched Tag of " 1248 "DIE @ {2:x}: index - {3}; debug_info - {4}.\n",
1256 error() <<
formatv(
"Name Index @ {0:x}: Entry @ {1:x}: mismatched Name " 1257 "of DIE @ {2:x}: index - {3}; debug_info - {4}.\n",
1259 make_range(EntryNames.begin(), EntryNames.end()));
1267 error() <<
formatv(
"Name Index @ {0:x}: Name {1} ({2}) is " 1268 "not associated with any entries.\n",
1274 <<
formatv(
"Name Index @ {0:x}: Name {1} ({2}): {3}\n",
1290 for (
const auto &
Entry : *Loc) {
1296 Op.
getCode() == DW_OP_form_tls_address ||
1297 Op.
getCode() == DW_OP_GNU_push_tls_address);
1305 unsigned DWARFVerifier::verifyNameIndexCompleteness(
1313 if (Die.
find(DW_AT_declaration))
1323 auto IncludeLinkageName = Die.
getTag() == DW_TAG_subprogram ||
1324 Die.
getTag() == DW_TAG_inlined_subroutine;
1325 auto EntryNames =
getNames(Die, IncludeLinkageName);
1326 if (EntryNames.empty())
1338 case DW_TAG_compile_unit:
1344 case DW_TAG_formal_parameter:
1345 case DW_TAG_template_value_parameter:
1346 case DW_TAG_template_type_parameter:
1347 case DW_TAG_GNU_template_parameter_pack:
1348 case DW_TAG_GNU_template_template_param:
1358 case DW_TAG_enumerator:
1363 case DW_TAG_imported_declaration:
1369 case DW_TAG_subprogram:
1370 case DW_TAG_inlined_subroutine:
1373 {DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges, DW_AT_entry_pc}))
1382 case DW_TAG_variable:
1393 unsigned NumErrors = 0;
1397 return E.getDIEUnitOffset() == DieUnitOffset;
1399 error() <<
formatv(
"Name Index @ {0:x}: Entry for DIE @ {1:x} ({2}) with " 1400 "name {3} missing.\n",
1409 unsigned DWARFVerifier::verifyDebugNames(
const DWARFSection &AccelSection,
1411 unsigned NumErrors = 0;
1413 DCtx.isLittleEndian(), 0);
1416 OS <<
"Verifying .debug_names...\n";
1420 if (
Error E = AccelTable.extract()) {
1425 NumErrors += verifyDebugNamesCULists(AccelTable);
1426 for (
const auto &NI : AccelTable)
1427 NumErrors += verifyNameIndexBuckets(NI, StrData);
1428 for (
const auto &NI : AccelTable)
1429 NumErrors += verifyNameIndexAbbrevs(NI);
1434 for (
const auto &NI : AccelTable)
1436 NumErrors += verifyNameIndexEntries(NI, NTE);
1441 for (
const std::unique_ptr<DWARFUnit> &U : DCtx.compile_units()) {
1443 AccelTable.getCUNameIndex(U->getOffset())) {
1444 auto *
CU = cast<DWARFCompileUnit>(U.get());
1446 NumErrors += verifyNameIndexCompleteness(
DWARFDie(
CU, &Die), *NI);
1455 unsigned NumErrors = 0;
1464 ".apple_namespaces");
1471 return NumErrors == 0;
1481 Die.
dump(OS, indent, DumpOpts);
auto lower_bound(R &&Range, T &&Value) -> decltype(adl_begin(Range))
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
static bool isMatchingUnitTypeAndTag(uint8_t UnitType, dwarf::Tag Tag)
reference emplace_back(ArgTypes &&... Args)
virtual StringRef getStrSection() const
DWARFUnit * getDwarfUnit() const
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.
virtual StringRef getAbbrevSection() const
bool isSubprogramDIE() const
Returns true if DIE represents a subprogram (not inlined).
bool isUnitType(uint8_t UnitType)
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
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)
uint64_t getCUOffset(uint32_t CU) const
Reads offset of compilation unit CU. CU is 0-based.
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.
Error takeError()
Take ownership of the stored error.
uint64_t getUnitOffset() const
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.
virtual const DWARFSection & getRangesSection() const
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.
virtual const DWARFSection & getNamesSection() const
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...
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.
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
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.
DWARFDie getDIEForOffset(uint64_t Offset)
Get a DIE given an exact offset.
StringRef toStringRef(const Optional< DWARFFormValue > &V, StringRef Default={})
Take an optional DWARFFormValue and try to extract a string value from it.
Encapsulates a DWARF attribute value and all of the data required to describe the attribute value...
StringRef AttributeString(unsigned Attribute)
virtual const DWARFSection & getStrOffsetsSection() const
const DenseSet< Abbrev, AbbrevMapInfo > & getAbbrevs() const
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
LLVM_NODISCARD size_t size() const
size - Get the string size.
Represents a single accelerator table within the DWARF v5 .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.
Expected< Entry > getEntry(uint64_t *Offset) const
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
static void LLVM_ATTRIBUTE_NORETURN ReportError(uint64_t StartOffset, const char *ErrorMsg)
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Expected< DWARFLocationExpressionsVector > getLocations(dwarf::Attribute Attr) const
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.
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...
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.
uint64_t getOffset() const
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...
Align max(MaybeAlign Lhs, Align Rhs)
A single entry in the Name Table (DWARF v5 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.
Optional< const char * > toString(const Optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract a string value from it.
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)
static bool isSupportedVersion(unsigned version)
DWARFDie getDIEAtIndex(unsigned Index)
Return the DIE object at the given index.
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
Expected< DWARFAddressRangesVector > getAddressRanges() const
Get the address ranges for this DIE.
std::set< DieRangeInfo >::const_iterator die_range_info_iterator
uint64_t getEntryOffset() const
Returns the offset of the first Entry in the list.
bool isLittleEndian() const
const DWARFObject & getDWARFObj() 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())
uint64_t getOffset() const
Get the absolute offset into the debug info or types section.
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.
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.