59 using namespace dwarf;
62 #define DEBUG_TYPE "dwarf" 70 :
DIContext(CK_DWARF), DWPName(
std::move(DWPName)), DObj(
std::move(DObj)) {}
76 auto *MachO =
dyn_cast<MachOObjectFile>(&Obj);
79 for (
auto LC : MachO->load_commands()) {
81 if (LC.C.cmd == MachO::LC_UUID) {
82 if (LC.C.cmdsize <
sizeof(UUID) +
sizeof(LC.C)) {
83 OS <<
"error: UUID load command is too short.\n";
87 memcpy(&UUID, LC.Ptr+
sizeof(LC.C),
sizeof(UUID));
89 Triple T = MachO->getArchTriple();
91 OS <<
' ' << MachO->getFileName() <<
'\n';
97 std::vector<Optional<StrOffsetsContributionDescriptor>>;
105 for (
const auto &
CU : CUs)
106 Contributions.push_back(
CU->getStringOffsetsTableContribution());
107 for (
const auto &TUS : TUSs)
108 for (
const auto &TU : TUS)
109 Contributions.push_back(TU->getStringOffsetsTableContribution());
114 llvm::sort(Contributions.begin(), Contributions.end(),
117 if (L && R)
return L->
Base < R->Base;
125 std::unique(Contributions.begin(), Contributions.end(),
129 return L->
Base == R->Base && L->
Size == R->Size;
132 Contributions.end());
133 return Contributions;
146 for (
auto &Contribution : Contributions) {
149 OS <<
"error: invalid contribution to string offsets table in section ." 150 << SectionName <<
".\n";
155 uint16_t
Version = Contribution->getVersion();
156 uint64_t ContributionHeader = Contribution->Base;
162 ContributionHeader -= Format ==
DWARF32 ? 8 : 16;
165 if (Offset > ContributionHeader) {
166 OS <<
"error: overlapping contributions to string offsets table in " 168 << SectionName <<
".\n";
172 if (Offset < ContributionHeader) {
173 OS <<
format(
"0x%8.8x: Gap, length = ", Offset);
174 OS << (ContributionHeader -
Offset) <<
"\n";
181 OS <<
"Contribution size = " << (Contribution->Size + (Version < 5 ? 0 : 4))
182 <<
", Format = " << (Format ==
DWARF32 ?
"DWARF32" :
"DWARF64")
183 <<
", Version = " << Version <<
"\n";
185 Offset = Contribution->Base;
186 unsigned EntrySize = Contribution->getDwarfOffsetByteSize();
187 while (Offset - Contribution->Base < Contribution->Size) {
188 OS <<
format(
"0x%8.8x: ", Offset);
190 uint64_t StringOffset =
196 OS <<
format(
"%8.8x ", StringOffset32);
197 const char *S = StrData.
getCStr(&StringOffset32);
199 OS <<
format(
"\"%s\"", S);
201 OS <<
format(
"%16.16" PRIx64
" ", StringOffset);
206 if (Offset < SectionSize) {
207 OS <<
format(
"0x%8.8x: Gap, length = ", Offset);
208 OS << (SectionSize -
Offset) <<
"\n";
223 unsigned MaxVersion) {
229 StringSection, CUs, TUSs, LittleEndian);
235 if (size & ((uint64_t)(
sizeof(
uint32_t) - 1))) {
236 OS <<
"error: size of ." << SectionName <<
" is not a multiple of " 238 size &= -(uint64_t)
sizeof(
uint32_t);
241 while (offset < size) {
242 OS <<
format(
"0x%8.8x: ", offset);
244 OS <<
format(
"%8.8x ", StringOffset);
245 const char *S = StrData.
getCStr(&StringOffset);
247 OS <<
format(
"\"%s\"", S);
259 static auto WarnCallback = [](
Error Warn) {
268 if (
Error Err = AddrTable.
extract(AddrData, &Offset, Version,
269 AddrSize, WarnCallback)) {
276 Offset = TableOffset + Length;
278 AddrTable.
dump(OS, DumpOpts);
291 if (
Error Err = Rnglists.
extract(rnglistData, &Offset)) {
293 uint64_t Length = Rnglists.
length();
298 Offset = TableOffset + Length;
300 Rnglists.
dump(OS, DumpOpts);
310 uint64_t DumpType = DumpOpts.
DumpType;
313 bool IsDWO = (Extension ==
".dwo") || (Extension ==
".dwp");
316 const auto *ObjFile =
DObj->getFile();
323 bool Explicit = DumpType !=
DIDT_All && !IsDWO;
324 bool ExplicitDWO = Explicit && IsDWO;
325 auto shouldDump = [&](
bool Explicit,
const char *
Name,
unsigned ID,
327 DumpOffset = DumpOffsets[
ID];
329 bool Should = (DumpType &
Mask) && (Explicit || !
Section.empty());
331 OS <<
"\n" << Name <<
" contents:\n";
336 if (shouldDump(Explicit,
".debug_abbrev", DIDT_ID_DebugAbbrev,
337 DObj->getAbbrevSection()))
339 if (shouldDump(ExplicitDWO,
".debug_abbrev.dwo", DIDT_ID_DebugAbbrev,
340 DObj->getAbbrevDWOSection()))
343 auto dumpDebugInfo = [&](
bool IsExplicit,
const char *
Name,
345 if (shouldDump(IsExplicit, Name, DIDT_ID_DebugInfo, Section.Data)) {
350 for (
const auto &
CU : CUs)
351 CU->dump(OS, DumpOpts);
354 dumpDebugInfo(Explicit,
".debug_info",
DObj->getInfoSection(),
356 dumpDebugInfo(ExplicitDWO,
".debug_info.dwo",
DObj->getInfoDWOSection(),
359 auto dumpDebugType = [&](
const char *
Name,
361 OS <<
'\n' << Name <<
" contents:\n";
362 DumpOffset = DumpOffsets[DIDT_ID_DebugTypes];
363 for (
const auto &TUS : TUSections)
364 for (
const auto &TU : TUS)
366 TU->getDIEForOffset(*DumpOffset)
369 TU->dump(OS, DumpOpts);
371 if ((DumpType & DIDT_DebugTypes)) {
378 if (shouldDump(Explicit,
".debug_loc", DIDT_ID_DebugLoc,
379 DObj->getLocSection().Data)) {
382 if (shouldDump(ExplicitDWO,
".debug_loc.dwo", DIDT_ID_DebugLoc,
383 DObj->getLocDWOSection().Data)) {
387 if (shouldDump(Explicit,
".debug_frame", DIDT_ID_DebugFrame,
388 DObj->getDebugFrameSection()))
391 if (shouldDump(Explicit,
".eh_frame", DIDT_ID_DebugFrame,
392 DObj->getEHFrameSection()))
395 if (DumpType & DIDT_DebugMacro) {
397 OS <<
"\n.debug_macinfo contents:\n";
402 if (shouldDump(Explicit,
".debug_aranges", DIDT_ID_DebugAranges,
403 DObj->getARangeSection())) {
407 while (
set.
extract(arangesData, &offset))
413 while (!Parser.
done()) {
414 if (DumpOffset && Parser.
getOffset() != *DumpOffset) {
423 LineTable.
dump(OS, DumpOpts);
428 if (shouldDump(Explicit,
".debug_line", DIDT_ID_DebugLine,
429 DObj->getLineSection().Data)) {
434 DumpLineSection(Parser, DumpOpts);
437 if (shouldDump(ExplicitDWO,
".debug_line.dwo", DIDT_ID_DebugLine,
438 DObj->getLineDWOSection().Data)) {
443 DumpLineSection(Parser, DumpOpts);
446 if (shouldDump(Explicit,
".debug_cu_index", DIDT_ID_DebugCUIndex,
447 DObj->getCUIndexSection())) {
451 if (shouldDump(Explicit,
".debug_tu_index", DIDT_ID_DebugTUIndex,
452 DObj->getTUIndexSection())) {
456 if (shouldDump(Explicit,
".debug_str", DIDT_ID_DebugStr,
457 DObj->getStringSection())) {
461 while (
const char *s = strData.getCStr(&offset)) {
462 OS <<
format(
"0x%8.8x: \"%s\"\n", strOffset, s);
466 if (shouldDump(ExplicitDWO,
".debug_str.dwo", DIDT_ID_DebugStr,
467 DObj->getStringDWOSection())) {
471 while (
const char *s = strDWOData.getCStr(&offset)) {
472 OS <<
format(
"0x%8.8x: \"%s\"\n", strDWOOffset, s);
473 strDWOOffset = offset;
476 if (shouldDump(Explicit,
".debug_line_str", DIDT_ID_DebugLineStr,
477 DObj->getLineStringSection())) {
481 while (
const char *s = strData.getCStr(&offset)) {
482 OS <<
format(
"0x%8.8x: \"", strOffset);
489 if (shouldDump(Explicit,
".debug_addr", DIDT_ID_DebugAddr,
490 DObj->getAddrSection().Data)) {
496 if (shouldDump(Explicit,
".debug_ranges", DIDT_ID_DebugRanges,
497 DObj->getRangeSection().Data)) {
503 while (rangesData.isValidOffset(offset)) {
512 if (shouldDump(Explicit,
".debug_rnglists", DIDT_ID_DebugRnglists,
513 DObj->getRnglistsSection().Data)) {
519 if (shouldDump(ExplicitDWO,
".debug_rnglists.dwo", DIDT_ID_DebugRnglists,
520 DObj->getRnglistsDWOSection().Data)) {
526 if (shouldDump(Explicit,
".debug_pubnames", DIDT_ID_DebugPubnames,
527 DObj->getPubNamesSection()))
531 if (shouldDump(Explicit,
".debug_pubtypes", DIDT_ID_DebugPubtypes,
532 DObj->getPubTypesSection()))
536 if (shouldDump(Explicit,
".debug_gnu_pubnames", DIDT_ID_DebugGnuPubnames,
537 DObj->getGnuPubNamesSection()))
542 if (shouldDump(Explicit,
".debug_gnu_pubtypes", DIDT_ID_DebugGnuPubtypes,
543 DObj->getGnuPubTypesSection()))
548 if (shouldDump(Explicit,
".debug_str_offsets", DIDT_ID_DebugStrOffsets,
549 DObj->getStringOffsetSection().Data))
551 OS,
"debug_str_offsets", *
DObj,
DObj->getStringOffsetSection(),
554 if (shouldDump(ExplicitDWO,
".debug_str_offsets.dwo", DIDT_ID_DebugStrOffsets,
555 DObj->getStringOffsetDWOSection().Data))
557 OS,
"debug_str_offsets.dwo", *
DObj,
DObj->getStringOffsetDWOSection(),
561 if (shouldDump(Explicit,
".gnu_index", DIDT_ID_GdbIndex,
562 DObj->getGdbIndexSection())) {
566 if (shouldDump(Explicit,
".apple_names", DIDT_ID_AppleNames,
567 DObj->getAppleNamesSection().Data))
570 if (shouldDump(Explicit,
".apple_types", DIDT_ID_AppleTypes,
571 DObj->getAppleTypesSection().Data))
574 if (shouldDump(Explicit,
".apple_namespaces", DIDT_ID_AppleNamespaces,
575 DObj->getAppleNamespacesSection().Data))
578 if (shouldDump(Explicit,
".apple_objc", DIDT_ID_AppleObjC,
579 DObj->getAppleObjCSection().Data))
581 if (shouldDump(Explicit,
".debug_names", DIDT_ID_DebugNames,
582 DObj->getDebugNamesSection().Data))
587 DWOCUs.parseDWO(*
this,
DObj->getInfoDWOSection(),
true);
590 if (
const auto *R = CUI.getFromHash(Hash))
591 return DWOCUs.getUnitForIndexEntry(*R);
601 if (!DWOCU->getDWOId()) {
603 toUnsigned(DWOCU->getUnitDIE().find(DW_AT_GNU_dwo_id)))
604 DWOCU->setDWOId(*DWOId);
609 if (DWOCU->getDWOId() == Hash)
617 if (
auto *
CU = CUs.getUnitForOffset(Offset))
618 return CU->getDIEForOffset(Offset);
627 if (DumpOpts.
DumpType & DIDT_DebugInfo)
629 if (DumpOpts.
DumpType & DIDT_DebugLine)
641 CUIndex = llvm::make_unique<DWARFUnitIndex>(
DW_SECT_INFO);
642 CUIndex->parse(CUIndexData);
653 TUIndex->parse(TUIndexData);
662 GdbIndex = llvm::make_unique<DWARFGdbIndex>();
663 GdbIndex->parse(GdbIndexData);
674 Abbrev->extract(abbrData);
680 return AbbrevDWO.get();
684 AbbrevDWO->extract(abbrData);
685 return AbbrevDWO.get();
711 LocDWO->parse(LocData);
718 return Aranges.get();
721 Aranges->generate(
this);
722 return Aranges.get();
727 return DebugFrame.get();
741 DebugFrame->parse(debugFrameData);
742 return DebugFrame.get();
747 return EHFrame.get();
750 DObj->getAddressSize());
752 DebugFrame->parse(debugFrameData);
753 return DebugFrame.get();
762 Macro->parse(MacinfoData);
766 template <
typename T>
769 bool IsLittleEndian) {
774 Cache.reset(
new T(AccelSection, StrData));
775 if (
Error E = Cache->extract())
797 DObj->getAppleNamespacesSection(),
810 if (!ExpectedLineTable) {
814 return *ExpectedLineTable;
842 return Line->getOrParseLineTable(lineData, stmtOffset, *
this, U,
843 RecoverableErrorCallback);
846 void DWARFContext::parseCompileUnits() {
847 CUs.parse(*
this,
DObj->getInfoSection());
850 void DWARFContext::parseTypeUnits() {
855 TUs.back().parse(*
this, S);
859 void DWARFContext::parseDWOCompileUnits() {
860 DWOCUs.parseDWO(*
this,
DObj->getInfoDWOSection());
863 void DWARFContext::parseDWOTypeUnits() {
867 DWOTUs.emplace_back();
868 DWOTUs.back().parseDWO(*
this, S);
874 return CUs.getUnitForOffset(Offset);
894 std::vector<DWARFDie> Worklist;
896 while (!Worklist.empty()) {
900 if (DIE.
getTag() == DW_TAG_lexical_block &&
906 for (
auto Child : DIE)
907 Worklist.push_back(Child);
916 std::string &FunctionName,
923 if (InlinedChain.
empty())
927 bool FoundResult =
false;
928 const char *
Name =
nullptr;
934 StartLine = DeclLineResult;
967 std::string FunctionName =
"<invalid>";
978 Lines.
push_back(std::make_pair(Address, Result));
985 std::vector<uint32_t> RowVector;
989 for (
uint32_t RowIndex : RowVector) {
1012 return InliningInfo;
1017 if (InlinedChain.
size() == 0) {
1028 return InliningInfo;
1031 uint32_t CallFile = 0, CallLine = 0, CallColumn = 0, CallDiscriminator = 0;
1032 for (
uint32_t i = 0, n = InlinedChain.
size(); i != n; i++) {
1033 DWARFDie &FunctionDIE = InlinedChain[i];
1055 Frame.
Line = CallLine;
1056 Frame.
Column = CallColumn;
1067 return InliningInfo;
1070 std::shared_ptr<DWARFContext>
1072 if (
auto S = DWP.lock()) {
1074 return std::shared_ptr<DWARFContext>(std::move(S), Ctxt);
1077 std::weak_ptr<DWOFile> *Entry = &DWOFiles[AbsolutePath];
1079 if (
auto S = Entry->lock()) {
1081 return std::shared_ptr<DWARFContext>(std::move(S), Ctxt);
1085 if (!CheckedForDWP) {
1088 this->DWPName.
empty()
1095 CheckedForDWP =
true;
1111 auto S = std::make_shared<DWOFile>();
1112 S->File = std::move(Obj.get());
1115 auto *Ctxt = S->Context.get();
1116 return std::shared_ptr<DWARFContext>(std::move(S), Ctxt);
1120 return make_error<StringError>(Reason +
toString(std::move(E)),
1134 const RelocationRef &Reloc,
1136 std::map<SymbolRef, SymInfo> &Cache) {
1141 std::map<SymbolRef, SymInfo>::iterator CacheIt = Cache.end();
1146 std::tie(CacheIt, New) = Cache.insert({*Sym, {0, 0}});
1148 return CacheIt->second;
1152 return createError(
"failed to compute symbol address: ",
1158 return createError(
"failed to get symbol section: ",
1159 SectOrErr.takeError());
1163 }
else if (
auto *MObj = dyn_cast<MachOObjectFile>(&Obj)) {
1164 RSec = MObj->getRelocationSection(Reloc.getRawDataRefImpl());
1165 Ret.
Address = RSec->getAddress();
1180 Ret.
Address += SectionLoadAddress - RSec->getAddress();
1182 if (CacheIt != Cache.end())
1183 CacheIt->second = Ret;
1189 const RelocationRef &Reloc) {
1190 const MachOObjectFile *MachObj =
dyn_cast<MachOObjectFile>(&Obj);
1195 auto RelocInfo = MachObj->getRelocation(Reloc.getRawDataRefImpl());
1196 return MachObj->isRelocationScattered(RelocInfo);
1209 class DWARFObjInMemory final :
public DWARFObject {
1210 bool IsLittleEndian;
1211 uint8_t AddressSize;
1214 std::vector<SectionName> SectionNames;
1217 std::map<object::SectionRef, unsigned>>;
1219 TypeSectionMap TypesSections;
1220 TypeSectionMap TypesDWOSections;
1222 DWARFSectionMap InfoSection;
1223 DWARFSectionMap LocSection;
1224 DWARFSectionMap LineSection;
1225 DWARFSectionMap RangeSection;
1226 DWARFSectionMap RnglistsSection;
1227 DWARFSectionMap StringOffsetSection;
1228 DWARFSectionMap InfoDWOSection;
1229 DWARFSectionMap LineDWOSection;
1230 DWARFSectionMap LocDWOSection;
1231 DWARFSectionMap StringOffsetDWOSection;
1232 DWARFSectionMap RangeDWOSection;
1233 DWARFSectionMap RnglistsDWOSection;
1234 DWARFSectionMap AddrSection;
1235 DWARFSectionMap AppleNamesSection;
1236 DWARFSectionMap AppleTypesSection;
1237 DWARFSectionMap AppleNamespacesSection;
1238 DWARFSectionMap AppleObjCSection;
1239 DWARFSectionMap DebugNamesSection;
1243 .Case(
"debug_info", &InfoSection)
1244 .
Case(
"debug_loc", &LocSection)
1245 .
Case(
"debug_line", &LineSection)
1246 .
Case(
"debug_str_offsets", &StringOffsetSection)
1247 .
Case(
"debug_ranges", &RangeSection)
1248 .
Case(
"debug_rnglists", &RnglistsSection)
1249 .
Case(
"debug_info.dwo", &InfoDWOSection)
1250 .
Case(
"debug_loc.dwo", &LocDWOSection)
1251 .
Case(
"debug_line.dwo", &LineDWOSection)
1252 .
Case(
"debug_names", &DebugNamesSection)
1253 .
Case(
"debug_rnglists.dwo", &RnglistsDWOSection)
1254 .
Case(
"debug_str_offsets.dwo", &StringOffsetDWOSection)
1255 .
Case(
"debug_addr", &AddrSection)
1256 .
Case(
"apple_names", &AppleNamesSection)
1257 .
Case(
"apple_types", &AppleTypesSection)
1258 .
Case(
"apple_namespaces", &AppleNamespacesSection)
1259 .
Case(
"apple_namespac", &AppleNamespacesSection)
1260 .
Case(
"apple_objc", &AppleObjCSection)
1283 std::deque<SmallString<0>> UncompressedSections;
1289 .Case(
"debug_abbrev", &AbbrevSection)
1290 .
Case(
"debug_aranges", &ARangeSection)
1291 .
Case(
"debug_frame", &DebugFrameSection)
1292 .
Case(
"eh_frame", &EHFrameSection)
1293 .
Case(
"debug_str", &StringSection)
1294 .
Case(
"debug_macinfo", &MacinfoSection)
1295 .
Case(
"debug_pubnames", &PubNamesSection)
1296 .
Case(
"debug_pubtypes", &PubTypesSection)
1297 .
Case(
"debug_gnu_pubnames", &GnuPubNamesSection)
1298 .
Case(
"debug_gnu_pubtypes", &GnuPubTypesSection)
1299 .
Case(
"debug_abbrev.dwo", &AbbrevDWOSection)
1300 .
Case(
"debug_str.dwo", &StringDWOSection)
1301 .
Case(
"debug_cu_index", &CUIndexSection)
1302 .
Case(
"debug_tu_index", &TUIndexSection)
1303 .
Case(
"gdb_index", &GdbIndexSection)
1304 .
Case(
"debug_line_str", &LineStringSection)
1311 Error maybeDecompress(
const object::SectionRef &Sec,
StringRef Name,
1313 if (!Decompressor::isCompressed(Sec))
1317 Decompressor::create(Name, Data, IsLittleEndian, AddressSize == 8);
1322 if (
auto Err = Decompressor->resizeAndDecompress(Out))
1325 UncompressedSections.push_back(std::move(Out));
1326 Data = UncompressedSections.
back();
1332 DWARFObjInMemory(
const StringMap<std::unique_ptr<MemoryBuffer>> &Sections,
1333 uint8_t AddrSize,
bool IsLittleEndian)
1334 : IsLittleEndian(IsLittleEndian) {
1335 for (
const auto &SecIt : Sections) {
1336 if (
StringRef *SectionData = mapSectionToMember(SecIt.first()))
1337 *SectionData = SecIt.second->getBuffer();
1350 ++SectionAmountMap[
Name];
1351 SectionNames.push_back({
Name,
true });
1369 if (
auto Err = maybeDecompress(
Section, Name, Data)) {
1371 "failed to decompress '" + Name +
"', ", std::move(Err)));
1386 if (
StringRef *SectionData = mapSectionToMember(Name)) {
1387 *SectionData =
Data;
1388 if (Name ==
"debug_ranges") {
1390 RangeDWOSection.Data =
Data;
1392 }
else if (Name ==
"debug_types") {
1396 }
else if (Name ==
"debug_types.dwo") {
1405 RelocatedSection->getName(RelSecName);
1418 if (!L && isa<MachOObjectFile>(&Obj))
1421 RelSecName = RelSecName.
substr(
1426 DWARFSectionMap *Sec = mapNameToDWARFSection(RelSecName);
1431 if (RelSecName ==
"debug_types")
1433 &
static_cast<DWARFSectionMap &
>(TypesSections[*RelocatedSection])
1435 else if (RelSecName ==
"debug_types.dwo")
1436 Map = &
static_cast<DWARFSectionMap &
>(
1437 TypesDWOSections[*RelocatedSection])
1447 std::map<SymbolRef, SymInfo> AddrCache;
1448 for (
const RelocationRef &Reloc :
Section.relocations()) {
1456 if (!SymInfoOrErr) {
1463 uint64_t Val = V.
visit(Reloc.getType(), Reloc, SymInfoOrErr->Address);
1466 Reloc.getTypeName(Type);
1468 createError(
"failed to compute relocation: " + Type +
", ",
1475 Map->
insert({Reloc.getOffset(), Rel});
1480 if (SectionAmountMap[S.Name] > 1)
1481 S.IsNameUnique =
false;
1485 uint64_t Pos)
const override {
1486 auto &Sec =
static_cast<const DWARFSectionMap &
>(S);
1488 if (AI == Sec.Relocs.end())
1496 return SectionNames;
1500 StringRef getAbbrevDWOSection()
const override {
return AbbrevDWOSection; }
1501 const DWARFSection &getLineDWOSection()
const override {
1502 return LineDWOSection;
1504 const DWARFSection &getLocDWOSection()
const override {
1505 return LocDWOSection;
1507 StringRef getStringDWOSection()
const override {
return StringDWOSection; }
1508 const DWARFSection &getStringOffsetDWOSection()
const override {
1509 return StringOffsetDWOSection;
1511 const DWARFSection &getRangeDWOSection()
const override {
1512 return RangeDWOSection;
1514 const DWARFSection &getRnglistsDWOSection()
const override {
1515 return RnglistsDWOSection;
1517 const DWARFSection &getAddrSection()
const override {
return AddrSection; }
1518 StringRef getCUIndexSection()
const override {
return CUIndexSection; }
1519 StringRef getGdbIndexSection()
const override {
return GdbIndexSection; }
1520 StringRef getTUIndexSection()
const override {
return TUIndexSection; }
1523 const DWARFSection &getStringOffsetSection()
const override {
1524 return StringOffsetSection;
1526 StringRef getLineStringSection()
const override {
return LineStringSection; }
1529 const DWARFSection &getInfoDWOSection()
const override {
1530 return InfoDWOSection;
1532 void forEachTypesDWOSections(
1534 for (
auto &
P : TypesDWOSections)
1538 StringRef getAbbrevSection()
const override {
return AbbrevSection; }
1539 const DWARFSection &getLocSection()
const override {
return LocSection; }
1540 StringRef getARangeSection()
const override {
return ARangeSection; }
1541 StringRef getDebugFrameSection()
const override {
return DebugFrameSection; }
1542 StringRef getEHFrameSection()
const override {
return EHFrameSection; }
1543 const DWARFSection &getLineSection()
const override {
return LineSection; }
1544 StringRef getStringSection()
const override {
return StringSection; }
1545 const DWARFSection &getRangeSection()
const override {
return RangeSection; }
1546 const DWARFSection &getRnglistsSection()
const override {
1547 return RnglistsSection;
1549 StringRef getMacinfoSection()
const override {
return MacinfoSection; }
1550 StringRef getPubNamesSection()
const override {
return PubNamesSection; }
1551 StringRef getPubTypesSection()
const override {
return PubTypesSection; }
1552 StringRef getGnuPubNamesSection()
const override {
1553 return GnuPubNamesSection;
1555 StringRef getGnuPubTypesSection()
const override {
1556 return GnuPubTypesSection;
1558 const DWARFSection &getAppleNamesSection()
const override {
1559 return AppleNamesSection;
1561 const DWARFSection &getAppleTypesSection()
const override {
1562 return AppleTypesSection;
1564 const DWARFSection &getAppleNamespacesSection()
const override {
1565 return AppleNamespacesSection;
1567 const DWARFSection &getAppleObjCSection()
const override {
1568 return AppleObjCSection;
1570 const DWARFSection &getDebugNamesSection()
const override {
1571 return DebugNamesSection;
1575 uint8_t getAddressSize()
const override {
return AddressSize; }
1576 const DWARFSection &getInfoSection()
const override {
return InfoSection; }
1577 void forEachTypesSections(
1579 for (
auto &
P : TypesSections)
1585 std::unique_ptr<DWARFContext>
1588 std::string DWPName) {
1589 auto DObj = llvm::make_unique<DWARFObjInMemory>(Obj, L, HandleError);
1590 return llvm::make_unique<DWARFContext>(std::move(
DObj), std::move(DWPName));
1593 std::unique_ptr<DWARFContext>
1597 llvm::make_unique<DWARFObjInMemory>(Sections, AddrSize,
isLittleEndian);
1598 return llvm::make_unique<DWARFContext>(std::move(
DObj),
"");
1608 std::string TargetLookupError;
1609 const Target *TheTarget =
1611 if (!TargetLookupError.empty())
1625 Addr =
CU->getAddressByteSize();
const DWARFUnitIndex & getTUIndex()
static Expected< OwningBinary< ObjectFile > > createObjectFile(StringRef ObjectPath)
void getInlinedChainForAddress(uint64_t Address, SmallVectorImpl< DWARFDie > &InlinedChain)
getInlinedChainForAddress - fetches inlined chain for a given address.
const DWARFDebugFrame * getEHFrame()
Get a pointer to the parsed eh frame information object.
void push_back(const T &Elt)
const DWARFDebugFrame * getDebugFrame()
Get a pointer to the parsed frame information object.
static void warn(Error Err)
Helper function for DWARFDebugLine parse functions, to report issues identified during parsing...
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
uint8_t[16] uuid_t
Output a formatted UUID with dash separators.
A parsed .debug_frame or .eh_frame section.
Compute iterated dominance frontiers using a linear time algorithm.
static ContributionCollection collectContributionData(DWARFContext::cu_iterator_range CUs, DWARFContext::tu_section_iterator_range TUSs)
const DWARFDebugLocDWO * getDebugLocDWO()
Get a pointer to the parsed DebugLoc object.
Represents structure for holding and parsing .debug_pub* tables.
const DWARFDebugLoc * getDebugLoc()
Get a pointer to the parsed DebugLoc object.
virtual bool getLoadedSectionContents(const object::SectionRef &Sec, StringRef &Data) const
If conveniently available, return the content of the given Section.
void dump(raw_ostream &OS, const MCRegisterInfo *RegInfo, Optional< uint64_t > Offset) const
Print the location lists found within the debug_loc section.
ErrorPolicy
Used as a return value for a error callback passed to DWARF context.
bool addressRangeContainsAddress(const uint64_t Address) const
void setVendor(VendorType Kind)
setVendor - Set the vendor (second) component of the triple to a known type.
StringRef getFileName() const
const AppleAcceleratorTable & getAppleNamespaces()
Get a reference to the parsed accelerator table object.
void dump(raw_ostream &OS) const
DWARFDie getDIEForOffset(uint32_t Offset)
Get a DIE given an exact offset.
DWARFGdbIndex & getGdbIndex()
std::shared_ptr< DWARFContext > getDWOContext(StringRef AbsolutePath)
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.
uint32_t findAddress(uint64_t Address) const
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.
An efficient, type-erasing, non-owning reference to a callable.
uint8_t getCUAddrSize()
Get address size from CUs.
uint32_t Line
An unsigned integer indicating a source line number.
DIEsForAddress getDIEsForAddress(uint64_t Address)
Get the compilation unit, the function DIE and lexical block DIE for the given address where applicab...
static void dumpStringOffsetsSection(raw_ostream &OS, StringRef SectionName, const DWARFObject &Obj, const DWARFSection &StringOffsetsSection, StringRef StringSection, DWARFContext::cu_iterator_range CUs, DWARFContext::tu_section_iterator_range TUSs, bool LittleEndian, unsigned MaxVersion)
This class is the base class for all object file types.
virtual std::string message() const
Return the error message as a string.
static raw_ostream & warning()
Convenience method for printing "warning: " to stderr.
This class implements a map that also provides access to all stored values in a deterministic order...
const DWARFDebugLine::LineTable * getLineTableForUnit(DWARFUnit *U)
Get a pointer to a parsed line table corresponding to a compile unit.
unsigned getNumTypeUnits()
Get the number of compile units in this context.
void setOS(OSType Kind)
setOS - Set the operating system (third) component of the triple to a known type. ...
void addFrame(const DILineInfo &Frame)
unsigned getMaxVersion() const
const DWARFDebugAbbrev * getDebugAbbrevDWO()
Get a pointer to the parsed dwo abbreviations object.
DINameKind
A DINameKind is passed to name search methods to specify a preference regarding the type of name reso...
Error takeError()
Take ownership of the stored error.
static const Target * lookupTarget(const std::string &Triple, std::string &Error)
lookupTarget - Lookup a target based on a target triple.
Base class for error info classes.
std::unique_ptr< const DWARFObject > DObj
bool handleDebugInfo()
Verify the information in the .debug_info section.
raw_ostream & write_uuid(const uuid_t UUID)
A format-neutral container for source line information.
DWARFDie getSubroutineForAddress(uint64_t Address)
Returns subprogram DIE with address range encompassing the provided address.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
std::string toString(Error E)
Write all error messages (if any) in E to a string.
DWARFCompileUnit * getCompileUnitForOffset(uint32_t Offset)
Return the compile unit that includes an offset (relative to .debug_info).
static bool getFunctionNameAndStartLineForAddress(DWARFCompileUnit *CU, uint64_t Address, FunctionNameKind Kind, std::string &FunctionName, uint32_t &StartLine)
static T & getAccelTable(std::unique_ptr< T > &Cache, const DWARFObject &Obj, const DWARFSection &Section, StringRef StringSection, bool IsLittleEndian)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
DwarfFormat
Constants that define the DWARF format as 32 or 64 bit.
const char * getCompilationDir()
A class representing an address table as specified in DWARF v5.
unsigned getNumCompileUnits()
Get the number of compile units in this context.
const DWARFSection & getLineSection() const
uint64_t Address
The program-counter value corresponding to a machine instruction generated by the compiler...
void getCallerFrame(uint32_t &CallFile, uint32_t &CallLine, uint32_t &CallColumn, uint32_t &CallDiscriminator) const
Retrieves values of DW_AT_call_file, DW_AT_call_line and DW_AT_call_column from DIE (or zeroes if the...
virtual uint64_t getSectionLoadAddress(const object::SectionRef &Sec) const
Obtain the Load Address of a section by SectionRef.
Tagged union holding either a T or a Error.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE R Default(T Value)
uint64_t Size
The contribution size not including the header.
const MCRegisterInfo * getRegisterInfo() const
unsigned getNumDWOTypeUnits()
Get the number of compile units in the DWO context.
uint8_t getAddressByteSize() const
content_iterator< SectionRef > section_iterator
bool verify(raw_ostream &OS, DIDumpOptions DumpOpts={}) override
const T & getValue() const LLVM_LVALUE_FUNCTION
const DWARFDebugAranges * getDebugAranges()
Get a pointer to the parsed DebugAranges object.
static void dumpDWARFv5StringOffsetsSection(raw_ostream &OS, StringRef SectionName, const DWARFObject &Obj, const DWARFSection &StringOffsetsSection, StringRef StringSection, DWARFContext::cu_iterator_range CUs, DWARFContext::tu_section_iterator_range TUSs, bool LittleEndian)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
const DWARFDebugAbbrev * getDebugAbbrev()
Get a pointer to the parsed DebugAbbrev object.
section_iterator_range sections() const
DWARFCompileUnit * getCompileUnitAtIndex(unsigned index)
Get the compile unit at the specified index for this compile unit.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
const std::string & str() const
uint64_t getDeclLine() const
Returns the declaration line (start line) for a DIE, assuming it specifies a subprogram.
Expected< section_iterator > getSection() const
Get section this symbol is defined in reference to.
void dump(raw_ostream &OS, const MCRegisterInfo *MRI, Optional< uint64_t > Offset) const
Dump the section data into the given stream.
Error loadRegisterInfo(const object::ObjectFile &Obj)
Loads register info for the architecture of the provided object file.
Container for dump options that control which debug information will be dumped.
virtual StringRef mapDebugSectionName(StringRef Name) const
Maps a debug section name to a standard DWARF section name.
static Expected< StringRef > getFileName(const DebugStringTableSubsectionRef &Strings, const DebugChecksumsSubsectionRef &Checksums, uint32_t FileID)
Optional< uint64_t > toSectionOffset(const Optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an section offset.
A switch()-like statement whose cases are string literals.
Utility class that carries the DWARF compile/type unit and the debug info entry in an object...
This implements the Apple accelerator table format, a precursor of the DWARF 5 accelerator table form...
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
virtual uint8_t getBytesInAddress() const =0
The number of bytes used to represent an address in this object file format.
Controls which fields of DILineInfo container should be filled with data.
DIDumpOptions noImplicitRecursion() const
Return the options with RecurseDepth set to 0 unless explicitly required.
void dump(raw_ostream &OS, DIDumpOptions DumpOpts={}) const
static void dumpAddrSection(raw_ostream &OS, DWARFDataExtractor &AddrData, DIDumpOptions DumpOpts, uint16_t Version, uint8_t AddrSize)
uint16_t File
An unsigned integer indicating the identity of the source file corresponding to a machine instruction...
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
const DWARFDebugMacro * getDebugMacro()
Get a pointer to the parsed DebugMacro object.
A format-neutral container for inlined code description.
A structured debug information entry.
LLVM_NODISCARD size_t find_first_not_of(char C, size_t From=0) const
Find the first character in the string that is not C or npos if not found.
void dump(raw_ostream &OS) const
bool handleDebugAbbrev()
Verify the information in any of the following sections, if available: .debug_abbrev, debug_abbrev.dwo.
void skip(function_ref< void(Error)> ErrorCallback=warn)
Skip the current line table and go to the following line table (if present) immediately.
static Error createError(const Twine &Reason, llvm::Error E)
DILineInfo getLineInfoForAddress(uint64_t Address, DILineInfoSpecifier Specifier=DILineInfoSpecifier()) override
static ErrorPolicy defaultErrorHandler(Error E)
Function used to handle default error reporting policy.
MCRegisterInfo * createMCRegInfo(StringRef TT) const
createMCRegInfo - Create a MCRegisterInfo implementation.
Error extract(DWARFDataExtractor Data, uint32_t *OffsetPtr, uint16_t Version, uint8_t AddrSize, std::function< void(Error)> WarnCallback)
Extract an entire table, including all addresses.
void dump(raw_ostream &OS)
virtual basic_symbol_iterator symbol_end() const =0
void dump(raw_ostream &OS, const MCRegisterInfo *RegInfo, Optional< uint64_t > Offset) const
static void dumpUUID(raw_ostream &OS, const ObjectFile &Obj)
Dump the UUID load command.
static bool isRelocScattered(const object::ObjectFile &Obj, const RelocationRef &Reloc)
void dump(raw_ostream &OS) const
Print the macro list found within the debug_macinfo section.
StringRef toStringRef(bool B)
Construct a string ref from a boolean.
Expected< uint64_t > getAddress() const
Returns the symbol virtual address (i.e.
void consumeError(Error Err)
Consume a Error without doing anything.
LLVM_NODISCARD char back() const
back - Get the last character in the string.
auto find(R &&Range, const T &Val) -> decltype(adl_begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
void dump(raw_ostream &OS, DIDumpOptions DumpOptions) const
bool isLittleEndian() const
const AppleAcceleratorTable & getAppleObjC()
Get a reference to the parsed accelerator table object.
Triple - Helper class for working with autoconf configuration names.
Standard .debug_line state machine structure.
const AppleAcceleratorTable & getAppleTypes()
Get a reference to the parsed accelerator table object.
static std::unique_ptr< DWARFContext > create(const object::ObjectFile &Obj, const LoadedObjectInfo *L=nullptr, function_ref< ErrorPolicy(Error)> HandleError=defaultErrorHandler, std::string DWPName="")
void sort(IteratorTy Start, IteratorTy End)
bool lookupAddressRange(uint64_t Address, uint64_t Size, std::vector< uint32_t > &Result) const
.debug_names section consists of one or more units.
DWARFCompileUnit * getDWOCompileUnitForHash(uint64_t Hash)
void dump(raw_ostream &OS, DIDumpOptions DumpOpts={}) const
void handleAllErrors(Error E, HandlerTs &&... Handlers)
Behaves the same as handleErrors, except that by contract all errors must be handled by the given han...
uint16_t Column
An unsigned integer indicating a column number within a source line.
DWARFDie getUnitDIE(bool ExtractUnitDIEOnly=true)
StringRef getArchName() const
getArchName - Get the architecture (first) component of the triple.
raw_ostream & write_escaped(StringRef Str, bool UseHexEscapes=false)
Output Str, turning '\', '', ' ', '"', and anything that doesn't satisfy llvm::isPrint into an escape...
static ErrorSuccess success()
Create a success value.
uint32_t getLength() const
Returns the length of this table, including the length field, or 0 if the length has not been determi...
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
bool getFileLineInfoForAddress(uint64_t Address, const char *CompDir, DILineInfoSpecifier::FileLineInfoKind Kind, DILineInfo &Result) const
Fills the Result argument with the file and line information corresponding to Address.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
DIInliningInfo getInliningInfoForAddress(uint64_t Address, DILineInfoSpecifier Specifier=DILineInfoSpecifier()) override
DWARFCompileUnit * CompileUnit
void dump(raw_ostream &OS) const override
static Expected< SymInfo > getSymbolInfo(const object::ObjectFile &Obj, const RelocationRef &Reloc, const LoadedObjectInfo *L, std::map< SymbolRef, SymInfo > &Cache)
Returns the address of symbol relocation used against and a section index.
virtual Triple::ArchType getArch() const =0
DWARFContext This data structure is the top level entity that deals with dwarf debug information pars...
tu_section_iterator_range dwo_type_unit_sections()
Get type units in the DWO context.
A range adaptor for a pair of iterators.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
This file contains constants used for implementing Dwarf debug support.
Target - Wrapper for Target specific information.
An inferface for inquiring the load address of a loaded object file to be used by the DIContext imple...
LLVM_ATTRIBUTE_ALWAYS_INLINE StringSwitch & Case(StringLiteral S, T Value)
void dump(raw_ostream &OS) const
static void dumpRnglistsSection(raw_ostream &OS, DWARFDataExtractor &rnglistData, DIDumpOptions DumpOpts)
DILineInfoTable getLineInfoForAddressRange(uint64_t Address, uint64_t Size, DILineInfoSpecifier Specifier=DILineInfoSpecifier()) override
RelocAddrEntry contains relocated value and section index.
const DWARFDebugNames & getDebugNames()
Get a reference to the parsed accelerator table object.
A class that verifies DWARF debug information given a DWARF Context.
virtual section_iterator section_end() const =0
dwarf::Tag getTag() const
LLVM_NODISCARD bool empty() const
const AppleAcceleratorTable & getAppleNames()
Get a reference to the parsed accelerator table object.
Wraps the returned DIEs for a given address.
bool handleAccelTables()
Verify the information in accelerator tables, if they exist.
cu_iterator_range compile_units()
Get compile units in this context.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
void dump(raw_ostream &OS, DIDumpOptions DumpOpts, std::array< Optional< uint64_t >, DIDT_ID_Count > DumpOffsets)
Dump a textual representation to OS.
DWARFContext(std::unique_ptr< const DWARFObject > DObj, std::string DWPName="")
bool isLittleEndian() const
const DWARFUnitIndex & getCUIndex()
void dump(raw_ostream &OS) const override
SymInfo contains information about symbol: it's address and section index which is -1LL for absolute ...
DINameKind FunctionNameKind
Error extract(DWARFDataExtractor Data, uint32_t *OffsetPtr)
Extract an entire table, including all list entries.
cu_iterator_range dwo_compile_units()
Get compile units in the DWO context.
LineTable parseNext(function_ref< void(Error)> RecoverableErrorCallback=warn, function_ref< void(Error)> UnrecoverableErrorCallback=warn, raw_ostream *OS=nullptr)
Get the next line table from the section.
bool getFileNameByIndex(uint64_t FileIndex, const char *CompDir, DILineInfoSpecifier::FileLineInfoKind Kind, std::string &Result) const
Extracts filename by its index in filename table in prologue.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
Lightweight error class with error context and mandatory checking.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
This class implements an extremely fast bulk output stream that can only output to a stream...
print Print MemDeps of function
StringRef - Represent a constant reference to a string, i.e.
bool hasValidLength() const
Verify that the given length is valid for this table.
tu_section_iterator_range type_unit_sections()
Get type units in this context.
Helper to allow for parsing of an entire .debug_line section in sequence.
bool done() const
Indicates if the parser has parsed as much as possible.
uint64_t visit(uint32_t Rel, RelocationRef R, uint64_t Value=0)
uint32_t getLineTableOffset() const
const char * getSubroutineName(DINameKind Kind) const
If a DIE represents a subprogram (or inlined subroutine), returns its mangled name (or short name...
void setArch(ArchType Kind)
setArch - Set the architecture (first) component of the triple to a known type.
Optional< uint64_t > toUnsigned(const Optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an unsigned constant.
uint32_t getOffset() const
Get the offset the parser has reached.
Error extract(const DWARFDataExtractor &data, uint32_t *offset_ptr)
This is a value type class that represents a single section in the list of sections in the object fil...
std::vector< Optional< StrOffsetsContributionDescriptor > > ContributionCollection
Base class for object file relocation visitors.
StringRef extension(StringRef path, Style style=Style::native)
Get extension.
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...