65using namespace object;
67#define DEBUG_TYPE "dwarf"
78 const auto &DObj =
C.getDWARFObj();
79 if (DObj.getCUIndexSection().empty())
85 if (!(
C.getParseCUTUIndexManually() ||
86 S.
Data.
size() >= std::numeric_limits<uint32_t>::max()))
90 while (Data.isValidOffset(
Offset)) {
91 DWARFUnitHeader Header;
92 if (Error ExtractionErr = Header.extract(
93 C, Data, &Offset, DWARFSectionKind::DW_SECT_INFO)) {
94 C.getWarningHandler()(
95 createError(
"Failed to parse CU header in DWP file: " +
96 toString(std::move(ExtractionErr))));
101 auto Iter = Map.insert({TruncOffset,
102 {Header.getOffset(), Header.getNextUnitOffset() -
103 Header.getOffset()}});
105 logAllUnhandledErrors(
106 createError(
"Collision occured between for truncated offset 0x" +
107 Twine::utohexstr(TruncOffset)),
113 Offset = Header.getNextUnitOffset();
126 if (Iter ==
Map.end()) {
133 CUOff.
setOffset(Iter->second.getOffset());
134 if (CUOff.
getOffset() != Iter->second.getOffset())
136 "match calculated length at offset 0x" +
145 const auto &DObj =
C.getDWARFObj();
146 DObj.forEachInfoDWOSections([&](
const DWARFSection &S) {
147 if (!(
C.getParseCUTUIndexManually() ||
148 S.
Data.
size() >= std::numeric_limits<uint32_t>::max()))
152 while (Data.isValidOffset(
Offset)) {
153 DWARFUnitHeader Header;
154 if (Error ExtractionErr = Header.extract(
155 C, Data, &Offset, DWARFSectionKind::DW_SECT_INFO)) {
156 C.getWarningHandler()(
157 createError(
"Failed to parse CU header in DWP file: " +
158 toString(std::move(ExtractionErr))));
161 bool CU = Header.getUnitType() == DW_UT_split_compile;
162 uint64_t Sig =
CU ? *Header.getDWOId() : Header.getTypeHash();
163 Map[Sig] = Header.getOffset();
164 Offset = Header.getNextUnitOffset();
173 auto Iter =
Map.find(
E.getSignature());
174 if (Iter ==
Map.end()) {
176 createError(
"Could not find unit with signature 0x" +
186 if (
Index.getVersion() < 5)
195 bool IsLittleEndian) {
200 Cache = std::make_unique<T>(AccelSection, StrData);
201 if (
Error E = Cache->extract())
207std::unique_ptr<DWARFDebugMacro>
209 auto Macro = std::make_unique<DWARFDebugMacro>();
224 switch (SectionType) {
227 ParseAndDump(
Data,
false);
232 ParseAndDump(
Data,
false);
238 ParseAndDump(
Data,
true);
243 ParseAndDump(
Data,
true);
253 std::optional<DenseMap<uint64_t, DWARFTypeUnit *>> NormalTypeUnits;
254 std::unique_ptr<DWARFUnitIndex> CUIndex;
255 std::unique_ptr<DWARFGdbIndex> GdbIndex;
256 std::unique_ptr<DWARFUnitIndex> TUIndex;
257 std::unique_ptr<DWARFDebugAbbrev> Abbrev;
258 std::unique_ptr<DWARFDebugLoc> Loc;
259 std::unique_ptr<DWARFDebugAranges> Aranges;
260 std::unique_ptr<DWARFDebugLine> Line;
261 std::unique_ptr<DWARFDebugFrame> DebugFrame;
262 std::unique_ptr<DWARFDebugFrame> EHFrame;
263 std::unique_ptr<DWARFDebugMacro>
Macro;
264 std::unique_ptr<DWARFDebugMacro> Macinfo;
265 std::unique_ptr<DWARFDebugNames> Names;
266 std::unique_ptr<AppleAcceleratorTable> AppleNames;
267 std::unique_ptr<AppleAcceleratorTable> AppleTypes;
268 std::unique_ptr<AppleAcceleratorTable> AppleNamespaces;
269 std::unique_ptr<AppleAcceleratorTable> AppleObjC;
271 std::optional<DenseMap<uint64_t, DWARFTypeUnit *>> DWOTypeUnits;
272 std::unique_ptr<DWARFDebugAbbrev> AbbrevDWO;
273 std::unique_ptr<DWARFDebugMacro> MacinfoDWO;
274 std::unique_ptr<DWARFDebugMacro> MacroDWO;
277 std::unique_ptr<DWARFContext>
Context;
280 std::weak_ptr<DWOFile> DWP;
281 bool CheckedForDWP =
false;
290 if (NormalUnits.
empty()) {
304 if (DWOUnits.
empty()) {
320 return AbbrevDWO.get();
323 AbbrevDWO = std::make_unique<DWARFDebugAbbrev>(abbrData);
324 return AbbrevDWO.get();
332 D.isLittleEndian(), 0);
333 CUIndex = std::make_unique<DWARFUnitIndex>(DW_SECT_INFO);
334 if (CUIndex->parse(Data))
343 D.isLittleEndian(), 0);
345 bool isParseSuccessful = TUIndex->parse(Data);
348 if (isParseSuccessful && TUIndex->getVersion() != 2)
357 DataExtractor Data(
D.getDWARFObj().getGdbIndexSection(),
true , 0);
358 GdbIndex = std::make_unique<DWARFGdbIndex>();
359 GdbIndex->parse(Data);
368 D.isLittleEndian(), 0);
369 Abbrev = std::make_unique<DWARFDebugAbbrev>(Data);
380 D.getNumCompileUnits()
382 D.getUnitAtIndex(0)->getAddressByteSize())
384 Loc = std::make_unique<DWARFDebugLoc>(std::move(Data));
390 return Aranges.get();
392 Aranges = std::make_unique<DWARFDebugAranges>();
393 Aranges->generate(&
D);
394 return Aranges.get();
400 Line = std::make_unique<DWARFDebugLine>();
402 auto UnitDIE = U->getUnitDIE();
416 if (stmtOffset >= U->getLineSection().Data.size())
421 U->isLittleEndian(), U->getAddressByteSize());
422 return Line->getOrParseLineTable(Data, stmtOffset, U->getContext(), U,
423 RecoverableErrorHandler);
431 auto UnitDIE = U->getUnitDIE();
440 Line->clearLineTable(stmtOffset);
445 return DebugFrame.get();
461 std::make_unique<DWARFDebugFrame>(
D.getArch(),
false,
467 return DebugFrame.get();
472 return EHFrame.get();
479 std::make_unique<DWARFDebugFrame>(
D.getArch(),
true,
484 return EHFrame.get();
489 Macinfo = parseMacroOrMacinfo(MacinfoSection);
490 return Macinfo.get();
494 MacinfoDWO = parseMacroOrMacinfo(MacinfoDwoSection);
495 return MacinfoDWO.get();
499 Macro = parseMacroOrMacinfo(MacroSection);
504 MacroDWO = parseMacroOrMacinfo(MacroDwoSection);
505 return MacroDWO.get();
537 std::shared_ptr<DWARFContext>
539 if (
auto S = DWP.lock()) {
541 return std::shared_ptr<DWARFContext>(std::move(S), Ctxt);
544 std::weak_ptr<DWOFile> *Entry = &DWOFiles[AbsolutePath];
546 if (
auto S = Entry->lock()) {
548 return std::shared_ptr<DWARFContext>(std::move(S), Ctxt);
554 if (!CheckedForDWP) {
557 this->DWPName.
empty()
558 ? (DObj.
getFileName() +
".dwp").toStringRef(DWPName)
564 CheckedForDWP =
true;
580 auto S = std::make_shared<DWOFile>();
581 S->File = std::move(Obj.
get());
584 bool ThreadSafe = isThreadSafe();
586 *S->File.getBinary(), DWARFContext::ProcessDebugRelocations::Ignore,
590 auto *Ctxt = S->Context.get();
591 return std::shared_ptr<DWARFContext>(std::move(S), Ctxt);
597 if (!NormalTypeUnits) {
598 NormalTypeUnits.emplace();
599 for (
const auto &U :
D.normal_units()) {
601 (*NormalTypeUnits)[TU->getTypeHash()] = TU;
604 return *NormalTypeUnits;
609 DWOTypeUnits.emplace();
610 for (
const auto &U :
D.dwo_units()) {
612 (*DWOTypeUnits)[TU->getTypeHash()] = TU;
615 return *DWOTypeUnits;
621 return getDWOTypeUnitMap();
623 return getNormalTypeUnitMap();
630 std::recursive_mutex
Mutex;
637 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
641 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
648 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
652 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
657 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
661 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
665 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
669 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
673 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
678 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
682 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
686 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
690 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
694 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
698 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
702 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
706 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
710 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
714 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
718 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
722 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
726 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
729 std::shared_ptr<DWARFContext>
731 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
739 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
748 std::function<
void(
Error)> RecoverableErrorHandler,
749 std::function<
void(
Error)> WarningHandler,
752 RecoverableErrorHandler(RecoverableErrorHandler),
753 WarningHandler(WarningHandler), DObj(
std::
move(DObj)) {
755 State = std::make_unique<ThreadSafeState>(*
this, DWPName);
757 State = std::make_unique<ThreadUnsafeDWARFContextState>(*
this, DWPName);
764 auto *MachO = dyn_cast<MachOObjectFile>(&Obj);
767 for (
auto LC : MachO->load_commands()) {
769 if (LC.C.cmd == MachO::LC_UUID) {
770 if (LC.C.cmdsize <
sizeof(
UUID) +
sizeof(LC.C)) {
771 OS <<
"error: UUID load command is too short.\n";
775 memcpy(&
UUID, LC.Ptr+
sizeof(LC.C),
sizeof(
UUID));
777 Triple T = MachO->getArchTriple();
778 OS <<
" (" <<
T.getArchName() <<
')';
779 OS <<
' ' << MachO->getFileName() <<
'\n';
785 std::vector<std::optional<StrOffsetsContributionDescriptor>>;
792 for (
const auto &U : Units)
793 if (
const auto &
C = U->getStringOffsetsTableContribution())
794 Contributions.push_back(
C);
799 [](
const std::optional<StrOffsetsContributionDescriptor> &L,
800 const std::optional<StrOffsetsContributionDescriptor> &R) {
802 return L->Base < R->Base;
803 return R.has_value();
810 std::unique(Contributions.begin(), Contributions.end(),
811 [](
const std::optional<StrOffsetsContributionDescriptor> &L,
812 const std::optional<StrOffsetsContributionDescriptor> &R) {
814 return L->Base == R->Base && L->Size == R->Size;
817 Contributions.end());
818 return Contributions;
841 for (
auto &Contribution : Contributions) {
844 OS <<
"error: invalid contribution to string offsets table in section ."
851 uint16_t Version = Contribution->getVersion();
852 uint64_t ContributionHeader = Contribution->Base;
861 if (
Offset > ContributionHeader) {
864 "overlapping contributions to string offsets table in section .%s.",
868 if (
Offset < ContributionHeader) {
870 OS << (ContributionHeader -
Offset) <<
"\n";
872 OS <<
format(
"0x%8.8" PRIx64
": ", ContributionHeader);
877 OS <<
"Contribution size = " << (Contribution->Size + (Version < 5 ? 0 : 4))
879 <<
", Version = " << Version <<
"\n";
881 Offset = Contribution->Base;
882 unsigned EntrySize = Contribution->getDwarfOffsetByteSize();
883 while (
Offset - Contribution->Base < Contribution->Size) {
887 OS <<
format(
"%0*" PRIx64
" ", OffsetDumpWidth, StringOffset);
888 const char *S = StrData.
getCStr(&StringOffset);
895 if (
Offset < SectionSize) {
897 OS << (SectionSize -
Offset) <<
"\n";
915 Offset = TableOffset + *TableLength;
920 AddrTable.
dump(
OS, DumpOpts);
943 Rnglists.
dump(rnglistData,
OS, LookupPooledAddress, DumpOpts);
951 std::optional<uint64_t> DumpOffset) {
961 Header.dump(
Data,
OS, DumpOpts);
963 uint64_t EndOffset = Header.length() + Header.getHeaderOffset();
964 Data.setAddressSize(Header.getAddrSize());
967 if (DumpOffset >=
Offset && DumpOffset < EndOffset) {
970 nullptr, DumpOpts, 0);
990 std::array<std::optional<uint64_t>,
DIDT_ID_Count> DumpOffsets) {
994 bool IsDWO = (Extension ==
".dwo") || (Extension ==
".dwp");
997 const auto *ObjFile = DObj->getFile();
1004 bool Explicit = DumpType !=
DIDT_All && !IsDWO;
1005 bool ExplicitDWO = Explicit && IsDWO;
1006 auto shouldDump = [&](
bool Explicit,
const char *
Name,
unsigned ID,
1007 StringRef Section) -> std::optional<uint64_t> * {
1008 unsigned Mask = 1U <<
ID;
1009 bool Should = (DumpType & Mask) && (Explicit || !Section.empty());
1012 OS <<
"\n" <<
Name <<
" contents:\n";
1013 return &DumpOffsets[
ID];
1017 if (shouldDump(Explicit,
".debug_abbrev", DIDT_ID_DebugAbbrev,
1018 DObj->getAbbrevSection()))
1020 if (shouldDump(ExplicitDWO,
".debug_abbrev.dwo", DIDT_ID_DebugAbbrev,
1021 DObj->getAbbrevDWOSection()))
1025 OS <<
'\n' <<
Name <<
" contents:\n";
1026 if (
auto DumpOffset = DumpOffsets[DIDT_ID_DebugInfo])
1027 for (
const auto &U : Units)
1028 U->getDIEForOffset(*DumpOffset)
1031 for (
const auto &U : Units)
1032 U->dump(
OS, DumpOpts);
1034 if ((DumpType & DIDT_DebugInfo)) {
1042 OS <<
'\n' <<
Name <<
" contents:\n";
1043 for (
const auto &U : Units)
1044 if (
auto DumpOffset = DumpOffsets[DIDT_ID_DebugTypes])
1045 U->getDIEForOffset(*DumpOffset)
1048 U->dump(
OS, DumpOpts);
1050 if ((DumpType & DIDT_DebugTypes)) {
1061 if (
const auto *Off = shouldDump(Explicit,
".debug_loc", DIDT_ID_DebugLoc,
1062 DObj->getLocSection().Data)) {
1065 if (
const auto *Off =
1066 shouldDump(Explicit,
".debug_loclists", DIDT_ID_DebugLoclists,
1067 DObj->getLoclistsSection().Data)) {
1072 if (
const auto *Off =
1073 shouldDump(ExplicitDWO,
".debug_loclists.dwo", DIDT_ID_DebugLoclists,
1074 DObj->getLoclistsDWOSection().Data)) {
1080 if (
const auto *Off =
1081 shouldDump(ExplicitDWO,
".debug_loc.dwo", DIDT_ID_DebugLoc,
1082 DObj->getLocDWOSection().Data)) {
1089 std::nullopt, *DObj,
nullptr,
1098 if (
const std::optional<uint64_t> *Off =
1099 shouldDump(Explicit,
".debug_frame", DIDT_ID_DebugFrame,
1100 DObj->getFrameSection().Data)) {
1102 (*DF)->dump(
OS, DumpOpts, *Off);
1104 RecoverableErrorHandler(
DF.takeError());
1107 if (
const std::optional<uint64_t> *Off =
1108 shouldDump(Explicit,
".eh_frame", DIDT_ID_DebugFrame,
1109 DObj->getEHFrameSection().Data)) {
1111 (*DF)->dump(
OS, DumpOpts, *Off);
1113 RecoverableErrorHandler(
DF.takeError());
1116 if (shouldDump(Explicit,
".debug_macro", DIDT_ID_DebugMacro,
1117 DObj->getMacroSection().Data)) {
1122 if (shouldDump(Explicit,
".debug_macro.dwo", DIDT_ID_DebugMacro,
1123 DObj->getMacroDWOSection())) {
1128 if (shouldDump(Explicit,
".debug_macinfo", DIDT_ID_DebugMacro,
1129 DObj->getMacinfoSection())) {
1134 if (shouldDump(Explicit,
".debug_macinfo.dwo", DIDT_ID_DebugMacro,
1135 DObj->getMacinfoDWOSection())) {
1137 MacinfoDWO->dump(
OS);
1140 if (shouldDump(Explicit,
".debug_aranges", DIDT_ID_DebugAranges,
1141 DObj->getArangesSection())) {
1149 RecoverableErrorHandler(std::move(
E));
1158 std::optional<uint64_t> DumpOffset) {
1160 if (DumpOffset &&
Parser.getOffset() != *DumpOffset) {
1164 OS <<
"debug_line[" <<
format(
"0x%8.8" PRIx64,
Parser.getOffset())
1171 auto DumpStrSection = [&](
StringRef Section) {
1182 OS <<
format(
"0x%8.8" PRIx64
": \"", StrOffset);
1189 if (
const auto *Off = shouldDump(Explicit,
".debug_line", DIDT_ID_DebugLine,
1190 DObj->getLineSection().Data)) {
1194 DumpLineSection(
Parser, DumpOpts, *Off);
1197 if (
const auto *Off =
1198 shouldDump(ExplicitDWO,
".debug_line.dwo", DIDT_ID_DebugLine,
1199 DObj->getLineDWOSection().Data)) {
1203 DumpLineSection(
Parser, DumpOpts, *Off);
1206 if (shouldDump(Explicit,
".debug_cu_index", DIDT_ID_DebugCUIndex,
1207 DObj->getCUIndexSection())) {
1211 if (shouldDump(Explicit,
".debug_tu_index", DIDT_ID_DebugTUIndex,
1212 DObj->getTUIndexSection())) {
1216 if (shouldDump(Explicit,
".debug_str", DIDT_ID_DebugStr,
1217 DObj->getStrSection()))
1218 DumpStrSection(DObj->getStrSection());
1220 if (shouldDump(ExplicitDWO,
".debug_str.dwo", DIDT_ID_DebugStr,
1221 DObj->getStrDWOSection()))
1222 DumpStrSection(DObj->getStrDWOSection());
1224 if (shouldDump(Explicit,
".debug_line_str", DIDT_ID_DebugLineStr,
1225 DObj->getLineStrSection()))
1226 DumpStrSection(DObj->getLineStrSection());
1228 if (shouldDump(Explicit,
".debug_addr", DIDT_ID_DebugAddr,
1229 DObj->getAddrSection().Data)) {
1235 if (shouldDump(Explicit,
".debug_ranges", DIDT_ID_DebugRanges,
1236 DObj->getRangesSection().Data)) {
1251 auto LookupPooledAddress =
1254 auto I = CUs.begin();
1256 return std::nullopt;
1257 return (*I)->getAddrOffsetSectionItem(
Index);
1260 if (shouldDump(Explicit,
".debug_rnglists", DIDT_ID_DebugRnglists,
1261 DObj->getRnglistsSection().Data)) {
1267 if (shouldDump(ExplicitDWO,
".debug_rnglists.dwo", DIDT_ID_DebugRnglists,
1268 DObj->getRnglistsDWOSection().Data)) {
1274 if (shouldDump(Explicit,
".debug_pubnames", DIDT_ID_DebugPubnames,
1275 DObj->getPubnamesSection().Data)) {
1281 if (shouldDump(Explicit,
".debug_pubtypes", DIDT_ID_DebugPubtypes,
1282 DObj->getPubtypesSection().Data)) {
1288 if (shouldDump(Explicit,
".debug_gnu_pubnames", DIDT_ID_DebugGnuPubnames,
1289 DObj->getGnuPubnamesSection().Data)) {
1295 if (shouldDump(Explicit,
".debug_gnu_pubtypes", DIDT_ID_DebugGnuPubtypes,
1296 DObj->getGnuPubtypesSection().Data)) {
1302 if (shouldDump(Explicit,
".debug_str_offsets", DIDT_ID_DebugStrOffsets,
1303 DObj->getStrOffsetsSection().Data))
1305 OS, DumpOpts,
"debug_str_offsets", *DObj, DObj->getStrOffsetsSection(),
1307 if (shouldDump(ExplicitDWO,
".debug_str_offsets.dwo", DIDT_ID_DebugStrOffsets,
1308 DObj->getStrOffsetsDWOSection().Data))
1310 DObj->getStrOffsetsDWOSection(),
1314 if (shouldDump(Explicit,
".gdb_index", DIDT_ID_GdbIndex,
1315 DObj->getGdbIndexSection())) {
1319 if (shouldDump(Explicit,
".apple_names", DIDT_ID_AppleNames,
1320 DObj->getAppleNamesSection().Data))
1323 if (shouldDump(Explicit,
".apple_types", DIDT_ID_AppleTypes,
1324 DObj->getAppleTypesSection().Data))
1327 if (shouldDump(Explicit,
".apple_namespaces", DIDT_ID_AppleNamespaces,
1328 DObj->getAppleNamespacesSection().Data))
1331 if (shouldDump(Explicit,
".apple_objc", DIDT_ID_AppleObjC,
1332 DObj->getAppleObjCSection().Data))
1334 if (shouldDump(Explicit,
".debug_names", DIDT_ID_DebugNames,
1335 DObj->getNamesSection().Data))
1343 if (
const auto *R = TUI.getFromHash(Hash))
1344 return dyn_cast_or_null<DWARFTypeUnit>(
1349 auto Iter = Map.find(Hash);
1350 if (Iter != Map.end())
1351 return Iter->second;
1359 if (
const auto *R = CUI.getFromHash(Hash))
1360 return dyn_cast_or_null<DWARFCompileUnit>(
1371 if (!DWOCU->getDWOId()) {
1372 if (std::optional<uint64_t> DWOId =
1373 toUnsigned(DWOCU->getUnitDIE().find(DW_AT_GNU_dwo_id)))
1374 DWOCU->setDWOId(*DWOId);
1379 if (DWOCU->getDWOId() == Hash)
1380 return dyn_cast<DWARFCompileUnit>(DWOCU.get());
1386 if (
auto *
CU = State->getNormalUnits().getUnitForOffset(
Offset))
1387 return CU->getDIEForOffset(
Offset);
1396 if (DumpOpts.
DumpType & DIDT_DebugCUIndex)
1398 if (DumpOpts.
DumpType & DIDT_DebugTUIndex)
1400 if (DumpOpts.
DumpType & DIDT_DebugInfo)
1402 if (DumpOpts.
DumpType & DIDT_DebugLine)
1404 if (DumpOpts.
DumpType & DIDT_DebugStrOffsets)
1411 return State->getCUIndex();
1415 return State->getTUIndex();
1419 return State->getGdbIndex();
1423 return State->getDebugAbbrev();
1427 return State->getDebugAbbrevDWO();
1431 return State->getDebugLoc();
1435 return State->getDebugAranges();
1439 return State->getDebugFrame();
1443 return State->getEHFrame();
1447 return State->getDebugMacro();
1451 return State->getDebugMacroDWO();
1455 return State->getDebugMacinfo();
1459 return State->getDebugMacinfoDWO();
1464 return State->getDebugNames();
1468 return State->getAppleNames();
1472 return State->getAppleTypes();
1476 return State->getAppleNamespaces();
1480 return State->getAppleObjC();
1487 if (!ExpectedLineTable) {
1488 WarningHandler(ExpectedLineTable.
takeError());
1491 return *ExpectedLineTable;
1496 return State->getLineTableForUnit(U, RecoverableErrorHandler);
1500 return State->clearLineTableForUnit(U);
1504 return State->getDWOUnits(Lazy);
1508 return dyn_cast_or_null<DWARFCompileUnit>(
1509 State->getNormalUnits().getUnitForOffset(
Offset));
1533 if (
CU->getVariableForAddress(
Address)) {
1547 Result.CompileUnit =
CU;
1548 Result.FunctionDIE =
CU->getSubroutineForAddress(
Address);
1550 std::vector<DWARFDie> Worklist;
1551 Worklist.push_back(Result.FunctionDIE);
1552 while (!Worklist.empty()) {
1554 Worklist.pop_back();
1559 if (
DIE.
getTag() == DW_TAG_lexical_block &&
1561 Result.BlockDIE =
DIE;
1576 std::string &FunctionName, std::string &StartFile,
uint32_t &StartLine,
1577 std::optional<uint64_t> &StartAddress) {
1582 CU->getInlinedChainForAddress(
Address, InlinedChain);
1583 if (InlinedChain.
empty())
1587 bool FoundResult =
false;
1588 const char *
Name =
nullptr;
1589 if (
Kind != FunctionNameKind::None && (
Name =
DIE.getSubroutineName(
Kind))) {
1590 FunctionName =
Name;
1593 std::string DeclFile =
DIE.getDeclFile(FileNameKind);
1594 if (!DeclFile.empty()) {
1595 StartFile = DeclFile;
1598 if (
auto DeclLineResult =
DIE.getDeclLine()) {
1599 StartLine = DeclLineResult;
1603 StartAddress = LowPcAddr->Address;
1607static std::optional<int64_t>
1609 std::optional<unsigned> FrameBaseReg) {
1610 if (!Expr.
empty() &&
1611 (Expr[0] == DW_OP_fbreg ||
1612 (FrameBaseReg && Expr[0] == DW_OP_breg0 + *FrameBaseReg))) {
1616 if (Expr.
size() == Count + 1)
1619 if (Expr.
size() == Count + 2 && Expr[Count + 1] == DW_OP_deref)
1623 return std::nullopt;
1627 DWARFDie Die, std::vector<DILocal> &Result) {
1628 if (Die.
getTag() == DW_TAG_variable ||
1629 Die.
getTag() == DW_TAG_formal_parameter) {
1634 std::optional<unsigned> FrameBaseReg;
1635 if (
auto FrameBase = Subprogram.
find(DW_AT_frame_base))
1637 if (!Expr->empty() && (*Expr)[0] >= DW_OP_reg0 &&
1638 (*Expr)[0] <= DW_OP_reg31) {
1639 FrameBaseReg = (*Expr)[0] - DW_OP_reg0;
1642 if (
Expected<std::vector<DWARFLocationExpression>> Loc =
1644 for (
const auto &Entry : *Loc) {
1645 if (std::optional<int64_t> FrameOffset =
1647 Local.FrameOffset = *FrameOffset;
1657 if (
auto TagOffsetAttr = Die.
find(DW_AT_LLVM_tag_offset))
1658 Local.TagOffset = TagOffsetAttr->getAsUnsignedConstant();
1663 if (
auto NameAttr = Die.
find(DW_AT_name))
1668 if (
auto DeclFileAttr = Die.
find(DW_AT_decl_file)) {
1669 if (
const auto *LT =
CU->getContext().getLineTableForUnit(
CU))
1670 LT->getFileNameByIndex(
1671 *DeclFileAttr->getAsUnsignedConstant(),
CU->getCompilationDir(),
1672 DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath,
1675 if (
auto DeclLineAttr = Die.
find(DW_AT_decl_line))
1676 Local.DeclLine = *DeclLineAttr->getAsUnsignedConstant();
1682 if (Die.
getTag() == DW_TAG_inlined_subroutine)
1685 Subprogram = Origin;
1687 for (
auto Child : Die)
1688 addLocalsForDie(
CU, Subprogram, Child, Result);
1693 std::vector<DILocal> Result;
1700 addLocalsForDie(
CU, Subprogram, Subprogram, Result);
1713 Result.StartFileName, Result.StartLine, Result.StartAddress);
1714 if (
Spec.FLIKind != FileLineInfoKind::None) {
1716 LineTable->getFileLineInfoForAddress(
1718 Spec.FLIKind, Result);
1733 Result.FileName = Die.
getDeclFile(FileLineInfoKind::AbsoluteFilePath);
1748 std::string StartFileName;
1750 std::optional<uint64_t> StartAddress;
1752 Spec.FLIKind, FunctionName,
1753 StartFileName, StartLine, StartAddress);
1757 if (
Spec.FLIKind == FileLineInfoKind::None) {
1759 Result.FunctionName = FunctionName;
1760 Result.StartFileName = StartFileName;
1761 Result.StartLine = StartLine;
1762 Result.StartAddress = StartAddress;
1763 Lines.push_back(std::make_pair(
Address.Address, Result));
1770 std::vector<uint32_t> RowVector;
1776 for (
uint32_t RowIndex : RowVector) {
1781 Spec.FLIKind, Result.FileName);
1782 Result.FunctionName = FunctionName;
1783 Result.Line = Row.Line;
1784 Result.Column = Row.Column;
1785 Result.StartFileName = StartFileName;
1786 Result.StartLine = StartLine;
1787 Result.StartAddress = StartAddress;
1788 Lines.push_back(std::make_pair(Row.Address.Address, Result));
1801 return InliningInfo;
1805 CU->getInlinedChainForAddress(
Address.Address, InlinedChain);
1806 if (InlinedChain.
size() == 0) {
1809 if (
Spec.FLIKind != FileLineInfoKind::None) {
1813 {Address.Address, Address.SectionIndex},
1814 CU->getCompilationDir(),
Spec.FLIKind, Frame))
1817 return InliningInfo;
1820 uint32_t CallFile = 0, CallLine = 0, CallColumn = 0, CallDiscriminator = 0;
1821 for (
uint32_t i = 0, n = InlinedChain.
size(); i != n; i++) {
1822 DWARFDie &FunctionDIE = InlinedChain[i];
1827 if (
auto DeclLineResult = FunctionDIE.
getDeclLine())
1832 if (
Spec.FLIKind != FileLineInfoKind::None) {
1841 Spec.FLIKind, Frame);
1848 Frame.
Line = CallLine;
1849 Frame.
Column = CallColumn;
1860 return InliningInfo;
1863std::shared_ptr<DWARFContext>
1865 return State->getDWOContext(AbsolutePath);
1869 return make_error<StringError>(Reason +
toString(std::move(
E)),
1885 std::map<SymbolRef, SymInfo> &Cache) {
1890 std::map<SymbolRef, SymInfo>::iterator CacheIt = Cache.end();
1895 std::tie(CacheIt, New) = Cache.insert({*
Sym, {0, 0}});
1897 return CacheIt->second;
1901 return createError(
"failed to compute symbol address: ",
1905 auto SectOrErr =
Sym->getSection();
1907 return createError(
"failed to get symbol section: ",
1908 SectOrErr.takeError());
1911 Ret.Address = *SymAddrOrErr;
1912 }
else if (
auto *MObj = dyn_cast<MachOObjectFile>(&Obj)) {
1918 Ret.SectionIndex = RSec->
getIndex();
1928 if (
uint64_t SectionLoadAddress = L->getSectionLoadAddress(*RSec))
1929 Ret.Address += SectionLoadAddress - RSec->
getAddress();
1931 if (CacheIt != Cache.end())
1932 CacheIt->second = Ret;
1953class DWARFObjInMemory final :
public DWARFObject {
1954 bool IsLittleEndian;
1955 uint8_t AddressSize;
1958 std::vector<SectionName> SectionNames;
1961 std::map<object::SectionRef, unsigned>>;
1963 InfoSectionMap InfoSections;
1964 InfoSectionMap TypesSections;
1965 InfoSectionMap InfoDWOSections;
1966 InfoSectionMap TypesDWOSections;
1968 DWARFSectionMap LocSection;
1969 DWARFSectionMap LoclistsSection;
1970 DWARFSectionMap LoclistsDWOSection;
1971 DWARFSectionMap LineSection;
1972 DWARFSectionMap RangesSection;
1973 DWARFSectionMap RnglistsSection;
1974 DWARFSectionMap StrOffsetsSection;
1975 DWARFSectionMap LineDWOSection;
1976 DWARFSectionMap FrameSection;
1977 DWARFSectionMap EHFrameSection;
1978 DWARFSectionMap LocDWOSection;
1979 DWARFSectionMap StrOffsetsDWOSection;
1980 DWARFSectionMap RangesDWOSection;
1981 DWARFSectionMap RnglistsDWOSection;
1982 DWARFSectionMap AddrSection;
1983 DWARFSectionMap AppleNamesSection;
1984 DWARFSectionMap AppleTypesSection;
1985 DWARFSectionMap AppleNamespacesSection;
1986 DWARFSectionMap AppleObjCSection;
1987 DWARFSectionMap NamesSection;
1988 DWARFSectionMap PubnamesSection;
1989 DWARFSectionMap PubtypesSection;
1990 DWARFSectionMap GnuPubnamesSection;
1991 DWARFSectionMap GnuPubtypesSection;
1992 DWARFSectionMap MacroSection;
1996 .
Case(
"debug_loc", &LocSection)
1997 .
Case(
"debug_loclists", &LoclistsSection)
1998 .
Case(
"debug_loclists.dwo", &LoclistsDWOSection)
1999 .
Case(
"debug_line", &LineSection)
2000 .
Case(
"debug_frame", &FrameSection)
2001 .
Case(
"eh_frame", &EHFrameSection)
2002 .
Case(
"debug_str_offsets", &StrOffsetsSection)
2003 .
Case(
"debug_ranges", &RangesSection)
2004 .
Case(
"debug_rnglists", &RnglistsSection)
2005 .
Case(
"debug_loc.dwo", &LocDWOSection)
2006 .
Case(
"debug_line.dwo", &LineDWOSection)
2007 .
Case(
"debug_names", &NamesSection)
2008 .
Case(
"debug_rnglists.dwo", &RnglistsDWOSection)
2009 .
Case(
"debug_str_offsets.dwo", &StrOffsetsDWOSection)
2010 .
Case(
"debug_addr", &AddrSection)
2011 .
Case(
"apple_names", &AppleNamesSection)
2012 .
Case(
"debug_pubnames", &PubnamesSection)
2013 .
Case(
"debug_pubtypes", &PubtypesSection)
2014 .
Case(
"debug_gnu_pubnames", &GnuPubnamesSection)
2015 .
Case(
"debug_gnu_pubtypes", &GnuPubtypesSection)
2016 .
Case(
"apple_types", &AppleTypesSection)
2017 .
Case(
"apple_namespaces", &AppleNamespacesSection)
2018 .
Case(
"apple_namespac", &AppleNamespacesSection)
2019 .
Case(
"apple_objc", &AppleObjCSection)
2020 .
Case(
"debug_macro", &MacroSection)
2039 std::deque<SmallString<0>> UncompressedSections;
2045 .
Case(
"debug_abbrev", &AbbrevSection)
2046 .
Case(
"debug_aranges", &ArangesSection)
2047 .
Case(
"debug_str", &StrSection)
2048 .
Case(
"debug_macinfo", &MacinfoSection)
2049 .
Case(
"debug_macinfo.dwo", &MacinfoDWOSection)
2050 .
Case(
"debug_macro.dwo", &MacroDWOSection)
2051 .
Case(
"debug_abbrev.dwo", &AbbrevDWOSection)
2052 .
Case(
"debug_str.dwo", &StrDWOSection)
2053 .
Case(
"debug_cu_index", &CUIndexSection)
2054 .
Case(
"debug_tu_index", &TUIndexSection)
2055 .
Case(
"gdb_index", &GdbIndexSection)
2056 .
Case(
"debug_line_str", &LineStrSection)
2077 UncompressedSections.push_back(std::move(Out));
2078 Data = UncompressedSections.back();
2084 DWARFObjInMemory(
const StringMap<std::unique_ptr<MemoryBuffer>> &Sections,
2085 uint8_t AddrSize,
bool IsLittleEndian)
2086 : IsLittleEndian(IsLittleEndian) {
2087 for (
const auto &SecIt : Sections) {
2088 if (
StringRef *SectionData = mapSectionToMember(SecIt.first()))
2089 *SectionData = SecIt.second->getBuffer();
2090 else if (SecIt.first() ==
"debug_info")
2093 InfoSections[
SectionRef()].Data = SecIt.second->getBuffer();
2094 else if (SecIt.first() ==
"debug_info.dwo")
2095 InfoDWOSections[
SectionRef()].Data = SecIt.second->getBuffer();
2096 else if (SecIt.first() ==
"debug_types")
2097 TypesSections[
SectionRef()].Data = SecIt.second->getBuffer();
2098 else if (SecIt.first() ==
"debug_types.dwo")
2099 TypesDWOSections[
SectionRef()].Data = SecIt.second->getBuffer();
2106 : IsLittleEndian(Obj.isLittleEndian()),
2107 AddressSize(Obj.getBytesInAddress()), FileName(Obj.
getFileName()),
2113 if (
auto NameOrErr =
Section.getName())
2118 ++SectionAmountMap[
Name];
2119 SectionNames.push_back({
Name,
true });
2132 HandleError(
createError(
"failed to get relocated section: ",
2142 if (!L || !
L->getLoadedSectionContents(*RelocatedSection, Data)) {
2151 if (
auto Err = maybeDecompress(Section,
Name, Data)) {
2163 *SectionData = Data;
2164 if (
Name ==
"debug_ranges") {
2166 RangesDWOSection.Data = Data;
2167 }
else if (
Name ==
"debug_frame" ||
Name ==
"eh_frame") {
2169 S->Address =
Section.getAddress();
2171 }
else if (InfoSectionMap *Sections =
2173 .Case(
"debug_info", &InfoSections)
2174 .Case(
"debug_info.dwo", &InfoDWOSections)
2175 .Case(
"debug_types", &TypesSections)
2176 .Case(
"debug_types.dwo", &TypesDWOSections)
2180 DWARFSectionMap &S = (*Sections)[
Section];
2185 (RelocAction == DWARFContext::ProcessDebugRelocations::Ignore))
2189 if (
auto NameOrErr = RelocatedSection->
getName())
2190 RelSecName = *NameOrErr;
2198 if (L &&
L->getLoadedSectionContents(*RelocatedSection, RelSecData))
2206 if (!L && isa<MachOObjectFile>(&Obj))
2209 if (!
Section.relocations().empty() &&
Name.ends_with(
".dwo") &&
2211 HandleWarning(
createError(
"unexpected relocations for dwo section '" +
2218 DWARFSectionMap *Sec = mapNameToDWARFSection(RelSecName);
2223 if (RelSecName ==
"debug_info")
2224 Map = &
static_cast<DWARFSectionMap &
>(InfoSections[*RelocatedSection])
2226 else if (RelSecName ==
"debug_types")
2228 &
static_cast<DWARFSectionMap &
>(TypesSections[*RelocatedSection])
2238 std::map<SymbolRef, SymInfo> AddrCache;
2250 if (!SymInfoOrErr) {
2259 if (Supports && Supports(Reloc.getType())) {
2260 auto I =
Map->try_emplace(
2263 SymInfoOrErr->SectionIndex, Reloc, SymInfoOrErr->Address,
2264 std::optional<object::RelocationRef>(), 0, Resolver});
2272 "At most two relocations per offset are supported"));
2279 Reloc.getTypeName(
Type);
2289 if (SectionAmountMap[S.Name] > 1)
2290 S.IsNameUnique =
false;
2295 auto &Sec =
static_cast<const DWARFSectionMap &
>(S);
2297 if (AI == Sec.Relocs.end())
2298 return std::nullopt;
2305 return SectionNames;
2308 bool isLittleEndian()
const override {
return IsLittleEndian; }
2309 StringRef getAbbrevDWOSection()
const override {
return AbbrevDWOSection; }
2310 const DWARFSection &getLineDWOSection()
const override {
2311 return LineDWOSection;
2313 const DWARFSection &getLocDWOSection()
const override {
2314 return LocDWOSection;
2316 StringRef getStrDWOSection()
const override {
return StrDWOSection; }
2317 const DWARFSection &getStrOffsetsDWOSection()
const override {
2318 return StrOffsetsDWOSection;
2320 const DWARFSection &getRangesDWOSection()
const override {
2321 return RangesDWOSection;
2323 const DWARFSection &getRnglistsDWOSection()
const override {
2324 return RnglistsDWOSection;
2326 const DWARFSection &getLoclistsDWOSection()
const override {
2327 return LoclistsDWOSection;
2329 const DWARFSection &getAddrSection()
const override {
return AddrSection; }
2330 StringRef getCUIndexSection()
const override {
return CUIndexSection; }
2331 StringRef getGdbIndexSection()
const override {
return GdbIndexSection; }
2332 StringRef getTUIndexSection()
const override {
return TUIndexSection; }
2335 const DWARFSection &getStrOffsetsSection()
const override {
2336 return StrOffsetsSection;
2338 StringRef getLineStrSection()
const override {
return LineStrSection; }
2341 void forEachInfoDWOSections(
2343 for (
auto &
P : InfoDWOSections)
2346 void forEachTypesDWOSections(
2348 for (
auto &
P : TypesDWOSections)
2352 StringRef getAbbrevSection()
const override {
return AbbrevSection; }
2353 const DWARFSection &getLocSection()
const override {
return LocSection; }
2354 const DWARFSection &getLoclistsSection()
const override {
return LoclistsSection; }
2355 StringRef getArangesSection()
const override {
return ArangesSection; }
2357 return FrameSection;
2359 const DWARFSection &getEHFrameSection()
const override {
2360 return EHFrameSection;
2362 const DWARFSection &getLineSection()
const override {
return LineSection; }
2363 StringRef getStrSection()
const override {
return StrSection; }
2364 const DWARFSection &getRangesSection()
const override {
return RangesSection; }
2365 const DWARFSection &getRnglistsSection()
const override {
2366 return RnglistsSection;
2368 const DWARFSection &getMacroSection()
const override {
return MacroSection; }
2369 StringRef getMacroDWOSection()
const override {
return MacroDWOSection; }
2370 StringRef getMacinfoSection()
const override {
return MacinfoSection; }
2371 StringRef getMacinfoDWOSection()
const override {
return MacinfoDWOSection; }
2372 const DWARFSection &getPubnamesSection()
const override {
return PubnamesSection; }
2373 const DWARFSection &getPubtypesSection()
const override {
return PubtypesSection; }
2374 const DWARFSection &getGnuPubnamesSection()
const override {
2375 return GnuPubnamesSection;
2377 const DWARFSection &getGnuPubtypesSection()
const override {
2378 return GnuPubtypesSection;
2380 const DWARFSection &getAppleNamesSection()
const override {
2381 return AppleNamesSection;
2383 const DWARFSection &getAppleTypesSection()
const override {
2384 return AppleTypesSection;
2386 const DWARFSection &getAppleNamespacesSection()
const override {
2387 return AppleNamespacesSection;
2389 const DWARFSection &getAppleObjCSection()
const override {
2390 return AppleObjCSection;
2393 return NamesSection;
2397 uint8_t getAddressSize()
const override {
return AddressSize; }
2398 void forEachInfoSections(
2400 for (
auto &
P : InfoSections)
2403 void forEachTypesSections(
2405 for (
auto &
P : TypesSections)
2411std::unique_ptr<DWARFContext>
2415 std::function<
void(
Error)> RecoverableErrorHandler,
2416 std::function<
void(
Error)> WarningHandler,
2418 auto DObj = std::make_unique<DWARFObjInMemory>(
2419 Obj, L, RecoverableErrorHandler, WarningHandler, RelocAction);
2420 return std::make_unique<DWARFContext>(std::move(DObj),
2422 RecoverableErrorHandler,
2427std::unique_ptr<DWARFContext>
2429 uint8_t AddrSize,
bool isLittleEndian,
2430 std::function<
void(
Error)> RecoverableErrorHandler,
2431 std::function<
void(
Error)> WarningHandler,
2434 std::make_unique<DWARFObjInMemory>(Sections, AddrSize,
isLittleEndian);
2435 return std::make_unique<DWARFContext>(
2436 std::move(DObj),
"", RecoverableErrorHandler, WarningHandler, ThreadSafe);
2446 return CUs.empty() ? 0 : (*CUs.begin())->getAddressByteSize();
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static Expected< StringRef > getFileName(const DebugStringTableSubsectionRef &Strings, const DebugChecksumsSubsectionRef &Checksums, uint32_t FileID)
static void dumpLoclistsSection(raw_ostream &OS, DIDumpOptions DumpOpts, DWARFDataExtractor Data, const DWARFObject &Obj, std::optional< uint64_t > DumpOffset)
static void dumpRnglistsSection(raw_ostream &OS, DWARFDataExtractor &rnglistData, llvm::function_ref< std::optional< object::SectionedAddress >(uint32_t)> LookupPooledAddress, DIDumpOptions DumpOpts)
static void dumpUUID(raw_ostream &OS, const ObjectFile &Obj)
Dump the UUID load command.
static bool getFunctionNameAndStartLineForAddress(DWARFCompileUnit *CU, uint64_t Address, FunctionNameKind Kind, DILineInfoSpecifier::FileLineInfoKind FileNameKind, std::string &FunctionName, std::string &StartFile, uint32_t &StartLine, std::optional< uint64_t > &StartAddress)
TODO: change input parameter from "uint64_t Address" into "SectionedAddress Address".
static void dumpPubTableSection(raw_ostream &OS, DIDumpOptions DumpOpts, DWARFDataExtractor Data, bool GnuStyle)
void fixupIndex(DWARFContext &C, DWARFUnitIndex &Index)
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.
static void dumpAddrSection(raw_ostream &OS, DWARFDataExtractor &AddrData, DIDumpOptions DumpOpts, uint16_t Version, uint8_t AddrSize)
static T & getAccelTable(std::unique_ptr< T > &Cache, const DWARFObject &Obj, const DWARFSection &Section, StringRef StringSection, bool IsLittleEndian)
std::vector< std::optional< StrOffsetsContributionDescriptor > > ContributionCollection
void fixupIndexV4(DWARFContext &C, DWARFUnitIndex &Index)
static ContributionCollection collectContributionData(DWARFContext::unit_iterator_range Units)
static bool isRelocScattered(const object::ObjectFile &Obj, const RelocationRef &Reloc)
static std::optional< int64_t > getExpressionFrameOffset(ArrayRef< uint8_t > Expr, std::optional< unsigned > FrameBaseReg)
void fixupIndexV5(DWARFContext &C, DWARFUnitIndex &Index)
static Error createError(const Twine &Reason, llvm::Error E)
static void dumpStringOffsetsSection(raw_ostream &OS, DIDumpOptions DumpOpts, StringRef SectionName, const DWARFObject &Obj, const DWARFSection &StringOffsetsSection, StringRef StringSection, DWARFContext::unit_iterator_range Units, bool LittleEndian)
static RegisterPass< DebugifyFunctionPass > DF("debugify-function", "Attach debug info to a function")
This file contains constants used for implementing Dwarf debug support.
This file implements a map that provides insertion order iteration.
This file defines the SmallString class.
This file defines the SmallVector class.
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
std::pair< llvm::MachO::Target, std::string > UUID
Expected< const DWARFDebugFrame * > getDebugFrame() override
const DWARFDebugMacro * getDebugMacinfoDWO() override
const DWARFDebugMacro * getDebugMacroDWO() override
const DWARFUnitIndex & getCUIndex() override
const AppleAcceleratorTable & getAppleNamespaces() override
const AppleAcceleratorTable & getAppleObjC() override
const DWARFDebugLoc * getDebugLoc() override
DWARFGdbIndex & getGdbIndex() override
DWARFUnitVector & getDWOUnits(bool Lazy) override
const AppleAcceleratorTable & getAppleNames() override
const AppleAcceleratorTable & getAppleTypes() override
const DWARFDebugNames & getDebugNames() override
const DWARFUnitIndex & getTUIndex() override
const DWARFDebugAranges * getDebugAranges() override
DWARFUnitVector & getNormalUnits() override
bool isThreadSafe() const override
ThreadSafeState(DWARFContext &DC, std::string &DWP)
Expected< const DWARFDebugFrame * > getEHFrame() override
std::shared_ptr< DWARFContext > getDWOContext(StringRef AbsolutePath) override
const DenseMap< uint64_t, DWARFTypeUnit * > & getTypeUnitMap(bool IsDWO) override
const DWARFDebugAbbrev * getDebugAbbrevDWO() override
const DWARFDebugAbbrev * getDebugAbbrev() override
Expected< const DWARFDebugLine::LineTable * > getLineTableForUnit(DWARFUnit *U, function_ref< void(Error)> RecoverableErrorHandler) override
const DWARFDebugMacro * getDebugMacinfo() override
const DWARFDebugMacro * getDebugMacro() override
void clearLineTableForUnit(DWARFUnit *U) override
const DenseMap< uint64_t, DWARFTypeUnit * > & getTypeUnitMap(bool IsDWO) override
const AppleAcceleratorTable & getAppleObjC() override
const DenseMap< uint64_t, DWARFTypeUnit * > & getNormalTypeUnitMap()
const DenseMap< uint64_t, DWARFTypeUnit * > & getDWOTypeUnitMap()
const DWARFDebugMacro * getDebugMacinfo() override
const AppleAcceleratorTable & getAppleTypes() override
const DWARFUnitIndex & getCUIndex() override
Expected< const DWARFDebugFrame * > getDebugFrame() override
const AppleAcceleratorTable & getAppleNamespaces() override
ThreadUnsafeDWARFContextState(DWARFContext &DC, std::string &DWP)
Expected< const DWARFDebugLine::LineTable * > getLineTableForUnit(DWARFUnit *U, function_ref< void(Error)> RecoverableErrorHandler) override
const DWARFDebugAbbrev * getDebugAbbrev() override
const DWARFDebugNames & getDebugNames() override
DWARFUnitVector & getDWOUnits(bool Lazy) override
const DWARFDebugAbbrev * getDebugAbbrevDWO() override
const DWARFDebugMacro * getDebugMacroDWO() override
DWARFGdbIndex & getGdbIndex() override
void clearLineTableForUnit(DWARFUnit *U) override
DWARFUnitVector & getNormalUnits() override
std::shared_ptr< DWARFContext > getDWOContext(StringRef AbsolutePath) override
const DWARFDebugMacro * getDebugMacinfoDWO() override
const AppleAcceleratorTable & getAppleNames() override
const DWARFUnitIndex & getTUIndex() override
bool isThreadSafe() const override
const DWARFDebugMacro * getDebugMacro() override
const DWARFDebugAranges * getDebugAranges() override
const DWARFDebugLoc * getDebugLoc() override
Expected< const DWARFDebugFrame * > getEHFrame() override
This implements the Apple accelerator table format, a precursor of the DWARF 5 accelerator table form...
void dump(raw_ostream &OS) const override
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
bool empty() const
empty - Check if the array is empty.
A structured debug information entry.
dwarf::Tag getTag() const
A format-neutral container for inlined code description.
void addFrame(const DILineInfo &Frame)
DWARFContextState This structure contains all member variables for DWARFContext that need to be prote...
MacroSecType
Helper enum to distinguish between macro[.dwo] and macinfo[.dwo] section.
std::unique_ptr< DWARFDebugMacro > parseMacroOrMacinfo(MacroSecType SectionType)
Parse a macro[.dwo] or macinfo[.dwo] section.
DWARFContext This data structure is the top level entity that deals with dwarf debug information pars...
DWARFCompileUnit * getCompileUnitForCodeAddress(uint64_t Address)
Return the compile unit which contains instruction with provided address.
uint8_t getCUAddrSize()
Get address size from CUs.
DIInliningInfo getInliningInfoForAddress(object::SectionedAddress Address, DILineInfoSpecifier Specifier=DILineInfoSpecifier()) override
Expected< const DWARFDebugFrame * > getDebugFrame()
Get a pointer to the parsed frame information object.
function_ref< void(Error)> getRecoverableErrorHandler()
DWARFGdbIndex & getGdbIndex()
unsigned getNumCompileUnits()
Get the number of compile units in this context.
DWARFContext(std::unique_ptr< const DWARFObject > DObj, std::string DWPName="", std::function< void(Error)> RecoverableErrorHandler=WithColor::defaultErrorHandler, std::function< void(Error)> WarningHandler=WithColor::defaultWarningHandler, bool ThreadSafe=false)
DWARFDie getDIEForOffset(uint64_t Offset)
Get a DIE given an exact offset.
unsigned getNumTypeUnits()
Get the number of type units in this context.
DIEsForAddress getDIEsForAddress(uint64_t Address)
Get the compilation unit, the function DIE and lexical block DIE for the given address where applicab...
DILineInfo getLineInfoForAddress(object::SectionedAddress Address, DILineInfoSpecifier Specifier=DILineInfoSpecifier()) override
const DWARFDebugAbbrev * getDebugAbbrevDWO()
Get a pointer to the parsed dwo abbreviations object.
compile_unit_range compile_units()
Get compile units in this context.
const AppleAcceleratorTable & getAppleObjC()
Get a reference to the parsed accelerator table object.
const DWARFUnitIndex & getTUIndex()
DWARFCompileUnit * getCompileUnitForDataAddress(uint64_t Address)
Return the compile unit which contains data with the provided address.
const DWARFDebugAbbrev * getDebugAbbrev()
Get a pointer to the parsed DebugAbbrev object.
std::vector< DILocal > getLocalsForAddress(object::SectionedAddress Address) override
DataExtractor getStringExtractor() const
DWARFCompileUnit * getCompileUnitForOffset(uint64_t Offset)
Return the compile unit that includes an offset (relative to .debug_info).
const DWARFDebugNames & getDebugNames()
Get a reference to the parsed accelerator table object.
unsigned getNumDWOTypeUnits()
Get the number of type units in the DWO context.
const DWARFDebugMacro * getDebugMacroDWO()
Get a pointer to the parsed DebugMacroDWO information object.
DILineInfoTable getLineInfoForAddressRange(object::SectionedAddress Address, uint64_t Size, DILineInfoSpecifier Specifier=DILineInfoSpecifier()) override
bool isLittleEndian() const
const DWARFDebugLine::LineTable * getLineTableForUnit(DWARFUnit *U)
Get a pointer to a parsed line table corresponding to a compile unit.
void clearLineTableForUnit(DWARFUnit *U)
const AppleAcceleratorTable & getAppleTypes()
Get a reference to the parsed accelerator table object.
const AppleAcceleratorTable & getAppleNames()
Get a reference to the parsed accelerator table object.
compile_unit_range dwo_compile_units()
Get compile units in the DWO context.
const DWARFDebugLoc * getDebugLoc()
Get a pointer to the parsed DebugLoc object.
const DWARFDebugMacro * getDebugMacinfoDWO()
Get a pointer to the parsed DebugMacinfoDWO information object.
bool verify(raw_ostream &OS, DIDumpOptions DumpOpts={}) override
unit_iterator_range dwo_types_section_units()
Get units from .debug_types.dwo in the DWO context.
void dump(raw_ostream &OS, DIDumpOptions DumpOpts, std::array< std::optional< uint64_t >, DIDT_ID_Count > DumpOffsets)
Dump a textual representation to OS.
unit_iterator_range normal_units()
Get all normal compile/type units in this context.
unit_iterator_range types_section_units()
Get units from .debug_types in this context.
std::shared_ptr< DWARFContext > getDWOContext(StringRef AbsolutePath)
DWARFCompileUnit * getDWOCompileUnitForHash(uint64_t Hash)
unsigned getNumDWOCompileUnits()
Get the number of compile units in the DWO context.
DILineInfo getLineInfoForDataAddress(object::SectionedAddress Address) override
const DWARFDebugAranges * getDebugAranges()
Get a pointer to the parsed DebugAranges object.
const DWARFUnitIndex & getCUIndex()
Expected< const DWARFDebugFrame * > getEHFrame()
Get a pointer to the parsed eh frame information object.
unit_iterator_range info_section_units()
Get units from .debug_info in this context.
DWARFTypeUnit * getTypeUnitForHash(uint16_t Version, uint64_t Hash, bool IsDWO)
unit_iterator_range dwo_info_section_units()
Get units from .debug_info..dwo in the DWO context.
DataExtractor getStringDWOExtractor() const
const AppleAcceleratorTable & getAppleNamespaces()
Get a reference to the parsed accelerator table object.
const DWARFDebugMacro * getDebugMacro()
Get a pointer to the parsed DebugMacro information object.
static std::unique_ptr< DWARFContext > create(const object::ObjectFile &Obj, ProcessDebugRelocations RelocAction=ProcessDebugRelocations::Process, const LoadedObjectInfo *L=nullptr, std::string DWPName="", std::function< void(Error)> RecoverableErrorHandler=WithColor::defaultErrorHandler, std::function< void(Error)> WarningHandler=WithColor::defaultWarningHandler, bool ThreadSafe=false)
const DWARFDebugMacro * getDebugMacinfo()
Get a pointer to the parsed DebugMacinfo information object.
unit_iterator_range dwo_units()
Get all units in the DWO context.
const DWARFObject & getDWARFObj() const
void dump(raw_ostream &OS) const
A class representing an address table as specified in DWARF v5.
void dump(raw_ostream &OS, DIDumpOptions DumpOpts={}) const
Error extract(const DWARFDataExtractor &Data, uint64_t *OffsetPtr, uint16_t CUVersion, uint8_t CUAddrSize, std::function< void(Error)> WarnCallback)
Extract the entire table, including all addresses.
std::optional< uint64_t > getFullLength() const
Return the full length of this table, including the length field.
Error extract(DWARFDataExtractor data, uint64_t *offset_ptr, function_ref< void(Error)> WarningHandler)
void dump(raw_ostream &OS) const
uint64_t findAddress(uint64_t Address) const
Helper to allow for parsing of an entire .debug_line section in sequence.
void dump(raw_ostream &OS, const DWARFObject &Obj, DIDumpOptions DumpOpts, std::optional< uint64_t > Offset) const
Print the location lists found within the debug_loc section.
void dumpRange(uint64_t StartOffset, uint64_t Size, raw_ostream &OS, const DWARFObject &Obj, DIDumpOptions DumpOpts)
Dump all location lists within the given range.
.debug_names section consists of one or more units.
void dump(raw_ostream &OS) const override
Represents structure for holding and parsing .debug_pub* tables.
void extract(DWARFDataExtractor Data, bool GnuStyle, function_ref< void(Error)> RecoverableErrorHandler)
void dump(raw_ostream &OS) const
Error extract(const DWARFDataExtractor &data, uint64_t *offset_ptr)
void dump(raw_ostream &OS) const
Utility class that carries the DWARF compile/type unit and the debug info entry in an object.
DWARFDie getAttributeValueAsReferencedDie(dwarf::Attribute Attr) const
Extract the specified attribute from this DIE as the referenced DIE.
std::optional< DWARFFormValue > find(dwarf::Attribute Attr) const
Extract the specified attribute from this DIE.
const char * getSubroutineName(DINameKind Kind) const
If a DIE represents a subprogram (or inlined subroutine), returns its mangled name (or short name,...
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...
std::string getDeclFile(DILineInfoSpecifier::FileLineInfoKind Kind) const
uint64_t getDeclLine() const
Returns the declaration line (start line) for a DIE, assuming it specifies a subprogram.
dwarf::Tag getTag() const
Expected< DWARFLocationExpressionsVector > getLocations(dwarf::Attribute Attr) const
void dump(raw_ostream &OS)
Error extract(DWARFDataExtractor Data, uint64_t *OffsetPtr)
Extract an entire table, including all list entries.
void dump(DWARFDataExtractor Data, raw_ostream &OS, llvm::function_ref< std::optional< object::SectionedAddress >(uint32_t)> LookupPooledAddress, DIDumpOptions DumpOpts={}) const
bool dumpLocationList(uint64_t *Offset, raw_ostream &OS, std::optional< object::SectionedAddress > BaseAddr, const DWARFObject &Obj, DWARFUnit *U, DIDumpOptions DumpOpts, unsigned Indent) const
Dump the location list at the given Offset.
virtual StringRef getFileName() const
virtual StringRef getAbbrevDWOSection() const
virtual const DWARFSection & getFrameSection() const
virtual const DWARFSection & getNamesSection() const
virtual const DWARFSection & getAppleNamespacesSection() const
virtual StringRef getMacroDWOSection() const
virtual void forEachInfoDWOSections(function_ref< void(const DWARFSection &)> F) const
virtual const DWARFSection & getAppleTypesSection() const
virtual void forEachInfoSections(function_ref< void(const DWARFSection &)> F) const
virtual StringRef getMacinfoDWOSection() const
virtual const DWARFSection & getAppleNamesSection() const
virtual const DWARFSection & getEHFrameSection() const
virtual void forEachTypesSections(function_ref< void(const DWARFSection &)> F) const
virtual StringRef getMacinfoSection() const
virtual const DWARFSection & getLocSection() const
virtual const DWARFSection & getAppleObjCSection() const
virtual void forEachTypesDWOSections(function_ref< void(const DWARFSection &)> F) const
virtual const DWARFSection & getMacroSection() const
virtual StringRef getStrSection() const
virtual uint8_t getAddressSize() const
void setOffset(uint64_t Value)
uint64_t getOffset() const
void dump(raw_ostream &OS) const
Describe a collection of units.
void finishedInfoUnits()
Indicate that parsing .debug_info[.dwo] is done, and remaining units will be from ....
void addUnitsForSection(DWARFContext &C, const DWARFSection &Section, DWARFSectionKind SectionKind)
Read units from a .debug_info or .debug_types section.
void addUnitsForDWOSection(DWARFContext &C, const DWARFSection &DWOSection, DWARFSectionKind SectionKind, bool Lazy=false)
Read units from a .debug_info.dwo or .debug_types.dwo section.
DWARFUnit * getUnitForIndexEntry(const DWARFUnitIndex::Entry &E)
A class that verifies DWARF debug information given a DWARF Context.
bool handleAccelTables()
Verify the information in accelerator tables, if they exist.
bool handleDebugTUIndex()
Verify the information in the .debug_tu_index section.
bool handleDebugStrOffsets()
Verify the information in the .debug_str_offsets[.dwo].
bool handleDebugCUIndex()
Verify the information in the .debug_cu_index section.
bool handleDebugInfo()
Verify the information in the .debug_info and .debug_types sections.
bool handleDebugLine()
Verify the information in the .debug_line section.
bool handleDebugAbbrev()
Verify the information in any of the following sections, if available: .debug_abbrev,...
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
reference get()
Returns a reference to the stored T value.
An inferface for inquiring the load address of a loaded object file to be used by the DIContext imple...
This class implements a map that also provides access to all stored values in a deterministic order.
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
StringRef - Represent a constant reference to a string, i.e.
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
constexpr size_t size() const
size - Get the string size.
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.
A switch()-like statement whose cases are string literals.
StringSwitch & Case(StringLiteral S, T Value)
Triple - Helper class for working with autoconf configuration names.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static Twine utohexstr(const uint64_t &Val)
The instances of the Type class are immutable: once they are created, they are never changed.
static void defaultWarningHandler(Error Warning)
Implement default handling for Warning.
static void defaultErrorHandler(Error Err)
Implement default handling for Error.
An efficient, type-erasing, non-owning reference to a callable.
A range adaptor for a pair of iterators.
Decompressor helps to handle decompression of compressed sections.
Error resizeAndDecompress(T &Out)
Resize the buffer and uncompress section data into it.
static Expected< Decompressor > create(StringRef Name, StringRef Data, bool IsLE, bool Is64Bit)
Create decompressor object.
MachO::any_relocation_info getRelocation(DataRefImpl Rel) const
bool isRelocationScattered(const MachO::any_relocation_info &RE) const
This class is the base class for all object file types.
virtual section_iterator section_end() const =0
section_iterator_range sections() const
static Expected< OwningBinary< ObjectFile > > createObjectFile(StringRef ObjectPath)
virtual StringRef mapDebugSectionName(StringRef Name) const
Maps a debug section name to a standard DWARF section name.
virtual bool isRelocatableObject() const =0
True if this is a relocatable object (.o/.obj).
This is a value type class that represents a single relocation in the list of relocations in the obje...
symbol_iterator getSymbol() const
DataRefImpl getRawDataRefImpl() const
This is a value type class that represents a single section in the list of sections in the object fil...
uint64_t getIndex() const
bool isCompressed() const
uint64_t getAddress() const
Expected< StringRef > getName() const
virtual basic_symbol_iterator symbol_end() const =0
This class implements an extremely fast bulk output stream that can only output to a stream.
raw_ostream & write_uuid(const uuid_t UUID)
raw_ostream & write_escaped(StringRef Str, bool UseHexEscapes=false)
Output Str, turning '\', '\t', ' ', '"', and anything that doesn't satisfy llvm::isPrint into an esca...
uint8_t[16] uuid_t
Output a formatted UUID with dash separators.
StringRef FormatString(DwarfFormat Format)
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
std::optional< const char * > toString(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract a string value from it.
std::optional< object::SectionedAddress > toSectionedAddress(const std::optional< DWARFFormValue > &V)
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.
uint8_t getDwarfOffsetByteSize(DwarfFormat Format)
The size of a reference determined by the DWARF 32/64-bit format.
std::optional< uint64_t > toUnsigned(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an unsigned constant.
uint64_t(*)(uint64_t Type, uint64_t Offset, uint64_t S, uint64_t LocData, int64_t Addend) RelocationResolver
Error createError(const Twine &Err)
bool(*)(uint64_t) SupportsRelocation
std::pair< SupportsRelocation, RelocationResolver > getRelocationResolver(const ObjectFile &Obj)
StringRef extension(StringRef path, Style style=Style::native)
Get extension.
SmartMutex< false > Mutex
Mutex - A standard, always enforced mutex.
This is an optimization pass for GlobalISel generic memory operations.
void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner={})
Log all errors (if any) in E to OS.
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
int64_t decodeSLEB128(const uint8_t *p, unsigned *n=nullptr, const uint8_t *end=nullptr, const char **error=nullptr)
Utility function to decode a SLEB128 value.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
void sort(IteratorTy Start, IteratorTy End)
static Error createError(const Twine &Err)
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
DINameKind
A DINameKind is passed to name search methods to specify a preference regarding the type of name reso...
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
void consumeError(Error Err)
Consume a Error without doing anything.
Implement std::hash so that hash_code can be used in STL containers.
SymInfo contains information about symbol: it's address and section index which is -1LL for absolute ...
Container for dump options that control which debug information will be dumped.
std::function< void(Error)> WarningHandler
std::function< void(Error)> RecoverableErrorHandler
DIDumpOptions noImplicitRecursion() const
Return the options with RecurseDepth set to 0 unless explicitly required.
Controls which fields of DILineInfo container should be filled with data.
DINameKind FunctionNameKind
A format-neutral container for source line information.
static constexpr const char *const BadString
std::optional< uint64_t > StartAddress
std::string StartFileName
Wraps the returned DIEs for a given address.
bool getFileLineInfoForAddress(object::SectionedAddress Address, const char *CompDir, DILineInfoSpecifier::FileLineInfoKind Kind, DILineInfo &Result) const
Fills the Result argument with the file and line information corresponding to Address.
bool getFileNameByIndex(uint64_t FileIndex, StringRef CompDir, DILineInfoSpecifier::FileLineInfoKind Kind, std::string &Result) const
Extracts filename by its index in filename table in prologue.
bool lookupAddressRange(object::SectionedAddress Address, uint64_t Size, std::vector< uint32_t > &Result) const
Standard .debug_line state machine structure.
RelocAddrEntry contains relocated value and section index.
std::optional< object::RelocationRef > Reloc2