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()))
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()))
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);
254 std::optional<DenseMap<uint64_t, DWARFTypeUnit *>> NormalTypeUnits;
255 std::unique_ptr<DWARFUnitIndex> CUIndex;
256 std::unique_ptr<DWARFGdbIndex> GdbIndex;
257 std::unique_ptr<DWARFUnitIndex> TUIndex;
258 std::unique_ptr<DWARFDebugAbbrev> Abbrev;
259 std::unique_ptr<DWARFDebugLoc> Loc;
260 std::unique_ptr<DWARFDebugAranges> Aranges;
261 std::unique_ptr<DWARFDebugLine> Line;
263 std::unique_ptr<DWARFDebugFrame> EHFrame;
264 std::unique_ptr<DWARFDebugMacro>
Macro;
265 std::unique_ptr<DWARFDebugMacro> Macinfo;
266 std::unique_ptr<DWARFDebugNames> Names;
267 std::unique_ptr<AppleAcceleratorTable>
AppleNames;
268 std::unique_ptr<AppleAcceleratorTable>
AppleTypes;
270 std::unique_ptr<AppleAcceleratorTable>
AppleObjC;
272 std::optional<DenseMap<uint64_t, DWARFTypeUnit *>> DWOTypeUnits;
273 std::unique_ptr<DWARFDebugAbbrev> AbbrevDWO;
274 std::unique_ptr<DWARFDebugMacro> MacinfoDWO;
275 std::unique_ptr<DWARFDebugMacro> MacroDWO;
278 std::unique_ptr<DWARFContext> Context;
281 std::weak_ptr<DWOFile> DWP;
282 bool CheckedForDWP =
false;
286 ThreadUnsafeDWARFContextState(
DWARFContext &DC, std::string &DWP) :
291 if (NormalUnits.
empty()) {
305 if (DWOUnits.
empty()) {
321 return AbbrevDWO.get();
324 AbbrevDWO = std::make_unique<DWARFDebugAbbrev>(abbrData);
325 return AbbrevDWO.get();
333 D.isLittleEndian(), 0);
334 CUIndex = std::make_unique<DWARFUnitIndex>(DW_SECT_INFO);
335 if (CUIndex->parse(Data))
344 D.isLittleEndian(), 0);
346 bool isParseSuccessful = TUIndex->parse(Data);
349 if (isParseSuccessful && TUIndex->getVersion() != 2)
358 DataExtractor Data(
D.getDWARFObj().getGdbIndexSection(),
true , 0);
359 GdbIndex = std::make_unique<DWARFGdbIndex>();
360 GdbIndex->parse(Data);
369 D.isLittleEndian(), 0);
370 Abbrev = std::make_unique<DWARFDebugAbbrev>(Data);
381 D.getNumCompileUnits()
383 D.getUnitAtIndex(0)->getAddressByteSize())
385 Loc = std::make_unique<DWARFDebugLoc>(std::move(Data));
391 return Aranges.get();
393 Aranges = std::make_unique<DWARFDebugAranges>();
394 Aranges->generate(&
D);
395 return Aranges.get();
401 Line = std::make_unique<DWARFDebugLine>();
403 auto UnitDIE =
U->getUnitDIE();
417 if (stmtOffset >=
U->getLineSection().Data.size())
422 U->isLittleEndian(),
U->getAddressByteSize());
423 return Line->getOrParseLineTable(Data, stmtOffset,
U->getContext(), U,
424 RecoverableErrorHandler);
428 void clearLineTableForUnit(
DWARFUnit *U)
override {
432 auto UnitDIE =
U->getUnitDIE();
441 Line->clearLineTable(stmtOffset);
462 std::make_unique<DWARFDebugFrame>(
D.getArch(),
false,
473 return EHFrame.
get();
480 std::make_unique<DWARFDebugFrame>(
D.getArch(),
true,
485 return EHFrame.get();
490 Macinfo = parseMacroOrMacinfo(MacinfoSection);
491 return Macinfo.get();
495 MacinfoDWO = parseMacroOrMacinfo(MacinfoDwoSection);
496 return MacinfoDWO.get();
500 Macro = parseMacroOrMacinfo(MacroSection);
505 MacroDWO = parseMacroOrMacinfo(MacroDwoSection);
506 return MacroDWO.get();
538 std::shared_ptr<DWARFContext>
539 getDWOContext(
StringRef AbsolutePath)
override {
540 if (
auto S = DWP.lock()) {
542 return std::shared_ptr<DWARFContext>(std::move(S), Ctxt);
545 std::weak_ptr<DWOFile> *
Entry = &DWOFiles[AbsolutePath];
547 if (
auto S =
Entry->lock()) {
549 return std::shared_ptr<DWARFContext>(std::move(S), Ctxt);
555 if (!CheckedForDWP) {
558 this->DWPName.
empty()
559 ? (DObj.
getFileName() +
".dwp").toStringRef(DWPName)
565 CheckedForDWP =
true;
581 auto S = std::make_shared<DWOFile>();
582 S->File = std::move(Obj.
get());
585 bool ThreadSafe = isThreadSafe();
587 *S->File.getBinary(), DWARFContext::ProcessDebugRelocations::Ignore,
591 auto *Ctxt = S->Context.get();
592 return std::shared_ptr<DWARFContext>(std::move(S), Ctxt);
595 bool isThreadSafe()
const override {
return false; }
598 if (!NormalTypeUnits) {
599 NormalTypeUnits.emplace();
600 for (
const auto &U :
D.normal_units()) {
602 (*NormalTypeUnits)[TU->getTypeHash()] = TU;
605 return *NormalTypeUnits;
610 DWOTypeUnits.emplace();
611 for (
const auto &U :
D.dwo_units()) {
613 (*DWOTypeUnits)[TU->getTypeHash()] = TU;
616 return *DWOTypeUnits;
620 getTypeUnitMap(
bool IsDWO)
override {
622 return getDWOTypeUnitMap();
624 return getNormalTypeUnitMap();
630class ThreadSafeState :
public ThreadUnsafeDWARFContextState {
631 std::recursive_mutex
Mutex;
635 ThreadUnsafeDWARFContextState(DC, DWP) {}
638 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
639 return ThreadUnsafeDWARFContextState::getNormalUnits();
642 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
646 return ThreadUnsafeDWARFContextState::getDWOUnits(
false);
649 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
650 return ThreadUnsafeDWARFContextState::getCUIndex();
653 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
654 return ThreadUnsafeDWARFContextState::getDebugAbbrevDWO();
658 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
659 return ThreadUnsafeDWARFContextState::getTUIndex();
662 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
663 return ThreadUnsafeDWARFContextState::getGdbIndex();
666 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
667 return ThreadUnsafeDWARFContextState::getDebugAbbrev();
670 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
671 return ThreadUnsafeDWARFContextState::getDebugLoc();
674 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
675 return ThreadUnsafeDWARFContextState::getDebugAranges();
679 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
680 return ThreadUnsafeDWARFContextState::getLineTableForUnit(U, RecoverableErrorHandler);
682 void clearLineTableForUnit(
DWARFUnit *U)
override {
683 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
684 return ThreadUnsafeDWARFContextState::clearLineTableForUnit(U);
687 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
688 return ThreadUnsafeDWARFContextState::getDebugFrame();
691 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
692 return ThreadUnsafeDWARFContextState::getEHFrame();
695 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
696 return ThreadUnsafeDWARFContextState::getDebugMacinfo();
699 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
700 return ThreadUnsafeDWARFContextState::getDebugMacinfoDWO();
703 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
704 return ThreadUnsafeDWARFContextState::getDebugMacro();
707 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
708 return ThreadUnsafeDWARFContextState::getDebugMacroDWO();
711 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
712 return ThreadUnsafeDWARFContextState::getDebugNames();
715 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
716 return ThreadUnsafeDWARFContextState::getAppleNames();
719 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
720 return ThreadUnsafeDWARFContextState::getAppleTypes();
723 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
724 return ThreadUnsafeDWARFContextState::getAppleNamespaces();
727 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
728 return ThreadUnsafeDWARFContextState::getAppleObjC();
730 std::shared_ptr<DWARFContext>
731 getDWOContext(
StringRef AbsolutePath)
override {
732 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
733 return ThreadUnsafeDWARFContextState::getDWOContext(AbsolutePath);
736 bool isThreadSafe()
const override {
return true; }
739 getTypeUnitMap(
bool IsDWO)
override {
740 std::unique_lock<std::recursive_mutex> LockGuard(
Mutex);
741 return ThreadUnsafeDWARFContextState::getTypeUnitMap(IsDWO);
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();
812 [](
const std::optional<StrOffsetsContributionDescriptor> &L,
813 const std::optional<StrOffsetsContributionDescriptor> &R) {
815 return L->Base == R->Base && L->Size == R->Size;
818 Contributions.end());
819 return Contributions;
842 for (
auto &Contribution : Contributions) {
845 OS <<
"error: invalid contribution to string offsets table in section ."
853 uint64_t ContributionHeader = Contribution->Base;
862 if (
Offset > ContributionHeader) {
865 "overlapping contributions to string offsets table in section .%s.",
869 if (
Offset < ContributionHeader) {
871 OS << (ContributionHeader -
Offset) <<
"\n";
873 OS <<
format(
"0x%8.8" PRIx64
": ", ContributionHeader);
878 OS <<
"Contribution size = " << (Contribution->Size + (
Version < 5 ? 0 : 4))
880 <<
", Version = " <<
Version <<
"\n";
882 Offset = Contribution->Base;
883 unsigned EntrySize = Contribution->getDwarfOffsetByteSize();
884 while (
Offset - Contribution->Base < Contribution->Size) {
888 OS <<
format(
"%0*" PRIx64
" ", OffsetDumpWidth, StringOffset);
889 const char *S = StrData.
getCStr(&StringOffset);
896 if (
Offset < SectionSize) {
898 OS << (SectionSize -
Offset) <<
"\n";
916 Offset = TableOffset + *TableLength;
921 AddrTable.
dump(
OS, DumpOpts);
944 Rnglists.
dump(rnglistData,
OS, LookupPooledAddress, DumpOpts);
952 std::optional<uint64_t> DumpOffset) {
962 Header.dump(
Data,
OS, DumpOpts);
964 uint64_t EndOffset = Header.length() + Header.getHeaderOffset();
965 Data.setAddressSize(Header.getAddrSize());
968 if (DumpOffset >=
Offset && DumpOffset < EndOffset) {
971 nullptr, DumpOpts, 0);
991 std::array<std::optional<uint64_t>,
DIDT_ID_Count> DumpOffsets) {
995 bool IsDWO = (Extension ==
".dwo") || (Extension ==
".dwp");
998 const auto *ObjFile = DObj->getFile();
1005 bool Explicit = DumpType !=
DIDT_All && !IsDWO;
1006 bool ExplicitDWO = Explicit && IsDWO;
1007 auto shouldDump = [&](
bool Explicit,
const char *
Name,
unsigned ID,
1008 StringRef Section) -> std::optional<uint64_t> * {
1009 unsigned Mask = 1U <<
ID;
1010 bool Should = (DumpType & Mask) && (Explicit || !Section.empty());
1013 OS <<
"\n" <<
Name <<
" contents:\n";
1014 return &DumpOffsets[
ID];
1018 if (shouldDump(Explicit,
".debug_abbrev", DIDT_ID_DebugAbbrev,
1019 DObj->getAbbrevSection()))
1021 if (shouldDump(ExplicitDWO,
".debug_abbrev.dwo", DIDT_ID_DebugAbbrev,
1022 DObj->getAbbrevDWOSection()))
1026 OS <<
'\n' <<
Name <<
" contents:\n";
1027 if (
auto DumpOffset = DumpOffsets[DIDT_ID_DebugInfo])
1028 for (
const auto &U : Units) {
1029 U->getDIEForOffset(*DumpOffset)
1031 DWARFDie CUDie = U->getUnitDIE(
false);
1032 DWARFDie CUNonSkeletonDie = U->getNonSkeletonUnitDIE(
false);
1033 if (CUNonSkeletonDie && CUDie != CUNonSkeletonDie) {
1040 for (
const auto &U : Units)
1041 U->dump(
OS, DumpOpts);
1043 if ((DumpType & DIDT_DebugInfo)) {
1051 OS <<
'\n' <<
Name <<
" contents:\n";
1052 for (
const auto &U : Units)
1053 if (
auto DumpOffset = DumpOffsets[DIDT_ID_DebugTypes])
1054 U->getDIEForOffset(*DumpOffset)
1057 U->dump(
OS, DumpOpts);
1059 if ((DumpType & DIDT_DebugTypes)) {
1070 if (
const auto *Off = shouldDump(Explicit,
".debug_loc", DIDT_ID_DebugLoc,
1071 DObj->getLocSection().Data)) {
1074 if (
const auto *Off =
1075 shouldDump(Explicit,
".debug_loclists", DIDT_ID_DebugLoclists,
1076 DObj->getLoclistsSection().Data)) {
1081 if (
const auto *Off =
1082 shouldDump(ExplicitDWO,
".debug_loclists.dwo", DIDT_ID_DebugLoclists,
1083 DObj->getLoclistsDWOSection().Data)) {
1089 if (
const auto *Off =
1090 shouldDump(ExplicitDWO,
".debug_loc.dwo", DIDT_ID_DebugLoc,
1091 DObj->getLocDWOSection().Data)) {
1098 std::nullopt, *DObj,
nullptr,
1107 if (
const std::optional<uint64_t> *Off =
1108 shouldDump(Explicit,
".debug_frame", DIDT_ID_DebugFrame,
1109 DObj->getFrameSection().Data)) {
1111 (*DF)->dump(
OS, DumpOpts, *Off);
1113 RecoverableErrorHandler(
DF.takeError());
1116 if (
const std::optional<uint64_t> *Off =
1117 shouldDump(Explicit,
".eh_frame", DIDT_ID_DebugFrame,
1118 DObj->getEHFrameSection().Data)) {
1120 (*DF)->dump(
OS, DumpOpts, *Off);
1122 RecoverableErrorHandler(
DF.takeError());
1125 if (shouldDump(Explicit,
".debug_macro", DIDT_ID_DebugMacro,
1126 DObj->getMacroSection().Data)) {
1131 if (shouldDump(Explicit,
".debug_macro.dwo", DIDT_ID_DebugMacro,
1132 DObj->getMacroDWOSection())) {
1137 if (shouldDump(Explicit,
".debug_macinfo", DIDT_ID_DebugMacro,
1138 DObj->getMacinfoSection())) {
1143 if (shouldDump(Explicit,
".debug_macinfo.dwo", DIDT_ID_DebugMacro,
1144 DObj->getMacinfoDWOSection())) {
1146 MacinfoDWO->dump(
OS);
1149 if (shouldDump(Explicit,
".debug_aranges", DIDT_ID_DebugAranges,
1150 DObj->getArangesSection())) {
1158 RecoverableErrorHandler(std::move(E));
1167 std::optional<uint64_t> DumpOffset) {
1169 if (DumpOffset &&
Parser.getOffset() != *DumpOffset) {
1173 OS <<
"debug_line[" <<
format(
"0x%8.8" PRIx64,
Parser.getOffset())
1180 auto DumpStrSection = [&](
StringRef Section) {
1191 OS <<
format(
"0x%8.8" PRIx64
": \"", StrOffset);
1198 if (
const auto *Off = shouldDump(Explicit,
".debug_line", DIDT_ID_DebugLine,
1199 DObj->getLineSection().Data)) {
1203 DumpLineSection(
Parser, DumpOpts, *Off);
1206 if (
const auto *Off =
1207 shouldDump(ExplicitDWO,
".debug_line.dwo", DIDT_ID_DebugLine,
1208 DObj->getLineDWOSection().Data)) {
1212 DumpLineSection(
Parser, DumpOpts, *Off);
1215 if (shouldDump(Explicit,
".debug_cu_index", DIDT_ID_DebugCUIndex,
1216 DObj->getCUIndexSection())) {
1220 if (shouldDump(Explicit,
".debug_tu_index", DIDT_ID_DebugTUIndex,
1221 DObj->getTUIndexSection())) {
1225 if (shouldDump(Explicit,
".debug_str", DIDT_ID_DebugStr,
1226 DObj->getStrSection()))
1227 DumpStrSection(DObj->getStrSection());
1229 if (shouldDump(ExplicitDWO,
".debug_str.dwo", DIDT_ID_DebugStr,
1230 DObj->getStrDWOSection()))
1231 DumpStrSection(DObj->getStrDWOSection());
1233 if (shouldDump(Explicit,
".debug_line_str", DIDT_ID_DebugLineStr,
1234 DObj->getLineStrSection()))
1235 DumpStrSection(DObj->getLineStrSection());
1237 if (shouldDump(Explicit,
".debug_addr", DIDT_ID_DebugAddr,
1238 DObj->getAddrSection().Data)) {
1244 if (shouldDump(Explicit,
".debug_ranges", DIDT_ID_DebugRanges,
1245 DObj->getRangesSection().Data)) {
1252 if (
Error E = rangeList.
extract(rangesData, &offset)) {
1260 auto LookupPooledAddress =
1263 auto I = CUs.begin();
1265 return std::nullopt;
1266 return (*I)->getAddrOffsetSectionItem(
Index);
1269 if (shouldDump(Explicit,
".debug_rnglists", DIDT_ID_DebugRnglists,
1270 DObj->getRnglistsSection().Data)) {
1276 if (shouldDump(ExplicitDWO,
".debug_rnglists.dwo", DIDT_ID_DebugRnglists,
1277 DObj->getRnglistsDWOSection().Data)) {
1283 if (shouldDump(Explicit,
".debug_pubnames", DIDT_ID_DebugPubnames,
1284 DObj->getPubnamesSection().Data)) {
1290 if (shouldDump(Explicit,
".debug_pubtypes", DIDT_ID_DebugPubtypes,
1291 DObj->getPubtypesSection().Data)) {
1297 if (shouldDump(Explicit,
".debug_gnu_pubnames", DIDT_ID_DebugGnuPubnames,
1298 DObj->getGnuPubnamesSection().Data)) {
1304 if (shouldDump(Explicit,
".debug_gnu_pubtypes", DIDT_ID_DebugGnuPubtypes,
1305 DObj->getGnuPubtypesSection().Data)) {
1311 if (shouldDump(Explicit,
".debug_str_offsets", DIDT_ID_DebugStrOffsets,
1312 DObj->getStrOffsetsSection().Data))
1314 OS, DumpOpts,
"debug_str_offsets", *DObj, DObj->getStrOffsetsSection(),
1316 if (shouldDump(ExplicitDWO,
".debug_str_offsets.dwo", DIDT_ID_DebugStrOffsets,
1317 DObj->getStrOffsetsDWOSection().Data))
1319 DObj->getStrOffsetsDWOSection(),
1323 if (shouldDump(Explicit,
".gdb_index", DIDT_ID_GdbIndex,
1324 DObj->getGdbIndexSection())) {
1328 if (shouldDump(Explicit,
".apple_names", DIDT_ID_AppleNames,
1329 DObj->getAppleNamesSection().Data))
1332 if (shouldDump(Explicit,
".apple_types", DIDT_ID_AppleTypes,
1333 DObj->getAppleTypesSection().Data))
1336 if (shouldDump(Explicit,
".apple_namespaces", DIDT_ID_AppleNamespaces,
1337 DObj->getAppleNamespacesSection().Data))
1340 if (shouldDump(Explicit,
".apple_objc", DIDT_ID_AppleObjC,
1341 DObj->getAppleObjCSection().Data))
1343 if (shouldDump(Explicit,
".debug_names", DIDT_ID_DebugNames,
1344 DObj->getNamesSection().Data))
1352 if (
const auto *R = TUI.getFromHash(Hash))
1353 return dyn_cast_or_null<DWARFTypeUnit>(
1357 return State->getTypeUnitMap(IsDWO).lookup(Hash);
1364 if (
const auto *R = CUI.getFromHash(Hash))
1365 return dyn_cast_or_null<DWARFCompileUnit>(
1376 if (!DWOCU->getDWOId()) {
1377 if (std::optional<uint64_t> DWOId =
1378 toUnsigned(DWOCU->getUnitDIE().find(DW_AT_GNU_dwo_id)))
1379 DWOCU->setDWOId(*DWOId);
1384 if (DWOCU->getDWOId() == Hash)
1385 return dyn_cast<DWARFCompileUnit>(DWOCU.get());
1391 if (
auto *
CU = State->getNormalUnits().getUnitForOffset(
Offset))
1392 return CU->getDIEForOffset(
Offset);
1401 if (DumpOpts.
DumpType & DIDT_DebugCUIndex)
1403 if (DumpOpts.
DumpType & DIDT_DebugTUIndex)
1405 if (DumpOpts.
DumpType & DIDT_DebugInfo)
1407 if (DumpOpts.
DumpType & DIDT_DebugLine)
1409 if (DumpOpts.
DumpType & DIDT_DebugStrOffsets)
1417 return State->getCUIndex();
1421 return State->getTUIndex();
1425 return State->getGdbIndex();
1429 return State->getDebugAbbrev();
1433 return State->getDebugAbbrevDWO();
1437 return State->getDebugLoc();
1441 return State->getDebugAranges();
1445 return State->getDebugFrame();
1449 return State->getEHFrame();
1453 return State->getDebugMacro();
1457 return State->getDebugMacroDWO();
1461 return State->getDebugMacinfo();
1465 return State->getDebugMacinfoDWO();
1470 return State->getDebugNames();
1474 return State->getAppleNames();
1478 return State->getAppleTypes();
1482 return State->getAppleNamespaces();
1486 return State->getAppleObjC();
1493 if (!ExpectedLineTable) {
1494 WarningHandler(ExpectedLineTable.
takeError());
1497 return *ExpectedLineTable;
1502 return State->getLineTableForUnit(U, RecoverableErrorHandler);
1506 return State->clearLineTableForUnit(U);
1510 return State->getDWOUnits(Lazy);
1514 return State->getNormalUnits().getUnitForOffset(
Offset);
1542 if (
CU->getVariableForAddress(
Address)) {
1562 DWARFDie CUDwoDie =
CU->getNonSkeletonUnitDIE(
false);
1563 if (CheckDWO && CUDwoDie && CUDie != CUDwoDie) {
1566 dyn_cast_or_null<DWARFCompileUnit>(CUDwoDie.
getDwarfUnit());
1569 if (Result.FunctionDIE)
1570 Result.CompileUnit = CUDwo;
1578 Result.CompileUnit =
CU;
1579 Result.FunctionDIE =
CU->getSubroutineForAddress(
Address);
1582 std::vector<DWARFDie> Worklist;
1583 Worklist.push_back(Result.FunctionDIE);
1584 while (!Worklist.empty()) {
1586 Worklist.pop_back();
1591 if (
DIE.
getTag() == DW_TAG_lexical_block &&
1593 Result.BlockDIE =
DIE;
1608 std::string &FunctionName, std::string &StartFile,
uint32_t &StartLine,
1609 std::optional<uint64_t> &StartAddress) {
1614 CU->getInlinedChainForAddress(
Address, InlinedChain);
1615 if (InlinedChain.
empty())
1619 bool FoundResult =
false;
1620 const char *
Name =
nullptr;
1621 if (
Kind != FunctionNameKind::None && (
Name =
DIE.getSubroutineName(
Kind))) {
1622 FunctionName =
Name;
1625 std::string DeclFile =
DIE.getDeclFile(FileNameKind);
1626 if (!DeclFile.empty()) {
1627 StartFile = DeclFile;
1630 if (
auto DeclLineResult =
DIE.getDeclLine()) {
1631 StartLine = DeclLineResult;
1635 StartAddress = LowPcAddr->Address;
1639static std::optional<int64_t>
1641 std::optional<unsigned> FrameBaseReg) {
1642 if (!Expr.
empty() &&
1643 (Expr[0] == DW_OP_fbreg ||
1644 (FrameBaseReg && Expr[0] == DW_OP_breg0 + *FrameBaseReg))) {
1648 if (Expr.
size() == Count + 1)
1651 if (Expr.
size() == Count + 2 && Expr[Count + 1] == DW_OP_deref)
1655 return std::nullopt;
1659 DWARFDie Die, std::vector<DILocal> &Result) {
1660 if (Die.
getTag() == DW_TAG_variable ||
1661 Die.
getTag() == DW_TAG_formal_parameter) {
1666 std::optional<unsigned> FrameBaseReg;
1667 if (
auto FrameBase = Subprogram.
find(DW_AT_frame_base))
1669 if (!Expr->empty() && (*Expr)[0] >= DW_OP_reg0 &&
1670 (*Expr)[0] <= DW_OP_reg31) {
1671 FrameBaseReg = (*Expr)[0] - DW_OP_reg0;
1674 if (
Expected<std::vector<DWARFLocationExpression>> Loc =
1676 for (
const auto &Entry : *Loc) {
1677 if (std::optional<int64_t> FrameOffset =
1679 Local.FrameOffset = *FrameOffset;
1689 if (
auto TagOffsetAttr = Die.
find(DW_AT_LLVM_tag_offset))
1690 Local.TagOffset = TagOffsetAttr->getAsUnsignedConstant();
1695 if (
auto NameAttr = Die.
find(DW_AT_name))
1700 if (
auto DeclFileAttr = Die.
find(DW_AT_decl_file)) {
1701 if (
const auto *LT =
CU->getContext().getLineTableForUnit(
CU))
1702 LT->getFileNameByIndex(
1703 *DeclFileAttr->getAsUnsignedConstant(),
CU->getCompilationDir(),
1704 DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath,
1707 if (
auto DeclLineAttr = Die.
find(DW_AT_decl_line))
1708 Local.DeclLine = *DeclLineAttr->getAsUnsignedConstant();
1714 if (Die.
getTag() == DW_TAG_inlined_subroutine)
1717 Subprogram = Origin;
1719 for (
auto Child : Die)
1720 addLocalsForDie(
CU, Subprogram, Child, Result);
1725 std::vector<DILocal> Result;
1732 addLocalsForDie(
CU, Subprogram, Subprogram, Result);
1745 Result.StartFileName, Result.StartLine, Result.StartAddress);
1746 if (
Spec.FLIKind != FileLineInfoKind::None) {
1748 LineTable->getFileLineInfoForAddress(
1750 CU->getCompilationDir(),
Spec.FLIKind, Result);
1765 Result.FileName = Die.
getDeclFile(FileLineInfoKind::AbsoluteFilePath);
1780 std::string StartFileName;
1782 std::optional<uint64_t> StartAddress;
1784 Spec.FLIKind, FunctionName,
1785 StartFileName, StartLine, StartAddress);
1789 if (
Spec.FLIKind == FileLineInfoKind::None) {
1791 Result.FunctionName = FunctionName;
1792 Result.StartFileName = StartFileName;
1793 Result.StartLine = StartLine;
1794 Result.StartAddress = StartAddress;
1795 Lines.push_back(std::make_pair(
Address.Address, Result));
1802 std::vector<uint32_t> RowVector;
1808 for (
uint32_t RowIndex : RowVector) {
1813 Spec.FLIKind, Result.FileName);
1814 Result.FunctionName = FunctionName;
1815 Result.Line = Row.Line;
1816 Result.Column = Row.Column;
1817 Result.StartFileName = StartFileName;
1818 Result.StartLine = StartLine;
1819 Result.StartAddress = StartAddress;
1820 Lines.push_back(std::make_pair(Row.Address.Address, Result));
1833 return InliningInfo;
1837 CU->getInlinedChainForAddress(
Address.Address, InlinedChain);
1838 if (InlinedChain.
size() == 0) {
1841 if (
Spec.FLIKind != FileLineInfoKind::None) {
1846 {Address.Address, Address.SectionIndex},
Spec.ApproximateLine,
1847 CU->getCompilationDir(),
Spec.FLIKind, Frame))
1850 return InliningInfo;
1853 uint32_t CallFile = 0, CallLine = 0, CallColumn = 0, CallDiscriminator = 0;
1854 for (
uint32_t i = 0, n = InlinedChain.
size(); i != n; i++) {
1855 DWARFDie &FunctionDIE = InlinedChain[i];
1860 if (
auto DeclLineResult = FunctionDIE.
getDeclLine())
1865 if (
Spec.FLIKind != FileLineInfoKind::None) {
1874 CU->getCompilationDir(),
Spec.FLIKind, Frame);
1881 Frame.
Line = CallLine;
1882 Frame.
Column = CallColumn;
1893 return InliningInfo;
1896std::shared_ptr<DWARFContext>
1898 return State->getDWOContext(AbsolutePath);
1902 return make_error<StringError>(Reason +
toString(std::move(E)),
1918 std::map<SymbolRef, SymInfo> &Cache) {
1923 std::map<SymbolRef, SymInfo>::iterator CacheIt = Cache.end();
1928 std::tie(CacheIt, New) = Cache.insert({*
Sym, {0, 0}});
1930 return CacheIt->second;
1934 return createError(
"failed to compute symbol address: ",
1938 auto SectOrErr =
Sym->getSection();
1940 return createError(
"failed to get symbol section: ",
1941 SectOrErr.takeError());
1944 Ret.Address = *SymAddrOrErr;
1945 }
else if (
auto *MObj = dyn_cast<MachOObjectFile>(&Obj)) {
1951 Ret.SectionIndex = RSec->
getIndex();
1961 if (
uint64_t SectionLoadAddress = L->getSectionLoadAddress(*RSec))
1962 Ret.Address += SectionLoadAddress - RSec->
getAddress();
1964 if (CacheIt != Cache.end())
1965 CacheIt->second = Ret;
1986class DWARFObjInMemory final :
public DWARFObject {
1987 bool IsLittleEndian;
1988 uint8_t AddressSize;
1994 std::map<object::SectionRef, unsigned>>;
1996 InfoSectionMap InfoSections;
1997 InfoSectionMap TypesSections;
1998 InfoSectionMap InfoDWOSections;
1999 InfoSectionMap TypesDWOSections;
2001 DWARFSectionMap LocSection;
2002 DWARFSectionMap LoclistsSection;
2003 DWARFSectionMap LoclistsDWOSection;
2004 DWARFSectionMap LineSection;
2005 DWARFSectionMap RangesSection;
2006 DWARFSectionMap RnglistsSection;
2007 DWARFSectionMap StrOffsetsSection;
2008 DWARFSectionMap LineDWOSection;
2009 DWARFSectionMap FrameSection;
2010 DWARFSectionMap EHFrameSection;
2011 DWARFSectionMap LocDWOSection;
2012 DWARFSectionMap StrOffsetsDWOSection;
2013 DWARFSectionMap RangesDWOSection;
2014 DWARFSectionMap RnglistsDWOSection;
2015 DWARFSectionMap AddrSection;
2016 DWARFSectionMap AppleNamesSection;
2017 DWARFSectionMap AppleTypesSection;
2018 DWARFSectionMap AppleNamespacesSection;
2019 DWARFSectionMap AppleObjCSection;
2020 DWARFSectionMap NamesSection;
2021 DWARFSectionMap PubnamesSection;
2022 DWARFSectionMap PubtypesSection;
2023 DWARFSectionMap GnuPubnamesSection;
2024 DWARFSectionMap GnuPubtypesSection;
2025 DWARFSectionMap MacroSection;
2029 .
Case(
"debug_loc", &LocSection)
2030 .
Case(
"debug_loclists", &LoclistsSection)
2031 .
Case(
"debug_loclists.dwo", &LoclistsDWOSection)
2032 .
Case(
"debug_line", &LineSection)
2033 .
Case(
"debug_frame", &FrameSection)
2034 .
Case(
"eh_frame", &EHFrameSection)
2035 .
Case(
"debug_str_offsets", &StrOffsetsSection)
2036 .
Case(
"debug_ranges", &RangesSection)
2037 .
Case(
"debug_rnglists", &RnglistsSection)
2038 .
Case(
"debug_loc.dwo", &LocDWOSection)
2039 .
Case(
"debug_line.dwo", &LineDWOSection)
2040 .
Case(
"debug_names", &NamesSection)
2041 .
Case(
"debug_rnglists.dwo", &RnglistsDWOSection)
2042 .
Case(
"debug_str_offsets.dwo", &StrOffsetsDWOSection)
2043 .
Case(
"debug_addr", &AddrSection)
2044 .
Case(
"apple_names", &AppleNamesSection)
2045 .
Case(
"debug_pubnames", &PubnamesSection)
2046 .
Case(
"debug_pubtypes", &PubtypesSection)
2047 .
Case(
"debug_gnu_pubnames", &GnuPubnamesSection)
2048 .
Case(
"debug_gnu_pubtypes", &GnuPubtypesSection)
2049 .
Case(
"apple_types", &AppleTypesSection)
2050 .
Case(
"apple_namespaces", &AppleNamespacesSection)
2051 .
Case(
"apple_namespac", &AppleNamespacesSection)
2052 .
Case(
"apple_objc", &AppleObjCSection)
2053 .
Case(
"debug_macro", &MacroSection)
2072 std::deque<SmallString<0>> UncompressedSections;
2078 .
Case(
"debug_abbrev", &AbbrevSection)
2079 .
Case(
"debug_aranges", &ArangesSection)
2080 .
Case(
"debug_str", &StrSection)
2081 .
Case(
"debug_macinfo", &MacinfoSection)
2082 .
Case(
"debug_macinfo.dwo", &MacinfoDWOSection)
2083 .
Case(
"debug_macro.dwo", &MacroDWOSection)
2084 .
Case(
"debug_abbrev.dwo", &AbbrevDWOSection)
2085 .
Case(
"debug_str.dwo", &StrDWOSection)
2086 .
Case(
"debug_cu_index", &CUIndexSection)
2087 .
Case(
"debug_tu_index", &TUIndexSection)
2088 .
Case(
"gdb_index", &GdbIndexSection)
2089 .
Case(
"debug_line_str", &LineStrSection)
2110 UncompressedSections.push_back(std::move(Out));
2111 Data = UncompressedSections.back();
2117 DWARFObjInMemory(
const StringMap<std::unique_ptr<MemoryBuffer>> &Sections,
2118 uint8_t AddrSize,
bool IsLittleEndian)
2119 : IsLittleEndian(IsLittleEndian) {
2120 for (
const auto &SecIt : Sections) {
2121 if (
StringRef *SectionData = mapSectionToMember(SecIt.first()))
2122 *SectionData = SecIt.second->getBuffer();
2123 else if (SecIt.first() ==
"debug_info")
2126 InfoSections[
SectionRef()].Data = SecIt.second->getBuffer();
2127 else if (SecIt.first() ==
"debug_info.dwo")
2128 InfoDWOSections[
SectionRef()].Data = SecIt.second->getBuffer();
2129 else if (SecIt.first() ==
"debug_types")
2130 TypesSections[
SectionRef()].Data = SecIt.second->getBuffer();
2131 else if (SecIt.first() ==
"debug_types.dwo")
2132 TypesDWOSections[
SectionRef()].Data = SecIt.second->getBuffer();
2139 : IsLittleEndian(Obj.isLittleEndian()),
2140 AddressSize(Obj.getBytesInAddress()), FileName(Obj.
getFileName()),
2146 if (
auto NameOrErr =
Section.getName())
2151 ++SectionAmountMap[
Name];
2165 HandleError(
createError(
"failed to get relocated section: ",
2175 if (!L || !
L->getLoadedSectionContents(*RelocatedSection, Data)) {
2184 if (
auto Err = maybeDecompress(Section,
Name, Data)) {
2196 *SectionData = Data;
2197 if (
Name ==
"debug_ranges") {
2199 RangesDWOSection.Data = Data;
2200 }
else if (
Name ==
"debug_frame" ||
Name ==
"eh_frame") {
2204 }
else if (InfoSectionMap *Sections =
2206 .Case(
"debug_info", &InfoSections)
2207 .Case(
"debug_info.dwo", &InfoDWOSections)
2208 .Case(
"debug_types", &TypesSections)
2209 .Case(
"debug_types.dwo", &TypesDWOSections)
2213 DWARFSectionMap &S = (*Sections)[
Section];
2218 (RelocAction == DWARFContext::ProcessDebugRelocations::Ignore))
2222 if (
auto NameOrErr = RelocatedSection->
getName())
2223 RelSecName = *NameOrErr;
2231 if (L &&
L->getLoadedSectionContents(*RelocatedSection, RelSecData))
2239 if (!L && isa<MachOObjectFile>(&Obj))
2242 if (!
Section.relocations().empty() &&
Name.ends_with(
".dwo") &&
2244 HandleWarning(
createError(
"unexpected relocations for dwo section '" +
2251 DWARFSectionMap *Sec = mapNameToDWARFSection(RelSecName);
2256 if (RelSecName ==
"debug_info")
2257 Map = &
static_cast<DWARFSectionMap &
>(InfoSections[*RelocatedSection])
2259 else if (RelSecName ==
"debug_types")
2261 &
static_cast<DWARFSectionMap &
>(TypesSections[*RelocatedSection])
2271 std::map<SymbolRef, SymInfo> AddrCache;
2283 if (!SymInfoOrErr) {
2292 if (Supports && Supports(Reloc.getType())) {
2293 auto I =
Map->try_emplace(
2296 SymInfoOrErr->SectionIndex, Reloc, SymInfoOrErr->Address,
2297 std::optional<object::RelocationRef>(), 0, Resolver});
2305 "At most two relocations per offset are supported"));
2312 Reloc.getTypeName(
Type);
2322 if (SectionAmountMap[S.Name] > 1)
2323 S.IsNameUnique =
false;
2328 auto &Sec =
static_cast<const DWARFSectionMap &
>(S);
2330 if (AI == Sec.Relocs.end())
2331 return std::nullopt;
2341 bool isLittleEndian()
const override {
return IsLittleEndian; }
2342 StringRef getAbbrevDWOSection()
const override {
return AbbrevDWOSection; }
2343 const DWARFSection &getLineDWOSection()
const override {
2344 return LineDWOSection;
2346 const DWARFSection &getLocDWOSection()
const override {
2347 return LocDWOSection;
2349 StringRef getStrDWOSection()
const override {
return StrDWOSection; }
2350 const DWARFSection &getStrOffsetsDWOSection()
const override {
2351 return StrOffsetsDWOSection;
2353 const DWARFSection &getRangesDWOSection()
const override {
2354 return RangesDWOSection;
2356 const DWARFSection &getRnglistsDWOSection()
const override {
2357 return RnglistsDWOSection;
2359 const DWARFSection &getLoclistsDWOSection()
const override {
2360 return LoclistsDWOSection;
2362 const DWARFSection &getAddrSection()
const override {
return AddrSection; }
2363 StringRef getCUIndexSection()
const override {
return CUIndexSection; }
2364 StringRef getGdbIndexSection()
const override {
return GdbIndexSection; }
2365 StringRef getTUIndexSection()
const override {
return TUIndexSection; }
2368 const DWARFSection &getStrOffsetsSection()
const override {
2369 return StrOffsetsSection;
2371 StringRef getLineStrSection()
const override {
return LineStrSection; }
2374 void forEachInfoDWOSections(
2376 for (
auto &
P : InfoDWOSections)
2379 void forEachTypesDWOSections(
2381 for (
auto &
P : TypesDWOSections)
2385 StringRef getAbbrevSection()
const override {
return AbbrevSection; }
2386 const DWARFSection &getLocSection()
const override {
return LocSection; }
2387 const DWARFSection &getLoclistsSection()
const override {
return LoclistsSection; }
2388 StringRef getArangesSection()
const override {
return ArangesSection; }
2390 return FrameSection;
2392 const DWARFSection &getEHFrameSection()
const override {
2393 return EHFrameSection;
2395 const DWARFSection &getLineSection()
const override {
return LineSection; }
2396 StringRef getStrSection()
const override {
return StrSection; }
2397 const DWARFSection &getRangesSection()
const override {
return RangesSection; }
2398 const DWARFSection &getRnglistsSection()
const override {
2399 return RnglistsSection;
2401 const DWARFSection &getMacroSection()
const override {
return MacroSection; }
2402 StringRef getMacroDWOSection()
const override {
return MacroDWOSection; }
2403 StringRef getMacinfoSection()
const override {
return MacinfoSection; }
2404 StringRef getMacinfoDWOSection()
const override {
return MacinfoDWOSection; }
2405 const DWARFSection &getPubnamesSection()
const override {
return PubnamesSection; }
2406 const DWARFSection &getPubtypesSection()
const override {
return PubtypesSection; }
2407 const DWARFSection &getGnuPubnamesSection()
const override {
2408 return GnuPubnamesSection;
2410 const DWARFSection &getGnuPubtypesSection()
const override {
2411 return GnuPubtypesSection;
2413 const DWARFSection &getAppleNamesSection()
const override {
2414 return AppleNamesSection;
2416 const DWARFSection &getAppleTypesSection()
const override {
2417 return AppleTypesSection;
2419 const DWARFSection &getAppleNamespacesSection()
const override {
2420 return AppleNamespacesSection;
2422 const DWARFSection &getAppleObjCSection()
const override {
2423 return AppleObjCSection;
2426 return NamesSection;
2430 uint8_t getAddressSize()
const override {
return AddressSize; }
2431 void forEachInfoSections(
2433 for (
auto &
P : InfoSections)
2436 void forEachTypesSections(
2438 for (
auto &
P : TypesSections)
2444std::unique_ptr<DWARFContext>
2448 std::function<
void(
Error)> RecoverableErrorHandler,
2449 std::function<
void(
Error)> WarningHandler,
2451 auto DObj = std::make_unique<DWARFObjInMemory>(
2452 Obj, L, RecoverableErrorHandler, WarningHandler, RelocAction);
2453 return std::make_unique<DWARFContext>(std::move(DObj),
2455 RecoverableErrorHandler,
2460std::unique_ptr<DWARFContext>
2462 uint8_t AddrSize,
bool isLittleEndian,
2463 std::function<
void(
Error)> RecoverableErrorHandler,
2464 std::function<
void(
Error)> WarningHandler,
2467 std::make_unique<DWARFObjInMemory>(Sections, AddrSize,
isLittleEndian);
2468 return std::make_unique<DWARFContext>(
2469 std::move(DObj),
"", RecoverableErrorHandler, WarningHandler, ThreadSafe);
2479 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.
static DebugLoc getDebugLoc(MachineBasicBlock::instr_iterator FirstMI, MachineBasicBlock::instr_iterator LastMI)
Return the first found DebugLoc that has a DILocation, given a range of instructions.
This file implements a map that provides insertion order iteration.
while(!ToSimplify.empty())
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
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.
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.
DWARFUnit * getUnitForOffset(uint64_t Offset)
Return the DWARF unit that includes an offset (relative to .debug_info).
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.
DIEsForAddress getDIEsForAddress(uint64_t Address, bool CheckDWO=false)
Get the compilation unit, the function DIE and lexical block DIE for the given address where applicab...
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.
DWARFUnit * getDwarfUnit() const
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, unsigned indent=0, DIDumpOptions DumpOpts=DIDumpOptions()) const
Dump the DIE and all of its attributes to the supplied stream.
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)
DWARFDie getDIEForOffset(uint64_t Offset)
Return the DIE object for a given offset Offset inside the unit's DIE vector.
DWARFDie getSubroutineForAddress(uint64_t Address)
Returns subprogram DIE with address range encompassing the provided address.
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.
void summarize()
Emits any aggregate information collected, depending on the dump options.
bool handleDebugAbbrev()
Verify the information in any of the following sections, if available: .debug_abbrev,...
DILocation * get() const
Get the underlying DILocation.
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.
static constexpr StringLiteral SectionNames[SectionKindsNum]
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.
auto unique(Range &&R, Predicate P)
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, bool Approximate, 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