45using namespace object;
51std::optional<DWARFAddressRange>
53 auto Begin =
Ranges.begin();
55 auto Pos = std::lower_bound(Begin,
End, R);
58 if (Pos !=
End && *Pos == R) {
81 return Children.end();
83 auto End = Children.end();
84 auto Iter = Children.begin();
86 if (Iter->intersects(RI))
91 return Children.end();
95 auto I1 = Ranges.begin(), E1 = Ranges.end();
96 auto I2 =
RHS.Ranges.begin(), E2 =
RHS.Ranges.end();
102 bool Covered = I1->LowPC <= R.LowPC;
103 if (R.LowPC == R.HighPC || (Covered && R.HighPC <= I1->HighPC)) {
111 if (R.LowPC < I1->HighPC)
112 R.LowPC = I1->HighPC;
119 auto I1 = Ranges.begin(), E1 = Ranges.end();
120 auto I2 =
RHS.Ranges.begin(), E2 =
RHS.Ranges.end();
121 while (I1 != E1 && I2 != E2) {
122 if (I1->intersects(*I2)) {
127 if (I1->LowPC < I2->LowPC)
143 bool ValidLength =
false;
144 bool ValidVersion =
false;
145 bool ValidAddrSize =
false;
146 bool ValidType =
true;
147 bool ValidAbbrevOffset =
true;
168 if (!AbbrevSetOrErr) {
169 ValidAbbrevOffset =
false;
179 if (!ValidLength || !ValidVersion || !ValidAddrSize || !ValidAbbrevOffset ||
182 bool HeaderShown =
false;
183 auto ShowHeaderOnce = [&]() {
185 error() <<
format(
"Units[%d] - start offset: 0x%08" PRIx64
" \n",
186 UnitIndex, OffsetStart);
192 "Unit Header Length: Unit too large for .debug_info provided", [&]() {
194 note() <<
"The length for this unit is too "
195 "large for the .debug_info provided.\n";
199 "Unit Header Length: 16 bit unit header version is not valid", [&]() {
201 note() <<
"The 16 bit unit header version is not valid.\n";
205 "Unit Header Length: Unit type encoding is not valid", [&]() {
207 note() <<
"The unit type encoding is not valid.\n";
209 if (!ValidAbbrevOffset)
211 "Unit Header Length: Offset into the .debug_abbrev section is not "
215 note() <<
"The offset into the .debug_abbrev section is "
219 ErrorCategory.
Report(
"Unit Header Length: Address size is unsupported",
222 note() <<
"The address size is unsupported.\n";
225 *
Offset = OffsetStart +
Length + (isUnitDWARF64 ? 12 : 4);
229bool DWARFVerifier::verifyName(
const DWARFDie &Die) {
233 std::string ReconstructedName;
235 std::string OriginalFullName;
238 if (OriginalFullName.empty() || OriginalFullName == ReconstructedName)
242 "Simplified template DW_AT_name could not be reconstituted", [&]() {
244 <<
"Simplified template DW_AT_name could not be reconstituted:\n"
246 " reconstituted: {1}\n",
247 OriginalFullName, ReconstructedName);
254unsigned DWARFVerifier::verifyUnitContents(
DWARFUnit &Unit,
255 ReferenceMap &UnitLocalReferences,
256 ReferenceMap &CrossUnitReferences) {
257 unsigned NumUnitErrors = 0;
258 unsigned NumDies = Unit.getNumDIEs();
259 for (
unsigned I = 0;
I < NumDies; ++
I) {
260 auto Die = Unit.getDIEAtIndex(
I);
262 if (Die.
getTag() == DW_TAG_null)
266 NumUnitErrors += verifyDebugInfoAttribute(Die, AttrValue);
267 NumUnitErrors += verifyDebugInfoForm(Die, AttrValue, UnitLocalReferences,
268 CrossUnitReferences);
271 NumUnitErrors += verifyName(Die);
277 <<
" has DW_CHILDREN_yes but DIE has no children: ";
282 NumUnitErrors += verifyDebugInfoCallSite(Die);
285 DWARFDie Die = Unit.getUnitDIE(
false);
287 ErrorCategory.
Report(
"Compilation unit missing DIE", [&]() {
288 error() <<
"Compilation unit without DIE.\n";
291 return NumUnitErrors;
295 ErrorCategory.
Report(
"Compilation unit root DIE is not a unit DIE", [&]() {
296 error() <<
"Compilation unit root DIE is not a unit DIE: "
304 ErrorCategory.
Report(
"Mismatched unit type", [&]() {
307 <<
") do not match.\n";
316 ErrorCategory.
Report(
"Skeleton CU has children", [&]() {
317 error() <<
"Skeleton compilation unit has children.\n";
323 NumUnitErrors += verifyDieRanges(Die, RI);
325 return NumUnitErrors;
328unsigned DWARFVerifier::verifyDebugInfoCallSite(
const DWARFDie &Die) {
329 if (Die.
getTag() != DW_TAG_call_site && Die.
getTag() != DW_TAG_GNU_call_site)
334 if (Curr.
getTag() == DW_TAG_inlined_subroutine) {
336 "Call site nested entry within inlined subroutine", [&]() {
337 error() <<
"Call site entry nested within inlined subroutine:";
346 "Call site entry not nested within valid subprogram", [&]() {
347 error() <<
"Call site entry not nested within a valid subprogram:";
353 std::optional<DWARFFormValue> CallAttr = Curr.
find(
354 {DW_AT_call_all_calls, DW_AT_call_all_source_calls,
355 DW_AT_call_all_tail_calls, DW_AT_GNU_all_call_sites,
356 DW_AT_GNU_all_source_call_sites, DW_AT_GNU_all_tail_call_sites});
359 "Subprogram with call site entry has no DW_AT_call attribute", [&]() {
361 <<
"Subprogram with call site entry has no DW_AT_call attribute:";
371unsigned DWARFVerifier::verifyAbbrevSection(
const DWARFDebugAbbrev *Abbrev) {
377 if (!AbbrDeclsOrErr) {
379 ErrorCategory.
Report(
"Abbreviation Declaration error",
380 [&]() {
error() << ErrMsg <<
"\n"; });
384 const auto *AbbrDecls = *AbbrDeclsOrErr;
385 unsigned NumErrors = 0;
386 for (
auto AbbrDecl : *AbbrDecls) {
388 for (
auto Attribute : AbbrDecl.attributes()) {
392 "Abbreviation declartion contains multiple attributes", [&]() {
393 error() <<
"Abbreviation declaration contains multiple "
405 OS <<
"Verifying .debug_abbrev...\n";
408 unsigned NumErrors = 0;
414 return NumErrors == 0;
418 unsigned NumDebugInfoErrors = 0;
419 ReferenceMap CrossUnitReferences;
422 for (
const auto &Unit : Units) {
423 OS <<
"Verifying unit: " <<
Index <<
" / " << Units.getNumUnits();
424 if (
const char*
Name = Unit->getUnitDIE(
true).getShortName())
425 OS <<
", \"" <<
Name <<
'\"';
428 ReferenceMap UnitLocalReferences;
429 NumDebugInfoErrors +=
430 verifyUnitContents(*Unit, UnitLocalReferences, CrossUnitReferences);
431 NumDebugInfoErrors += verifyDebugInfoReferences(
432 UnitLocalReferences, [&](
uint64_t Offset) {
return Unit.get(); });
436 NumDebugInfoErrors += verifyDebugInfoReferences(
443 return NumDebugInfoErrors;
446unsigned DWARFVerifier::verifyUnitSection(
const DWARFSection &S) {
449 unsigned NumDebugInfoErrors = 0;
452 bool isUnitDWARF64 =
false;
453 bool isHeaderChainValid =
true;
460 isHeaderChainValid =
false;
467 if (UnitIdx == 0 && !hasDIE) {
468 warn() <<
"Section is empty.\n";
469 isHeaderChainValid =
true;
471 if (!isHeaderChainValid)
472 ++NumDebugInfoErrors;
473 return NumDebugInfoErrors;
479 if (IndexStr.
empty())
481 OS <<
"Verifying " <<
Name <<
"...\n";
487 MapType::Allocator
Alloc;
488 std::vector<std::unique_ptr<MapType>> Sections(
Index.getColumnKinds().size());
491 if (!
E.getContributions())
494 InfoColumnKind == DW_SECT_INFO
502 Sections[Col] = std::make_unique<MapType>(
Alloc);
503 auto &
M = *Sections[Col];
506 StringRef Category = InfoColumnKind == DWARFSectionKind::DW_SECT_INFO
507 ?
"Overlapping CU index entries"
508 :
"Overlapping TU index entries";
509 ErrorCategory.
Report(Category, [&]() {
511 "overlapping index entries for entries {0:x16} "
512 "and {1:x16} for column {2}\n",
525 return verifyIndex(
".debug_cu_index", DWARFSectionKind::DW_SECT_INFO,
536 unsigned NumErrors = 0;
538 OS <<
"Verifying .debug_info Unit Header Chain...\n";
540 NumErrors += verifyUnitSection(S);
543 OS <<
"Verifying .debug_types Unit Header Chain...\n";
545 NumErrors += verifyUnitSection(S);
548 OS <<
"Verifying non-dwo Units...\n";
551 OS <<
"Verifying dwo Units...\n";
553 return NumErrors == 0;
556unsigned DWARFVerifier::verifyDieRanges(
const DWARFDie &Die,
557 DieRangeInfo &ParentRI) {
558 unsigned NumErrors = 0;
566 if (!RangesOrError) {
568 if (!Unit->isDWOUnit())
577 DieRangeInfo RI(Die);
598 if (!IsObjectFile || IsMachOObject || Die.
getTag() != DW_TAG_compile_unit) {
599 bool DumpDieAfterError =
false;
600 for (
const auto &
Range : Ranges) {
601 if (!
Range.valid()) {
603 ErrorCategory.
Report(
"Invalid address range", [&]() {
604 error() <<
"Invalid address range " <<
Range <<
"\n";
605 DumpDieAfterError =
true;
616 if (
auto PrevRange = RI.insert(
Range)) {
618 ErrorCategory.
Report(
"DIE has overlapping DW_AT_ranges", [&]() {
619 error() <<
"DIE has overlapping ranges in DW_AT_ranges attribute: "
620 << *PrevRange <<
" and " <<
Range <<
'\n';
621 DumpDieAfterError =
true;
625 if (DumpDieAfterError)
626 dump(Die, 2) <<
'\n';
630 const auto IntersectingChild = ParentRI.insert(RI);
631 if (IntersectingChild != ParentRI.Children.end()) {
633 ErrorCategory.
Report(
"DIEs have overlapping address ranges", [&]() {
634 error() <<
"DIEs have overlapping address ranges:";
636 dump(IntersectingChild->Die) <<
'\n';
641 bool ShouldBeContained = !RI.Ranges.empty() && !ParentRI.Ranges.empty() &&
642 !(Die.
getTag() == DW_TAG_subprogram &&
643 ParentRI.Die.getTag() == DW_TAG_subprogram);
644 if (ShouldBeContained && !ParentRI.contains(RI)) {
647 "DIE address ranges are not contained by parent ranges", [&]() {
649 <<
"DIE address ranges are not contained in its parent's ranges:";
651 dump(Die, 2) <<
'\n';
657 NumErrors += verifyDieRanges(Child, RI);
664 for (
unsigned Operand = 0; Operand <
Op.Desc.
Op.
size(); ++Operand) {
665 unsigned Size =
Op.Desc.
Op[Operand];
672 if (
Op.Opcode == DW_OP_convert &&
Op.Operands[Operand] == 0)
674 auto Die =
U->getDIEForOffset(
U->getOffset() +
Op.Operands[Operand]);
675 if (!Die || Die.
getTag() != dwarf::DW_TAG_base_type)
685 if (!verifyExpressionOp(
Op, U))
691unsigned DWARFVerifier::verifyDebugInfoAttribute(
const DWARFDie &Die,
693 unsigned NumErrors = 0;
694 auto ReportError = [&](
StringRef category,
const Twine &TitleMsg) {
696 ErrorCategory.
Report(category, [&]() {
697 error() << TitleMsg <<
'\n';
704 const auto Attr = AttrValue.
Attr;
709 unsigned DwarfVersion =
U->getVersion();
713 if (
U->isDWOUnit() && RangeSection.
Data.
empty())
715 if (*SectionOffset >= RangeSection.
Data.
size())
716 ReportError(
"DW_AT_ranges offset out of bounds",
717 "DW_AT_ranges offset is beyond " +
718 StringRef(DwarfVersion < 5 ?
".debug_ranges"
719 :
".debug_rnglists") +
723 ReportError(
"Invalid DW_AT_ranges encoding",
724 "DIE has invalid DW_AT_ranges encoding:");
726 case DW_AT_stmt_list:
729 if (*SectionOffset >=
U->getLineSection().Data.size())
730 ReportError(
"DW_AT_stmt_list offset out of bounds",
731 "DW_AT_stmt_list offset is beyond .debug_line bounds: " +
735 ReportError(
"Invalid DW_AT_stmt_list encoding",
736 "DIE has invalid DW_AT_stmt_list encoding:");
738 case DW_AT_location: {
749 if (
Expected<std::vector<DWARFLocationExpression>> Loc =
751 for (
const auto &Entry : *Loc) {
754 U->getFormParams().Format);
760 ReportError(
"Invalid DWARF expressions",
761 "DIE contains invalid DWARF expression:");
764 Loc.takeError(), [&](std::unique_ptr<ResolverError>
E) {
765 return U->isDWOUnit() ? Error::success()
766 : Error(std::move(E));
768 ReportError(
"Invalid DW_AT_location",
toString(std::move(Err)));
771 case DW_AT_specification:
772 case DW_AT_abstract_origin: {
774 auto DieTag = Die.
getTag();
775 auto RefTag = ReferencedDie.getTag();
776 if (DieTag == RefTag)
778 if (DieTag == DW_TAG_inlined_subroutine && RefTag == DW_TAG_subprogram)
780 if (DieTag == DW_TAG_variable && RefTag == DW_TAG_member)
783 if (DieTag == DW_TAG_GNU_call_site && RefTag == DW_TAG_subprogram)
785 ReportError(
"Incompatible DW_AT_abstract_origin tag reference",
786 "DIE with tag " +
TagString(DieTag) +
" has " +
788 " that points to DIE with "
789 "incompatible tag " +
797 ReportError(
"Incompatible DW_AT_type attribute tag",
803 case DW_AT_call_file:
804 case DW_AT_decl_file: {
806 if (
U->isDWOUnit() && !
U->isTypeUnit())
808 const auto *
LT =
U->getContext().getLineTableForUnit(U);
810 if (!
LT->hasFileAtIndex(*FileIdx)) {
811 bool IsZeroIndexed =
LT->Prologue.getVersion() >= 5;
812 if (std::optional<uint64_t> LastFileIdx =
813 LT->getLastValidFileIndex()) {
814 ReportError(
"Invalid file index in DW_AT_decl_file",
816 " with an invalid file index " +
818 " (valid values are [" +
819 (IsZeroIndexed ?
"0-" :
"1-") +
822 ReportError(
"Invalid file index in DW_AT_decl_file",
824 " with an invalid file index " +
826 " (the file table in the prologue is empty)");
831 "File index in DW_AT_decl_file reference CU with no line table",
833 " that references a file with index " +
835 " and the compile unit has no line table");
838 ReportError(
"Invalid encoding in DW_AT_decl_file",
840 " with invalid encoding");
844 case DW_AT_call_line:
845 case DW_AT_decl_line: {
848 Attr == DW_AT_call_line ?
"Invalid file index in DW_AT_decl_line"
849 :
"Invalid file index in DW_AT_call_line",
860unsigned DWARFVerifier::verifyDebugInfoForm(
const DWARFDie &Die,
862 ReferenceMap &LocalReferences,
863 ReferenceMap &CrossUnitReferences) {
865 unsigned NumErrors = 0;
872 case DW_FORM_ref_udata: {
877 auto CUSize = DieCU->getNextUnitOffset() - DieCU->getOffset();
879 if (CUOffset >= CUSize) {
881 ErrorCategory.
Report(
"Invalid CU offset", [&]() {
883 <<
format(
"0x%08" PRIx64, CUOffset)
884 <<
" is invalid (must be less than CU size of "
885 <<
format(
"0x%08" PRIx64, CUSize) <<
"):\n";
886 Die.
dump(
OS, 0, DumpOpts);
898 case DW_FORM_ref_addr: {
904 if (*RefVal >= DieCU->getInfoSection().Data.size()) {
906 ErrorCategory.
Report(
"DW_FORM_ref_addr offset out of bounds", [&]() {
907 error() <<
"DW_FORM_ref_addr offset beyond .debug_info "
914 CrossUnitReferences[*RefVal].insert(Die.
getOffset());
925 case DW_FORM_line_strp: {
928 std::string ErrMsg =
toString(std::move(
E));
929 ErrorCategory.
Report(
"Invalid DW_FORM attribute", [&]() {
930 error() << ErrMsg <<
":\n";
942unsigned DWARFVerifier::verifyDebugInfoReferences(
943 const ReferenceMap &References,
947 return U->getDIEForOffset(
Offset);
950 unsigned NumErrors = 0;
951 for (
const std::pair<
const uint64_t, std::set<uint64_t>> &Pair :
953 if (GetDIEForOffset(Pair.first))
956 ErrorCategory.
Report(
"Invalid DIE reference", [&]() {
957 error() <<
"invalid DIE reference " <<
format(
"0x%08" PRIx64, Pair.first)
958 <<
". Offset is in between DIEs:\n";
959 for (
auto Offset : Pair.second)
967void DWARFVerifier::verifyDebugLineStmtOffsets() {
968 std::map<uint64_t, DWARFDie> StmtListToDie;
970 auto Die =
CU->getUnitDIE();
975 if (!StmtSectionOffset)
977 const uint64_t LineTableOffset = *StmtSectionOffset;
981 ++NumDebugLineErrors;
982 ErrorCategory.
Report(
"Unparsable .debug_line entry", [&]() {
983 error() <<
".debug_line[" <<
format(
"0x%08" PRIx64, LineTableOffset)
984 <<
"] was not able to be parsed for CU:\n";
991 assert(LineTable ==
nullptr);
996 auto [Iter,
Inserted] = StmtListToDie.try_emplace(LineTableOffset, Die);
998 ++NumDebugLineErrors;
999 const auto &OldDie = Iter->second;
1000 ErrorCategory.
Report(
"Identical DW_AT_stmt_list section offset", [&]() {
1001 error() <<
"two compile unit DIEs, "
1002 <<
format(
"0x%08" PRIx64, OldDie.getOffset()) <<
" and "
1004 <<
", have the same DW_AT_stmt_list section offset:\n";
1013void DWARFVerifier::verifyDebugLineRows() {
1015 auto Die =
CU->getUnitDIE();
1024 uint32_t MaxDirIndex = LineTable->Prologue.IncludeDirectories.size();
1025 uint32_t MinFileIndex = isDWARF5 ? 0 : 1;
1028 for (
const auto &FileName : LineTable->Prologue.FileNames) {
1030 if (FileName.DirIdx > MaxDirIndex) {
1031 ++NumDebugLineErrors;
1033 "Invalid index in .debug_line->prologue.file_names->dir_idx",
1035 error() <<
".debug_line["
1036 <<
format(
"0x%08" PRIx64,
1038 <<
"].prologue.file_names[" << FileIndex
1039 <<
"].dir_idx contains an invalid index: "
1040 << FileName.DirIdx <<
"\n";
1045 std::string FullPath;
1046 const bool HasFullPath = LineTable->getFileNameByIndex(
1047 FileIndex,
CU->getCompilationDir(),
1048 DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath, FullPath);
1049 assert(HasFullPath &&
"Invalid index?");
1052 if (!Inserted && It->second != FileIndex && DumpOpts.
Verbose) {
1053 warn() <<
".debug_line["
1054 <<
format(
"0x%08" PRIx64,
1056 <<
"].prologue.file_names[" << FileIndex
1057 <<
"] is a duplicate of file_names[" << It->second <<
"]\n";
1065 if (LineTable->Rows.size() == 1 && LineTable->Rows.front().EndSequence)
1071 for (
const auto &Row : LineTable->Rows) {
1073 if (Row.Address.Address < PrevAddress) {
1074 ++NumDebugLineErrors;
1076 "decreasing address between debug_line rows", [&]() {
1077 error() <<
".debug_line["
1078 <<
format(
"0x%08" PRIx64,
1080 <<
"] row[" << RowIndex
1081 <<
"] decreases in address from previous row:\n";
1085 LineTable->Rows[RowIndex - 1].dump(
OS);
1091 if (!LineTable->hasFileAtIndex(Row.File)) {
1092 ++NumDebugLineErrors;
1093 ErrorCategory.
Report(
"Invalid file index in debug_line", [&]() {
1094 error() <<
".debug_line["
1095 <<
format(
"0x%08" PRIx64,
1097 <<
"][" << RowIndex <<
"] has invalid file index " << Row.File
1098 <<
" (valid values are [" << MinFileIndex <<
','
1099 << LineTable->Prologue.FileNames.size()
1100 << (isDWARF5 ?
")" :
"]") <<
"):\n";
1106 if (Row.EndSequence)
1109 PrevAddress = Row.Address.Address;
1118 IsMachOObject(
false) {
1120 !this->DumpOpts.ShowAggregateErrors);
1122 IsObjectFile =
F->isRelocatableObject();
1123 IsMachOObject =
F->isMachO();
1128 NumDebugLineErrors = 0;
1129 OS <<
"Verifying .debug_line...\n";
1130 verifyDebugLineStmtOffsets();
1131 verifyDebugLineRows();
1132 return NumDebugLineErrors == 0;
1135void DWARFVerifier::verifyAppleAccelTable(
const DWARFSection *AccelSection,
1145 if (!AccelSectionData.isValidOffset(
AccelTable.getSizeHdr())) {
1146 ErrorCategory.
Report(
"Section is too small to fit a section header", [&]() {
1147 error() <<
"Section is too small to fit a section header.\n";
1154 std::string Msg =
toString(std::move(
E));
1155 ErrorCategory.
Report(
"Section is too small to fit a section header",
1156 [&]() {
error() << Msg <<
'\n'; });
1166 uint64_t HashesBase = BucketsOffset + NumBuckets * 4;
1167 uint64_t OffsetsBase = HashesBase + NumHashes * 4;
1168 for (
uint32_t BucketIdx = 0; BucketIdx < NumBuckets; ++BucketIdx) {
1169 uint32_t HashIdx = AccelSectionData.getU32(&BucketsOffset);
1170 if (HashIdx >= NumHashes && HashIdx != UINT32_MAX) {
1171 ErrorCategory.
Report(
"Invalid hash index", [&]() {
1172 error() <<
format(
"Bucket[%d] has invalid hash index: %u.\n", BucketIdx,
1178 if (NumAtoms == 0) {
1179 ErrorCategory.
Report(
"No atoms", [&]() {
1180 error() <<
"No atoms: failed to read HashData.\n";
1185 ErrorCategory.
Report(
"Unsupported form", [&]() {
1186 error() <<
"Unsupported form: failed to read HashData.\n";
1191 for (
uint32_t HashIdx = 0; HashIdx < NumHashes; ++HashIdx) {
1192 uint64_t HashOffset = HashesBase + 4 * HashIdx;
1193 uint64_t DataOffset = OffsetsBase + 4 * HashIdx;
1194 uint32_t Hash = AccelSectionData.getU32(&HashOffset);
1195 uint64_t HashDataOffset = AccelSectionData.getU32(&DataOffset);
1196 if (!AccelSectionData.isValidOffsetForDataOfSize(HashDataOffset,
1198 ErrorCategory.
Report(
"Invalid HashData offset", [&]() {
1199 error() <<
format(
"Hash[%d] has invalid HashData offset: "
1200 "0x%08" PRIx64
".\n",
1201 HashIdx, HashDataOffset);
1210 while ((StrpOffset = AccelSectionData.getU32(&HashDataOffset)) != 0) {
1211 const uint32_t NumHashDataObjects =
1212 AccelSectionData.getU32(&HashDataOffset);
1213 for (
uint32_t HashDataIdx = 0; HashDataIdx < NumHashDataObjects;
1219 NumBuckets ? (Hash % NumBuckets) : UINT32_MAX;
1220 StringOffset = StrpOffset;
1221 const char *
Name = StrData->
getCStr(&StringOffset);
1225 ErrorCategory.
Report(
"Invalid DIE offset", [&]() {
1227 "%s Bucket[%d] Hash[%d] = 0x%08x "
1228 "Str[%u] = 0x%08" PRIx64
" DIE[%d] = 0x%08" PRIx64
" "
1229 "is not a valid DIE offset for \"%s\".\n",
1230 SectionName, BucketIdx, HashIdx, Hash, StringCount, StrpOffset,
1235 if ((
Tag != dwarf::DW_TAG_null) && (Die.
getTag() !=
Tag)) {
1236 ErrorCategory.
Report(
"Mismatched Tag in accellerator table", [&]() {
1238 <<
" in accelerator table does not match Tag "
1240 << HashDataIdx <<
"].\n";
1260 ErrorCategory.Report(
"Name Index doesn't index any CU", [&]() {
1261 error() << formatv(
"Name Index @ {0:x} does not index any CU\n",
1262 NI.getUnitOffset());
1269 ErrorCategory.
Report(
"Name Index references non-existing CU", [&]() {
1271 "Name Index @ {0:x} references a non-existing CU @ {1:x}\n",
1278 std::lock_guard<std::mutex> Lock(AccessMutex);
1280 if (Iter != CUMap.
end())
1281 DuplicateCUOffset = Iter->second;
1285 if (DuplicateCUOffset) {
1286 ErrorCategory.
Report(
"Duplicate Name Index", [&]() {
1288 "Name Index @ {0:x} references a CU @ {1:x}, but "
1289 "this CU is already indexed by Name Index @ {2:x}\n",
1297 for (
const auto &
CU : DCtx.compile_units()) {
1298 if (CUMap.
count(
CU->getOffset()) == 0)
1299 warn() <<
formatv(
"CU @ {0:x} not covered by any Name Index\n",
1316 warn() <<
formatv(
"Name Index @ {0:x} does not contain a hash table.\n",
1323 std::vector<BucketInfo> BucketStarts;
1329 ErrorCategory.
Report(
"Name Index Bucket contains invalid value", [&]() {
1330 error() <<
formatv(
"Bucket {0} of Name Index @ {1:x} contains invalid "
1331 "value {2}. Valid range is [0, {3}].\n",
1338 BucketStarts.emplace_back(Bucket,
Index);
1344 if (OrigNumberOfErrors != ErrorCategory.
GetNumErrors())
1358 for (
const BucketInfo &
B : BucketStarts) {
1365 if (
B.Index > NextUncovered) {
1366 ErrorCategory.
Report(
"Name table entries uncovered by hash table", [&]() {
1367 error() <<
formatv(
"Name Index @ {0:x}: Name table entries [{1}, {2}] "
1368 "are not covered by the hash table.\n",
1385 ErrorCategory.
Report(
"Name Index point to mismatched hash value", [&]() {
1387 "Name Index @ {0:x}: Bucket {1} is not empty but points to a "
1388 "mismatched hash value {2:x} (belonging to bucket {3}).\n",
1405 "String hash doesn't match Name Index hash", [&]() {
1407 "Name Index @ {0:x}: String ({1}) at index {2} "
1408 "hashes to {3:x}, but "
1409 "the Name Index hash is {4:x}\n",
1415 NextUncovered = std::max(NextUncovered,
Idx);
1419void DWARFVerifier::verifyNameIndexAttribute(
1423 if (FormName.
empty()) {
1424 ErrorCategory.
Report(
"Unknown NameIndex Abbreviation", [&]() {
1425 error() <<
formatv(
"NameIndex @ {0:x}: Abbreviation {1:x}: {2} uses an "
1426 "unknown form: {3}.\n",
1433 if (AttrEnc.
Index == DW_IDX_type_hash) {
1434 if (AttrEnc.
Form != dwarf::DW_FORM_data8) {
1435 ErrorCategory.
Report(
"Unexpected NameIndex Abbreviation", [&]() {
1437 "NameIndex @ {0:x}: Abbreviation {1:x}: DW_IDX_type_hash "
1438 "uses an unexpected form {2} (should be {3}).\n",
1446 if (AttrEnc.
Index == dwarf::DW_IDX_parent) {
1447 constexpr static auto AllowedForms = {dwarf::Form::DW_FORM_flag_present,
1448 dwarf::Form::DW_FORM_ref4};
1450 ErrorCategory.
Report(
"Unexpected NameIndex Abbreviation", [&]() {
1452 "NameIndex @ {0:x}: Abbreviation {1:x}: DW_IDX_parent "
1453 "uses an unexpected form {2} (should be "
1454 "DW_FORM_ref4 or DW_FORM_flag_present).\n",
1465 struct FormClassTable {
1470 static constexpr FormClassTable Table[] = {
1478 return T.Index == AttrEnc.
Index;
1481 warn() <<
formatv(
"NameIndex @ {0:x}: Abbreviation {1:x} contains an "
1482 "unknown index attribute: {2}.\n",
1488 ErrorCategory.
Report(
"Unexpected NameIndex Abbreviation", [&]() {
1489 error() <<
formatv(
"NameIndex @ {0:x}: Abbreviation {1:x}: {2} uses an "
1490 "unexpected form {3} (expected form class {4}).\n",
1492 AttrEnc.
Form, Iter->ClassName);
1498void DWARFVerifier::verifyNameIndexAbbrevs(
1502 if (TagName.
empty()) {
1503 warn() <<
formatv(
"NameIndex @ {0:x}: Abbreviation {1:x} references an "
1504 "unknown tag: {2}.\n",
1508 for (
const auto &AttrEnc : Abbrev.Attributes) {
1511 "NameIndex Abbreviateion contains multiple attributes", [&]() {
1513 "NameIndex @ {0:x}: Abbreviation {1:x} contains "
1514 "multiple {2} attributes.\n",
1519 verifyNameIndexAttribute(NI, Abbrev, AttrEnc);
1523 !
Attributes.count(dwarf::DW_IDX_type_unit)) {
1524 ErrorCategory.
Report(
"Abbreviation contains no attribute", [&]() {
1525 error() <<
formatv(
"NameIndex @ {0:x}: Indexing multiple compile units "
1526 "and abbreviation {1:x} has no DW_IDX_compile_unit "
1527 "or DW_IDX_type_unit attribute.\n",
1531 if (!
Attributes.count(dwarf::DW_IDX_die_offset)) {
1532 ErrorCategory.
Report(
"Abbreviate in NameIndex missing attribute", [&]() {
1534 "NameIndex @ {0:x}: Abbreviation {1:x} has no {2} attribute.\n",
1544 bool IncludeStrippedTemplateNames,
1545 bool IncludeObjCNames =
true,
1546 bool IncludeLinkageName =
true) {
1548 if (
const char *Str =
DIE.getShortName()) {
1550 Result.emplace_back(
Name);
1551 if (IncludeStrippedTemplateNames) {
1552 if (std::optional<StringRef> StrippedName =
1556 Result.push_back(StrippedName->str());
1559 if (IncludeObjCNames) {
1560 if (std::optional<ObjCSelectorNames> ObjCNames =
1562 Result.emplace_back(ObjCNames->ClassName);
1563 Result.emplace_back(ObjCNames->Selector);
1564 if (ObjCNames->ClassNameNoCategory)
1565 Result.emplace_back(*ObjCNames->ClassNameNoCategory);
1566 if (ObjCNames->MethodNameNoCategory)
1567 Result.push_back(std::move(*ObjCNames->MethodNameNoCategory));
1570 }
else if (
DIE.
getTag() == dwarf::DW_TAG_namespace)
1571 Result.emplace_back(
"(anonymous namespace)");
1573 if (IncludeLinkageName) {
1574 if (
const char *Str =
DIE.getLinkageName())
1575 Result.emplace_back(Str);
1581void DWARFVerifier::verifyNameIndexEntries(
1587 ErrorCategory.
Report(
"Unable to get string associated with name", [&]() {
1588 error() <<
formatv(
"Name Index @ {0:x}: Unable to get string associated "
1599 for (; EntryOr; ++
NumEntries, EntryID = NextEntryID,
1600 EntryOr = NI.
getEntry(&NextEntryID)) {
1602 std::optional<uint64_t> CUIndex = EntryOr->getRelatedCUIndex();
1603 std::optional<uint64_t> TUIndex = EntryOr->getTUIndex();
1604 if (CUIndex && *CUIndex >= NI.
getCUCount()) {
1605 ErrorCategory.
Report(
"Name Index entry contains invalid CU index", [&]() {
1606 error() <<
formatv(
"Name Index @ {0:x}: Entry @ {1:x} contains an "
1607 "invalid CU index ({2}).\n",
1614 if (TUIndex && *TUIndex >= (NumLocalTUs + NumForeignTUs)) {
1615 ErrorCategory.
Report(
"Name Index entry contains invalid TU index", [&]() {
1616 error() <<
formatv(
"Name Index @ {0:x}: Entry @ {1:x} contains an "
1617 "invalid TU index ({2}).\n",
1622 std::optional<uint64_t> UnitOffset;
1625 if (*TUIndex >= NumLocalTUs) {
1639 "Name Index entry contains foreign TU index with invalid CU "
1643 "Name Index @ {0:x}: Entry @ {1:x} contains an "
1644 "foreign TU index ({2}) with no CU index.\n",
1653 }
else if (CUIndex) {
1659 if (!UnitOffset || UnitOffset == UINT32_MAX)
1665 if (DU ==
nullptr || DU->
getOffset() != *UnitOffset) {
1669 "Name Index entry contains invalid CU or TU offset", [&]() {
1670 error() <<
formatv(
"Name Index @ {0:x}: Entry @ {1:x} contains an "
1671 "invalid CU or TU offset {2:x}.\n",
1690 NonSkeletonUnit = Iter->second;
1692 NonSkeletonUnit = DU;
1696 ErrorCategory.
Report(
"Unable to get load .dwo file", [&]() {
1698 "Name Index @ {0:x}: Entry @ {1:x} unable to load "
1699 ".dwo file \"{2}\" for DWARF unit @ {3:x}.\n",
1707 if (TUIndex && *TUIndex >= NumLocalTUs) {
1715 const uint32_t ForeignTUIdx = *TUIndex - NumLocalTUs;
1725 if (NonSkeletonDCtx.
isDWP()) {
1728 UnitDie.
find({DW_AT_dwo_name, DW_AT_GNU_dwo_name}));
1730 NonSkeletonUnitDie.
find({DW_AT_dwo_name, DW_AT_GNU_dwo_name}));
1731 if (DUDwoName != TUDwoName)
1736 NonSkeletonUnit->
getOffset() + *EntryOr->getDIEUnitOffset();
1740 if (DIEOffset >= NextUnitOffset) {
1741 ErrorCategory.
Report(
"NameIndex relative DIE offset too large", [&]() {
1742 error() <<
formatv(
"Name Index @ {0:x}: Entry @ {1:x} references a "
1743 "DIE @ {2:x} when CU or TU ends at {3:x}.\n",
1751 ErrorCategory.
Report(
"NameIndex references nonexistent DIE", [&]() {
1752 error() <<
formatv(
"Name Index @ {0:x}: Entry @ {1:x} references a "
1753 "non-existing DIE @ {2:x}.\n",
1762 if (
DIE.getDwarfUnit() == DU &&
1764 ErrorCategory.
Report(
"Name index contains mismatched CU of DIE", [&]() {
1766 "Name Index @ {0:x}: Entry @ {1:x}: mismatched CU of "
1767 "DIE @ {2:x}: index - {3:x}; debug_info - {4:x}.\n",
1773 ErrorCategory.
Report(
"Name Index contains mismatched Tag of DIE", [&]() {
1775 "Name Index @ {0:x}: Entry @ {1:x}: mismatched Tag of "
1776 "DIE @ {2:x}: index - {3}; debug_info - {4}.\n",
1784 auto IncludeStrippedTemplateNames =
1786 DIE.
getTag() == DW_TAG_inlined_subroutine;
1787 auto EntryNames =
getNames(
DIE, IncludeStrippedTemplateNames);
1789 ErrorCategory.
Report(
"Name Index contains mismatched name of DIE", [&]() {
1790 error() <<
formatv(
"Name Index @ {0:x}: Entry @ {1:x}: mismatched Name "
1791 "of DIE @ {2:x}: index - {3}; debug_info - {4}.\n",
1793 make_range(EntryNames.begin(), EntryNames.end()));
1798 EntryOr.takeError(),
1802 ErrorCategory.Report(
1803 "NameIndex Name is not associated with any entries", [&]() {
1804 error() << formatv(
"Name Index @ {0:x}: Name {1} ({2}) is "
1805 "not associated with any entries.\n",
1806 NI.getUnitOffset(), NTE.getIndex(), Str);
1810 ErrorCategory.Report(
"Uncategorized NameIndex error", [&]() {
1811 error() <<
formatv(
"Name Index @ {0:x}: Name {1} ({2}): {3}\n",
1826 for (
const auto &Entry : *Loc) {
1828 U->getAddressByteSize());
1830 U->getFormParams().Format);
1831 bool IsInteresting =
1834 Op.
getCode() == DW_OP_form_tls_address ||
1835 Op.
getCode() == DW_OP_GNU_push_tls_address);
1843void DWARFVerifier::verifyNameIndexCompleteness(
1852 if (Die.
find(DW_AT_declaration))
1862 auto IncludeLinkageName = Die.
getTag() == DW_TAG_subprogram ||
1863 Die.
getTag() == DW_TAG_inlined_subroutine;
1866 auto IncludeStrippedTemplateNames =
false;
1867 auto IncludeObjCNames =
false;
1868 auto EntryNames =
getNames(Die, IncludeStrippedTemplateNames,
1869 IncludeObjCNames, IncludeLinkageName);
1870 if (EntryNames.empty())
1880 case DW_TAG_compile_unit:
1886 case DW_TAG_formal_parameter:
1887 case DW_TAG_template_value_parameter:
1888 case DW_TAG_template_type_parameter:
1889 case DW_TAG_GNU_template_parameter_pack:
1890 case DW_TAG_GNU_template_template_param:
1900 case DW_TAG_enumerator:
1905 case DW_TAG_imported_declaration:
1911 case DW_TAG_subprogram:
1912 case DW_TAG_inlined_subroutine:
1915 {DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges, DW_AT_entry_pc}))
1924 case DW_TAG_variable:
1937 auto iter = NamesToDieOffsets.find(
Name);
1938 if (iter == NamesToDieOffsets.end() || !iter->second.count(DieUnitOffset)) {
1940 "Name Index DIE entry missing name",
1943 "Name Index @ {0:x}: Entry for DIE @ {1:x} ({2}) with "
1944 "name {3} missing.\n",
1945 NI.getUnitOffset(), Die.getOffset(), Die.getTag(), Name);
1957 CUTU->getBaseAddress();
1960 if (Error E = CUTU->tryExtractDIEsIfNeeded(false))
1961 DCtx.getRecoverableErrorHandler()(std::move(E));
1967 if (!
CU->getDWOId())
1970 CU->getNonSkeletonUnitDIE().getDwarfUnit()->getContext();
1972 for (
auto &CUTU : NonSkeletonContext.
dwo_units()) {
1974 CUTU->getBaseAddress();
1977 if (Error E = CUTU->tryExtractDIEsIfNeeded(false))
1978 DCtx.getRecoverableErrorHandler()(std::move(E));
1981 if (NonSkeletonContext.
isDWP())
1986void DWARFVerifier::verifyDebugNames(
const DWARFSection &AccelSection,
1992 OS <<
"Verifying .debug_names...\n";
1997 std::string Msg =
toString(std::move(E));
1998 ErrorCategory.
Report(
"Accelerator Table Error",
1999 [&]() { error() << Msg <<
'\n'; });
2005 verifyNameIndexBuckets(NI, StrData);
2007 verifyNameIndexAbbrevs(NI);
2015 if (!(
CU->getVersion() >= 5 &&
CU->getDWOId()))
2017 CUOffsetsToDUMap[
CU->getOffset()] =
2018 CU->getNonSkeletonUnitDIE().getDwarfUnit();
2023 verifyNameIndexEntries(NI, NTE, CUOffsetsToDUMap);
2027 auto populateNameToOffset =
2032 const std::string
Name = tName ? std::string(tName) :
"";
2036 for (; EntryOr; EntryOr = NI.getEntry(&EntryID)) {
2037 if (std::optional<uint64_t> DieOffset = EntryOr->getDIEUnitOffset())
2038 Iter.first->second.insert(*DieOffset);
2043 if (!NamesToDieOffsets.empty())
2045 ErrorCategory.Report(
2046 "NameIndex Name is not associated with any entries", [&]() {
2048 << formatv(
"Name Index @ {0:x}: Name {1} ({2}) is "
2049 "not associated with any entries.\n",
2050 NI.getUnitOffset(), NTE.getIndex(), Name);
2054 ErrorCategory.
Report(
"Uncategorized NameIndex error", [&]() {
2056 "Name Index @ {0:x}: Name {1} ({2}): {3}\n",
2066 populateNameToOffset(NI, NamesToDieOffsets);
2067 for (
uint32_t i = 0, iEnd = NI.getCUCount(); i < iEnd; ++i) {
2068 const uint64_t CUOffset = NI.getCUOffset(i);
2069 DWARFUnit *
U = DCtx.getUnitForOffset(CUOffset);
2072 if (
CU->getDWOId()) {
2076 if (CUDie != NonSkeletonUnitDie) {
2080 verifyNameIndexCompleteness(
2081 DWARFDie(NonSkeletonUnitDie.getDwarfUnit(), &Die), NI,
2087 verifyNameIndexCompleteness(DWARFDie(CU, &Die), NI,
2099 if (!
D.getAppleNamesSection().Data.empty())
2100 verifyAppleAccelTable(&
D.getAppleNamesSection(), &StrData,
".apple_names");
2101 if (!
D.getAppleTypesSection().Data.empty())
2102 verifyAppleAccelTable(&
D.getAppleTypesSection(), &StrData,
".apple_types");
2103 if (!
D.getAppleNamespacesSection().Data.empty())
2104 verifyAppleAccelTable(&
D.getAppleNamespacesSection(), &StrData,
2105 ".apple_namespaces");
2106 if (!
D.getAppleObjCSection().Data.empty())
2107 verifyAppleAccelTable(&
D.getAppleObjCSection(), &StrData,
".apple_objc");
2109 if (!
D.getNamesSection().Data.empty())
2110 verifyDebugNames(
D.getNamesSection(), StrData);
2115 OS <<
"Verifying .debug_str_offsets...\n";
2124 std::optional<DwarfFormat> DwoLegacyDwarf4Format;
2126 if (DwoLegacyDwarf4Format)
2132 DwoLegacyDwarf4Format = InfoFormat;
2136 DwoLegacyDwarf4Format,
".debug_str_offsets.dwo",
2139 std::nullopt,
".debug_str_offsets",
2153 while (
C.seek(NextUnit),
C.tell() < DA.getData().size()) {
2159 Length = DA.getData().size();
2165 if (
C.tell() +
Length > DA.getData().size()) {
2167 "Section contribution length exceeds available space", [&]() {
2169 "{0}: contribution {1:X}: length exceeds available space "
2171 "offset ({1:X}) + length field space ({2:X}) + length "
2173 "{4:X} > section size {5:X})\n",
2175 C.tell() +
Length, DA.getData().size());
2184 ErrorCategory.
Report(
"Invalid Section version", [&]() {
2185 error() <<
formatv(
"{0}: contribution {1:X}: invalid version {2}\n",
2196 DA.setAddressSize(OffsetByteSize);
2198 if (Remainder != 0) {
2199 ErrorCategory.
Report(
"Invalid section contribution length", [&]() {
2201 "{0}: contribution {1:X}: invalid length ((length ({2:X}) "
2202 "- header (0x4)) % offset size {3:X} == {4:X} != 0)\n",
2213 if (StrData.
size() <= StrOff) {
2215 "String offset out of bounds of string section", [&]() {
2217 "{0}: contribution {1:X}: index {2:X}: invalid string "
2218 "offset *{3:X} == {4:X}, is beyond the bounds of the string "
2219 "section of length {5:X}\n",
2225 if (StrData[StrOff - 1] ==
'\0')
2228 "Section contribution contains invalid string offset", [&]() {
2230 "{0}: contribution {1:X}: index {2:X}: invalid string "
2231 "offset *{3:X} == {4:X}, is neither zero nor "
2232 "immediately following a null character\n",
2239 if (
Error E =
C.takeError()) {
2240 std::string Msg =
toString(std::move(E));
2241 ErrorCategory.
Report(
"String offset error", [&]() {
2250 StringRef s, std::function<
void(
void)> detailCallback) {
2251 this->
Report(s,
"", detailCallback);
2256 std::function<
void(
void)> detailCallback) {
2257 std::lock_guard<std::mutex> Lock(WriteMutex);
2259 std::string category_str = std::string(category);
2262 if (!sub_category.
empty()) {
2270 std::function<
void(
StringRef,
unsigned)> handleCounts) {
2271 for (
const auto &[
name, aggData] : Aggregation) {
2272 handleCounts(
name, aggData.OverallCount);
2277 const auto Agg = Aggregation.find(category);
2278 if (Agg != Aggregation.end()) {
2280 handleCounts(
name, aggData);
2287 error() <<
"Aggregated error counts:\n";
2289 error() << s <<
" occurred " <<
count <<
" time(s).\n";
2297 error() <<
"unable to open json summary file '"
2299 <<
"' for writing: " << EC.message() <<
'\n';
2310 Category, [&](
StringRef SubCategory,
unsigned SubCount) {
2315 ErrorCount += Count;
2318 RootNode.
try_emplace(
"error-categories", std::move(Categories));
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
ArrayRef< TableEntry > TableRef
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Analysis containing CSE Info
static void extractCUsTus(DWARFContext &DCtx)
Extracts all the data for CU/TUs so we can access it in parallel without locks.
static bool isVariableIndexable(const DWARFDie &Die, DWARFContext &DCtx)
static SmallVector< std::string, 3 > getNames(const DWARFDie &DIE, bool IncludeStrippedTemplateNames, bool IncludeObjCNames=true, bool IncludeLinkageName=true)
Constructs a full name for a DIE.
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
This file contains constants used for implementing Dwarf debug support.
This file implements a coalescing interval map for small objects.
This file supports working with JSON data.
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
This file defines the SmallSet class.
This class holds an abstract representation of an Accelerator Table, consisting of a sequence of buck...
This implements the Apple accelerator table format, a precursor of the DWARF 5 accelerator table form...
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
A structured debug information entry.
unsigned getOffset() const
Get the compile/type unit relative offset of this DIE.
dwarf::Tag getTag() const
DWARFContext This data structure is the top level entity that deals with dwarf debug information pars...
static bool isSupportedVersion(unsigned version)
unsigned getNumCompileUnits()
Get the number of compile units in this context.
DWARFDie getDIEForOffset(uint64_t Offset)
Get a DIE given an exact offset.
const DWARFDebugAbbrev * getDebugAbbrevDWO()
Get a pointer to the parsed dwo abbreviations object.
compile_unit_range compile_units()
Get compile units in this context.
const DWARFDebugAbbrev * getDebugAbbrev()
Get a pointer to the parsed DebugAbbrev object.
bool isDWP() const
Return true of this DWARF context is a DWP file.
bool isLittleEndian() const
const DWARFDebugLine::LineTable * getLineTableForUnit(DWARFUnit *U)
Get a pointer to a parsed line table corresponding to a compile unit.
DWARFUnit * getUnitForOffset(uint64_t Offset)
Return the DWARF unit that includes an offset (relative to .debug_info).
const DWARFUnitVector & getNormalUnitsVector()
DWARFTypeUnit * getTypeUnitForHash(uint64_t Hash, bool IsDWO)
unit_iterator_range normal_units()
Get all normal compile/type units in this context.
static bool isAddressSizeSupported(unsigned AddressSize)
const DWARFUnitVector & getDWOUnitsVector()
unit_iterator_range dwo_units()
Get all units in the DWO context.
const DWARFObject & getDWARFObj() const
LLVM_ABI Expected< const DWARFAbbreviationDeclarationSet * > getAbbreviationDeclarationSet(uint64_t CUAbbrOffset) const
DWARFDebugInfoEntry - A DIE with only the minimum required data.
Represents a single accelerator table within the DWARF v5 .debug_names section.
LLVM_ABI uint32_t getHashArrayEntry(uint32_t Index) const
Reads an entry in the Hash Array for the given Index.
LLVM_ABI uint64_t getLocalTUOffset(uint32_t TU) const
Reads offset of local type unit TU, TU is 0-based.
LLVM_ABI uint32_t getBucketArrayEntry(uint32_t Bucket) const
Reads an entry in the Bucket Array for the given Bucket.
uint64_t getUnitOffset() const
uint32_t getCUCount() const
LLVM_ABI uint64_t getCUOffset(uint32_t CU) const
Reads offset of compilation unit CU. CU is 0-based.
LLVM_ABI Expected< Entry > getEntry(uint64_t *Offset) const
LLVM_ABI NameTableEntry getNameTableEntry(uint32_t Index) const
Reads an entry in the Name Table for the given Index.
uint32_t getNameCount() const
const DenseSet< Abbrev, AbbrevMapInfo > & getAbbrevs() const
uint32_t getForeignTUCount() const
LLVM_ABI uint64_t getForeignTUSignature(uint32_t TU) const
Reads signature of foreign type unit TU. TU is 0-based.
uint32_t getBucketCount() const
uint32_t getLocalTUCount() const
A single entry in the Name Table (DWARF v5 sect.
uint64_t getEntryOffset() const
Returns the offset of the first Entry in the list.
const char * getString() const
Return the string referenced by this name table entry or nullptr if the string offset is not valid.
uint32_t getIndex() const
Return the index of this name in the parent Name Index.
Error returned by NameIndex::getEntry to report it has reached the end of the entry list.
.debug_names section consists of one or more units.
Utility class that carries the DWARF compile/type unit and the debug info entry in an object.
LLVM_ABI void getFullName(raw_string_ostream &, std::string *OriginalFullName=nullptr) const
uint64_t getOffset() const
Get the absolute offset into the debug info or types section.
LLVM_ABI Expected< DWARFAddressRangesVector > getAddressRanges() const
Get the address ranges for this DIE.
LLVM_ABI DWARFDie getAttributeValueAsReferencedDie(dwarf::Attribute Attr) const
Extract the specified attribute from this DIE as the referenced DIE.
LLVM_ABI DWARFDie getParent() const
Get the parent of this DIE object.
LLVM_ABI std::optional< DWARFFormValue > find(dwarf::Attribute Attr) const
Extract the specified attribute from this DIE.
DWARFUnit * getDwarfUnit() const
LLVM_ABI bool isSubprogramDIE() const
Returns true if DIE represents a subprogram (not inlined).
LLVM_ABI std::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...
LLVM_ABI DWARFDie getFirstChild() const
Get the first child of this DIE object.
dwarf::Tag getTag() const
LLVM_ABI Expected< DWARFLocationExpressionsVector > getLocations(dwarf::Attribute Attr) const
LLVM_ABI iterator_range< attribute_iterator > attributes() const
Get an iterator range to all attributes in the current DIE only.
LLVM_ABI void dump(raw_ostream &OS, unsigned indent=0, DIDumpOptions DumpOpts=DIDumpOptions()) const
Dump the DIE and all of its attributes to the supplied stream.
This class represents an Operation in the Expression.
virtual StringRef getStrDWOSection() const
virtual StringRef getAbbrevDWOSection() const
virtual StringRef getAbbrevSection() const
virtual const DWARFSection & getStrOffsetsDWOSection() const
virtual void forEachInfoDWOSections(function_ref< void(const DWARFSection &)> F) const
virtual void forEachInfoSections(function_ref< void(const DWARFSection &)> F) const
virtual const DWARFSection & getRangesSection() const
virtual StringRef getTUIndexSection() const
virtual void forEachTypesSections(function_ref< void(const DWARFSection &)> F) const
virtual const DWARFSection & getStrOffsetsSection() const
virtual const DWARFSection & getLineSection() const
virtual const DWARFSection & getRnglistsSection() const
virtual StringRef getCUIndexSection() const
virtual StringRef getStrSection() const
virtual const object::ObjectFile * getFile() const
uint64_t getLength() const
uint64_t getOffset() const
Describe a collection of units.
std::optional< uint64_t > getDWOId()
DWARFDie getNonSkeletonUnitDIE(bool ExtractUnitDIEOnly=true, StringRef DWOAlternativeLocation={})
DWARFDie getUnitDIE(bool ExtractUnitDIEOnly=true)
DWARFContext & getContext() const
DWARFDie getDIEForOffset(uint64_t Offset)
Return the DIE object for a given offset Offset inside the unit's DIE vector.
die_iterator_range dies()
static bool isMatchingUnitTypeAndTag(uint8_t UnitType, dwarf::Tag Tag)
uint64_t getNextUnitOffset() const
uint64_t getOffset() const
LLVM_ABI bool handleAccelTables()
Verify the information in accelerator tables, if they exist.
LLVM_ABI bool verifyDebugStrOffsets(std::optional< dwarf::DwarfFormat > LegacyFormat, StringRef SectionName, const DWARFSection &Section, StringRef StrData)
LLVM_ABI bool handleDebugTUIndex()
Verify the information in the .debug_tu_index section.
LLVM_ABI bool handleDebugStrOffsets()
Verify the information in the .debug_str_offsets[.dwo].
LLVM_ABI bool handleDebugCUIndex()
Verify the information in the .debug_cu_index section.
LLVM_ABI DWARFVerifier(raw_ostream &S, DWARFContext &D, DIDumpOptions DumpOpts=DIDumpOptions::getForSingleDIE())
LLVM_ABI bool handleDebugInfo()
Verify the information in the .debug_info and .debug_types sections.
LLVM_ABI bool handleDebugLine()
Verify the information in the .debug_line section.
LLVM_ABI void summarize()
Emits any aggregate information collected, depending on the dump options.
LLVM_ABI bool handleDebugAbbrev()
Verify the information in any of the following sections, if available: .debug_abbrev,...
iterator find(const_arg_type_t< KeyT > Val)
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
void reserve(size_type NumEntries)
Grow the densemap so that it can contain at least NumEntries items before resizing again.
Implements a dense probed hash-table based set.
Base class for error info classes.
Lightweight error class with error context and mandatory checking.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
Class representing an expression and its matching format.
void ShowDetail(bool showDetail)
LLVM_ABI void EnumerateResults(std::function< void(StringRef, unsigned)> handleCounts)
size_t GetNumCategories() const
LLVM_ABI void EnumerateDetailedResultsFor(StringRef category, std::function< void(StringRef, unsigned)> handleCounts)
LLVM_ABI void Report(StringRef category, std::function< void()> detailCallback)
uint64_t GetNumErrors() const
Return the number of errors that have been reported.
Implements a dense probed hash-table based set with some number of buckets stored inline.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
std::pair< iterator, bool > try_emplace(StringRef Key, ArgsTy &&...Args)
Emplace a new element for the specified key into the map if the key isn't already in the map.
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
constexpr size_t size() const
size - Get the string size.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static LLVM_ABI raw_ostream & warning()
Convenience method for printing "warning: " to stderr.
static LLVM_ABI raw_ostream & error()
Convenience method for printing "error: " to stderr.
static LLVM_ABI raw_ostream & note()
Convenience method for printing "note: " to stderr.
std::pair< iterator, bool > insert(const ValueT &V)
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
An efficient, type-erasing, non-owning reference to a callable.
An Object is a JSON object, which maps strings to heterogenous JSON values.
std::pair< iterator, bool > try_emplace(const ObjectKey &K, Ts &&... Args)
A Value is an JSON value of unknown type.
A raw_ostream that writes to a file descriptor.
This class implements an extremely fast bulk output stream that can only output to a stream.
A raw_ostream that writes to an std::string.
LLVM_ABI StringRef AttributeString(unsigned Attribute)
LLVM_ABI StringRef FormEncodingString(unsigned Encoding)
LLVM_ABI StringRef UnitTypeString(unsigned)
LLVM_ABI StringRef TagString(unsigned Tag)
@ C
The default llvm calling convention, compatible with C.
LLVM_ABI void warn(Error E, StringRef Whence="")
std::optional< const char * > toString(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract a string value from it.
bool isUnitType(uint8_t UnitType)
UnitType
Constants for unit types in DWARF v5.
DwarfFormat
Constants that define the DWARF format as 32 or 64 bit.
std::optional< uint64_t > toSectionOffset(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an section offset.
StringRef toStringRef(const std::optional< DWARFFormValue > &V, StringRef Default={})
Take an optional DWARFFormValue and try to extract a string value from it.
uint8_t getDwarfOffsetByteSize(DwarfFormat Format)
The size of a reference determined by the DWARF 32/64-bit format.
@ OF_Text
The file should be opened in text mode on platforms like z/OS that make this distinction.
This is an optimization pass for GlobalISel generic memory operations.
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
bool operator<(int64_t V1, const APSInt &V2)
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
void handleAllErrors(Error E, HandlerTs &&... Handlers)
Behaves the same as handleErrors, except that by contract all errors must be handled by the given han...
Error handleErrors(Error E, HandlerTs &&... Hs)
Pass the ErrorInfo(s) contained in E to their respective handlers.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
std::vector< DWARFAddressRange > DWARFAddressRangesVector
DWARFAddressRangesVector - represents a set of absolute address ranges.
DWARFSectionKind
The enum of section identifiers to be used in internal interfaces.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
LLVM_ABI std::optional< StringRef > StripTemplateParameters(StringRef Name)
If Name is the name of a templated function that includes template parameters, returns a substring of...
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
@ Success
The lock was released successfully.
LLVM_ABI 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...
auto count(R &&Range, const E &Element)
Wrapper function around std::count to count the number of times an element Element occurs in the give...
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI std::optional< ObjCSelectorNames > getObjCNamesIfSelector(StringRef Name)
If Name is the AT_name of a DIE which refers to an Objective-C selector, returns an instance of ObjCS...
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
const char * toString(DWARFSectionKind Kind)
void array_pod_sort(IteratorTy Start, IteratorTy End)
array_pod_sort - This sorts an array with the specified start and end extent.
void parallelForEach(IterTy Begin, IterTy End, FuncTy Fn)
void consumeError(Error Err)
Consume a Error without doing anything.
Implement std::hash so that hash_code can be used in STL containers.
std::map< std::string, unsigned > DetailedCounts
Container for dump options that control which debug information will be dumped.
std::string JsonErrSummaryFile
Encapsulates a DWARF attribute value and all of the data required to describe the attribute value.
DWARFFormValue Value
The form and value for this attribute.
dwarf::Attribute Attr
The attribute enumeration of this attribute.
uint16_t getVersion() const
static LLVM_ABI void dumpTableHeader(raw_ostream &OS, unsigned Indent)
Abbreviation describing the encoding of Name Index entries.
uint32_t Code
< Abbreviation offset in the .debug_names section
Index attribute and its encoding.
SmallVector< Encoding > Op
Encoding for Op operands.
A class that keeps the address range information for a single DIE.
std::vector< DWARFAddressRange > Ranges
Sorted DWARFAddressRanges.
LLVM_ABI bool contains(const DieRangeInfo &RHS) const
Return true if ranges in this object contains all ranges within RHS.
std::set< DieRangeInfo >::const_iterator die_range_info_iterator
LLVM_ABI bool intersects(const DieRangeInfo &RHS) const
Return true if any range in this object intersects with any range in RHS.
LLVM_ABI std::optional< DWARFAddressRange > insert(const DWARFAddressRange &R)
Inserts the address range.