LLVM 18.0.0git
DWARFContext.cpp
Go to the documentation of this file.
1//===- DWARFContext.cpp ---------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10#include "llvm/ADT/MapVector.h"
11#include "llvm/ADT/STLExtras.h"
14#include "llvm/ADT/StringRef.h"
43#include "llvm/Object/MachO.h"
48#include "llvm/Support/Error.h"
49#include "llvm/Support/Format.h"
50#include "llvm/Support/LEB128.h"
53#include "llvm/Support/Path.h"
55#include <algorithm>
56#include <cstdint>
57#include <deque>
58#include <map>
59#include <string>
60#include <utility>
61#include <vector>
62
63using namespace llvm;
64using namespace dwarf;
65using namespace object;
66
67#define DEBUG_TYPE "dwarf"
68
72
73
76 using EntryMap = DenseMap<uint32_t, EntryType>;
77 EntryMap Map;
78 const auto &DObj = C.getDWARFObj();
79 if (DObj.getCUIndexSection().empty())
80 return;
81
82 uint64_t Offset = 0;
83 uint32_t TruncOffset = 0;
84 DObj.forEachInfoDWOSections([&](const DWARFSection &S) {
85 if (!(C.getParseCUTUIndexManually() ||
86 S.Data.size() >= std::numeric_limits<uint32_t>::max()))
87 return;
88
89 DWARFDataExtractor Data(DObj, S, C.isLittleEndian(), 0);
90 while (Data.isValidOffset(Offset)) {
91 DWARFUnitHeader Header;
92 if (!Header.extract(C, Data, &Offset, DWARFSectionKind::DW_SECT_INFO)) {
93 logAllUnhandledErrors(
94 createError("Failed to parse CU header in DWP file"), errs());
95 Map.clear();
96 break;
97 }
98
99 auto Iter = Map.insert({TruncOffset,
100 {Header.getOffset(), Header.getNextUnitOffset() -
101 Header.getOffset()}});
102 if (!Iter.second) {
103 logAllUnhandledErrors(
104 createError("Collision occured between for truncated offset 0x" +
105 Twine::utohexstr(TruncOffset)),
106 errs());
107 Map.clear();
108 return;
109 }
110
111 Offset = Header.getNextUnitOffset();
112 TruncOffset = Offset;
113 }
114 });
115
116 if (Map.empty())
117 return;
118
119 for (DWARFUnitIndex::Entry &E : Index.getMutableRows()) {
120 if (!E.isValid())
121 continue;
122 DWARFUnitIndex::Entry::SectionContribution &CUOff = E.getContribution();
123 auto Iter = Map.find(CUOff.getOffset());
124 if (Iter == Map.end()) {
125 logAllUnhandledErrors(createError("Could not find CU offset 0x" +
126 Twine::utohexstr(CUOff.getOffset()) +
127 " in the Map"),
128 errs());
129 break;
130 }
131 CUOff.setOffset(Iter->second.getOffset());
132 if (CUOff.getOffset() != Iter->second.getOffset())
133 logAllUnhandledErrors(createError("Length of CU in CU index doesn't "
134 "match calculated length at offset 0x" +
135 Twine::utohexstr(CUOff.getOffset())),
136 errs());
137 }
138}
139
142
143 const auto &DObj = C.getDWARFObj();
144 DObj.forEachInfoDWOSections([&](const DWARFSection &S) {
145 if (!(C.getParseCUTUIndexManually() ||
146 S.Data.size() >= std::numeric_limits<uint32_t>::max()))
147 return;
148 DWARFDataExtractor Data(DObj, S, C.isLittleEndian(), 0);
149 uint64_t Offset = 0;
150 while (Data.isValidOffset(Offset)) {
151 DWARFUnitHeader Header;
152 if (!Header.extract(C, Data, &Offset, DWARFSectionKind::DW_SECT_INFO)) {
153 logAllUnhandledErrors(
154 createError("Failed to parse unit header in DWP file"), errs());
155 break;
156 }
157 bool CU = Header.getUnitType() == DW_UT_split_compile;
158 uint64_t Sig = CU ? *Header.getDWOId() : Header.getTypeHash();
159 Map[Sig] = Header.getOffset();
160 Offset = Header.getNextUnitOffset();
161 }
162 });
163 if (Map.empty())
164 return;
165 for (DWARFUnitIndex::Entry &E : Index.getMutableRows()) {
166 if (!E.isValid())
167 continue;
168 DWARFUnitIndex::Entry::SectionContribution &CUOff = E.getContribution();
169 auto Iter = Map.find(E.getSignature());
170 if (Iter == Map.end()) {
172 createError("Could not find unit with signature 0x" +
173 Twine::utohexstr(E.getSignature()) + " in the Map"),
174 errs());
175 break;
176 }
177 CUOff.setOffset(Iter->second);
178 }
179}
180
182 if (Index.getVersion() < 5)
184 else
186}
187
188template <typename T>
189static T &getAccelTable(std::unique_ptr<T> &Cache, const DWARFObject &Obj,
190 const DWARFSection &Section, StringRef StringSection,
191 bool IsLittleEndian) {
192 if (Cache)
193 return *Cache;
194 DWARFDataExtractor AccelSection(Obj, Section, IsLittleEndian, 0);
195 DataExtractor StrData(StringSection, IsLittleEndian, 0);
196 Cache.reset(new T(AccelSection, StrData));
197 if (Error E = Cache->extract())
198 llvm::consumeError(std::move(E));
199 return *Cache;
200}
201
202
203std::unique_ptr<DWARFDebugMacro>
205 auto Macro = std::make_unique<DWARFDebugMacro>();
206 auto ParseAndDump = [&](DWARFDataExtractor &Data, bool IsMacro) {
207 if (Error Err = IsMacro ? Macro->parseMacro(SectionType == MacroSection
208 ? D.compile_units()
210 SectionType == MacroSection
213 Data)
214 : Macro->parseMacinfo(Data)) {
215 D.getRecoverableErrorHandler()(std::move(Err));
216 Macro = nullptr;
217 }
218 };
219 const DWARFObject &DObj = D.getDWARFObj();
220 switch (SectionType) {
221 case MacinfoSection: {
223 ParseAndDump(Data, /*IsMacro=*/false);
224 break;
225 }
226 case MacinfoDwoSection: {
228 ParseAndDump(Data, /*IsMacro=*/false);
229 break;
230 }
231 case MacroSection: {
233 0);
234 ParseAndDump(Data, /*IsMacro=*/true);
235 break;
236 }
237 case MacroDwoSection: {
239 ParseAndDump(Data, /*IsMacro=*/true);
240 break;
241 }
242 }
243 return Macro;
244}
245
247
248 DWARFUnitVector NormalUnits;
249 std::optional<DenseMap<uint64_t, DWARFTypeUnit *>> NormalTypeUnits;
250 std::unique_ptr<DWARFUnitIndex> CUIndex;
251 std::unique_ptr<DWARFGdbIndex> GdbIndex;
252 std::unique_ptr<DWARFUnitIndex> TUIndex;
253 std::unique_ptr<DWARFDebugAbbrev> Abbrev;
254 std::unique_ptr<DWARFDebugLoc> Loc;
255 std::unique_ptr<DWARFDebugAranges> Aranges;
256 std::unique_ptr<DWARFDebugLine> Line;
257 std::unique_ptr<DWARFDebugFrame> DebugFrame;
258 std::unique_ptr<DWARFDebugFrame> EHFrame;
259 std::unique_ptr<DWARFDebugMacro> Macro;
260 std::unique_ptr<DWARFDebugMacro> Macinfo;
261 std::unique_ptr<DWARFDebugNames> Names;
262 std::unique_ptr<AppleAcceleratorTable> AppleNames;
263 std::unique_ptr<AppleAcceleratorTable> AppleTypes;
264 std::unique_ptr<AppleAcceleratorTable> AppleNamespaces;
265 std::unique_ptr<AppleAcceleratorTable> AppleObjC;
266 DWARFUnitVector DWOUnits;
267 std::optional<DenseMap<uint64_t, DWARFTypeUnit *>> DWOTypeUnits;
268 std::unique_ptr<DWARFDebugAbbrev> AbbrevDWO;
269 std::unique_ptr<DWARFDebugMacro> MacinfoDWO;
270 std::unique_ptr<DWARFDebugMacro> MacroDWO;
271 struct DWOFile {
273 std::unique_ptr<DWARFContext> Context;
274 };
276 std::weak_ptr<DWOFile> DWP;
277 bool CheckedForDWP = false;
278 std::string DWPName;
279
280public:
282 DWARFContext::DWARFContextState(DC),
283 DWPName(std::move(DWP)) {}
284
286 if (NormalUnits.empty()) {
287 const DWARFObject &DObj = D.getDWARFObj();
288 DObj.forEachInfoSections([&](const DWARFSection &S) {
289 NormalUnits.addUnitsForSection(D, S, DW_SECT_INFO);
290 });
291 NormalUnits.finishedInfoUnits();
292 DObj.forEachTypesSections([&](const DWARFSection &S) {
293 NormalUnits.addUnitsForSection(D, S, DW_SECT_EXT_TYPES);
294 });
295 }
296 return NormalUnits;
297 }
298
299 DWARFUnitVector &getDWOUnits(bool Lazy) override {
300 if (DWOUnits.empty()) {
301 const DWARFObject &DObj = D.getDWARFObj();
302
303 DObj.forEachInfoDWOSections([&](const DWARFSection &S) {
304 DWOUnits.addUnitsForDWOSection(D, S, DW_SECT_INFO, Lazy);
305 });
306 DWOUnits.finishedInfoUnits();
307 DObj.forEachTypesDWOSections([&](const DWARFSection &S) {
308 DWOUnits.addUnitsForDWOSection(D, S, DW_SECT_EXT_TYPES, Lazy);
309 });
310 }
311 return DWOUnits;
312 }
313
315 if (AbbrevDWO)
316 return AbbrevDWO.get();
317 const DWARFObject &DObj = D.getDWARFObj();
318 DataExtractor abbrData(DObj.getAbbrevDWOSection(), D.isLittleEndian(), 0);
319 AbbrevDWO = std::make_unique<DWARFDebugAbbrev>(abbrData);
320 return AbbrevDWO.get();
321 }
322
323 const DWARFUnitIndex &getCUIndex() override {
324 if (CUIndex)
325 return *CUIndex;
326
327 DataExtractor Data(D.getDWARFObj().getCUIndexSection(),
328 D.isLittleEndian(), 0);
329 CUIndex = std::make_unique<DWARFUnitIndex>(DW_SECT_INFO);
330 if (CUIndex->parse(Data))
331 fixupIndex(D, *CUIndex);
332 return *CUIndex;
333 }
334 const DWARFUnitIndex &getTUIndex() override {
335 if (TUIndex)
336 return *TUIndex;
337
338 DataExtractor Data(D.getDWARFObj().getTUIndexSection(),
339 D.isLittleEndian(), 0);
340 TUIndex = std::make_unique<DWARFUnitIndex>(DW_SECT_EXT_TYPES);
341 bool isParseSuccessful = TUIndex->parse(Data);
342 // If we are parsing TU-index and for .debug_types section we don't need
343 // to do anything.
344 if (isParseSuccessful && TUIndex->getVersion() != 2)
345 fixupIndex(D, *TUIndex);
346 return *TUIndex;
347 }
348
350 if (GdbIndex)
351 return *GdbIndex;
352
353 DataExtractor Data(D.getDWARFObj().getGdbIndexSection(), true /*LE*/, 0);
354 GdbIndex = std::make_unique<DWARFGdbIndex>();
355 GdbIndex->parse(Data);
356 return *GdbIndex;
357 }
358
360 if (Abbrev)
361 return Abbrev.get();
362
363 DataExtractor Data(D.getDWARFObj().getAbbrevSection(),
364 D.isLittleEndian(), 0);
365 Abbrev = std::make_unique<DWARFDebugAbbrev>(Data);
366 return Abbrev.get();
367 }
368
369 const DWARFDebugLoc *getDebugLoc() override {
370 if (Loc)
371 return Loc.get();
372
373 const DWARFObject &DObj = D.getDWARFObj();
374 // Assume all units have the same address byte size.
375 auto Data =
376 D.getNumCompileUnits()
377 ? DWARFDataExtractor(DObj, DObj.getLocSection(), D.isLittleEndian(),
378 D.getUnitAtIndex(0)->getAddressByteSize())
379 : DWARFDataExtractor("", D.isLittleEndian(), 0);
380 Loc.reset(new DWARFDebugLoc(std::move(Data)));
381 return Loc.get();
382 }
383
385 if (Aranges)
386 return Aranges.get();
387
388 Aranges.reset(new DWARFDebugAranges());
389 Aranges->generate(&D);
390 return Aranges.get();
391 }
392
394 getLineTableForUnit(DWARFUnit *U, function_ref<void(Error)> RecoverableErrorHandler) override {
395 if (!Line)
396 Line.reset(new DWARFDebugLine);
397
398 auto UnitDIE = U->getUnitDIE();
399 if (!UnitDIE)
400 return nullptr;
401
402 auto Offset = toSectionOffset(UnitDIE.find(DW_AT_stmt_list));
403 if (!Offset)
404 return nullptr; // No line table for this compile unit.
405
406 uint64_t stmtOffset = *Offset + U->getLineTableOffset();
407 // See if the line table is cached.
408 if (const DWARFLineTable *lt = Line->getLineTable(stmtOffset))
409 return lt;
410
411 // Make sure the offset is good before we try to parse.
412 if (stmtOffset >= U->getLineSection().Data.size())
413 return nullptr;
414
415 // We have to parse it first.
416 DWARFDataExtractor Data(U->getContext().getDWARFObj(), U->getLineSection(),
417 U->isLittleEndian(), U->getAddressByteSize());
418 return Line->getOrParseLineTable(Data, stmtOffset, U->getContext(), U,
419 RecoverableErrorHandler);
420
421 }
422
424 if (!Line)
425 return;
426
427 auto UnitDIE = U->getUnitDIE();
428 if (!UnitDIE)
429 return;
430
431 auto Offset = toSectionOffset(UnitDIE.find(DW_AT_stmt_list));
432 if (!Offset)
433 return;
434
435 uint64_t stmtOffset = *Offset + U->getLineTableOffset();
436 Line->clearLineTable(stmtOffset);
437 }
438
440 if (DebugFrame)
441 return DebugFrame.get();
442 const DWARFObject &DObj = D.getDWARFObj();
443 const DWARFSection &DS = DObj.getFrameSection();
444
445 // There's a "bug" in the DWARFv3 standard with respect to the target address
446 // size within debug frame sections. While DWARF is supposed to be independent
447 // of its container, FDEs have fields with size being "target address size",
448 // which isn't specified in DWARF in general. It's only specified for CUs, but
449 // .eh_frame can appear without a .debug_info section. Follow the example of
450 // other tools (libdwarf) and extract this from the container (ObjectFile
451 // provides this information). This problem is fixed in DWARFv4
452 // See this dwarf-discuss discussion for more details:
453 // http://lists.dwarfstd.org/htdig.cgi/dwarf-discuss-dwarfstd.org/2011-December/001173.html
454 DWARFDataExtractor Data(DObj, DS, D.isLittleEndian(),
455 DObj.getAddressSize());
456 auto DF =
457 std::make_unique<DWARFDebugFrame>(D.getArch(), /*IsEH=*/false,
458 DS.Address);
459 if (Error E = DF->parse(Data))
460 return std::move(E);
461
462 DebugFrame.swap(DF);
463 return DebugFrame.get();
464 }
465
467 if (EHFrame)
468 return EHFrame.get();
469 const DWARFObject &DObj = D.getDWARFObj();
470
471 const DWARFSection &DS = DObj.getEHFrameSection();
472 DWARFDataExtractor Data(DObj, DS, D.isLittleEndian(),
473 DObj.getAddressSize());
474 auto DF =
475 std::make_unique<DWARFDebugFrame>(D.getArch(), /*IsEH=*/true,
476 DS.Address);
477 if (Error E = DF->parse(Data))
478 return std::move(E);
479 EHFrame.swap(DF);
480 return EHFrame.get();
481 }
482
484 if (!Macinfo)
485 Macinfo = parseMacroOrMacinfo(MacinfoSection);
486 return Macinfo.get();
487 }
489 if (!MacinfoDWO)
490 MacinfoDWO = parseMacroOrMacinfo(MacinfoDwoSection);
491 return MacinfoDWO.get();
492 }
493 const DWARFDebugMacro *getDebugMacro() override {
494 if (!Macro)
495 Macro = parseMacroOrMacinfo(MacroSection);
496 return Macro.get();
497 }
499 if (!MacroDWO)
500 MacroDWO = parseMacroOrMacinfo(MacroDwoSection);
501 return MacroDWO.get();
502 }
503 const DWARFDebugNames &getDebugNames() override {
504 const DWARFObject &DObj = D.getDWARFObj();
505 return getAccelTable(Names, DObj, DObj.getNamesSection(),
506 DObj.getStrSection(), D.isLittleEndian());
507 }
509 const DWARFObject &DObj = D.getDWARFObj();
510 return getAccelTable(AppleNames, DObj, DObj.getAppleNamesSection(),
511 DObj.getStrSection(), D.isLittleEndian());
512
513 }
515 const DWARFObject &DObj = D.getDWARFObj();
516 return getAccelTable(AppleTypes, DObj, DObj.getAppleTypesSection(),
517 DObj.getStrSection(), D.isLittleEndian());
518
519 }
521 const DWARFObject &DObj = D.getDWARFObj();
522 return getAccelTable(AppleNamespaces, DObj,
524 DObj.getStrSection(), D.isLittleEndian());
525
526 }
528 const DWARFObject &DObj = D.getDWARFObj();
529 return getAccelTable(AppleObjC, DObj, DObj.getAppleObjCSection(),
530 DObj.getStrSection(), D.isLittleEndian());
531 }
532
533 std::shared_ptr<DWARFContext>
534 getDWOContext(StringRef AbsolutePath) override {
535 if (auto S = DWP.lock()) {
536 DWARFContext *Ctxt = S->Context.get();
537 return std::shared_ptr<DWARFContext>(std::move(S), Ctxt);
538 }
539
540 std::weak_ptr<DWOFile> *Entry = &DWOFiles[AbsolutePath];
541
542 if (auto S = Entry->lock()) {
543 DWARFContext *Ctxt = S->Context.get();
544 return std::shared_ptr<DWARFContext>(std::move(S), Ctxt);
545 }
546
547 const DWARFObject &DObj = D.getDWARFObj();
548
550 if (!CheckedForDWP) {
551 SmallString<128> DWPName;
553 this->DWPName.empty()
554 ? (DObj.getFileName() + ".dwp").toStringRef(DWPName)
555 : StringRef(this->DWPName));
556 if (Obj) {
557 Entry = &DWP;
558 return Obj;
559 } else {
560 CheckedForDWP = true;
561 // TODO: Should this error be handled (maybe in a high verbosity mode)
562 // before falling back to .dwo files?
563 consumeError(Obj.takeError());
564 }
565 }
566
567 return object::ObjectFile::createObjectFile(AbsolutePath);
568 }();
569
570 if (!Obj) {
571 // TODO: Actually report errors helpfully.
572 consumeError(Obj.takeError());
573 return nullptr;
574 }
575
576 auto S = std::make_shared<DWOFile>();
577 S->File = std::move(Obj.get());
578 S->Context = DWARFContext::create(*S->File.getBinary(),
579 DWARFContext::ProcessDebugRelocations::Ignore);
580 *Entry = S;
581 auto *Ctxt = S->Context.get();
582 return std::shared_ptr<DWARFContext>(std::move(S), Ctxt);
583 }
584
586 if (!NormalTypeUnits) {
587 NormalTypeUnits.emplace();
588 for (const auto &U :D.normal_units()) {
589 if (DWARFTypeUnit *TU = dyn_cast<DWARFTypeUnit>(U.get()))
590 (*NormalTypeUnits)[TU->getTypeHash()] = TU;
591 }
592 }
593 return *NormalTypeUnits;
594 }
595
597 if (!DWOTypeUnits) {
598 DWOTypeUnits.emplace();
599 for (const auto &U :D.dwo_units()) {
600 if (DWARFTypeUnit *TU = dyn_cast<DWARFTypeUnit>(U.get()))
601 (*DWOTypeUnits)[TU->getTypeHash()] = TU;
602 }
603 }
604 return *DWOTypeUnits;
605 }
606
608 getTypeUnitMap(bool IsDWO) override {
609 if (IsDWO)
610 return getDWOTypeUnitMap();
611 else
612 return getNormalTypeUnitMap();
613 }
614
615
616};
617
619 std::recursive_mutex Mutex;
620
621public:
622 ThreadSafeState(DWARFContext &DC, std::string &DWP) :
624
626 std::unique_lock<std::recursive_mutex> LockGuard(Mutex);
628 }
629 DWARFUnitVector &getDWOUnits(bool Lazy) override {
630 std::unique_lock<std::recursive_mutex> LockGuard(Mutex);
632 }
633 const DWARFUnitIndex &getCUIndex() override {
634 std::unique_lock<std::recursive_mutex> LockGuard(Mutex);
636 }
638 std::unique_lock<std::recursive_mutex> LockGuard(Mutex);
640 }
641
642 const DWARFUnitIndex &getTUIndex() override {
643 std::unique_lock<std::recursive_mutex> LockGuard(Mutex);
645 }
647 std::unique_lock<std::recursive_mutex> LockGuard(Mutex);
649 }
651 std::unique_lock<std::recursive_mutex> LockGuard(Mutex);
653 }
654 const DWARFDebugLoc *getDebugLoc() override {
655 std::unique_lock<std::recursive_mutex> LockGuard(Mutex);
657 }
659 std::unique_lock<std::recursive_mutex> LockGuard(Mutex);
661 }
663 getLineTableForUnit(DWARFUnit *U, function_ref<void(Error)> RecoverableErrorHandler) override {
664 std::unique_lock<std::recursive_mutex> LockGuard(Mutex);
665 return ThreadUnsafeDWARFContextState::getLineTableForUnit(U, RecoverableErrorHandler);
666 }
668 std::unique_lock<std::recursive_mutex> LockGuard(Mutex);
670 }
672 std::unique_lock<std::recursive_mutex> LockGuard(Mutex);
674 }
676 std::unique_lock<std::recursive_mutex> LockGuard(Mutex);
678 }
680 std::unique_lock<std::recursive_mutex> LockGuard(Mutex);
682 }
684 std::unique_lock<std::recursive_mutex> LockGuard(Mutex);
686 }
687 const DWARFDebugMacro *getDebugMacro() override {
688 std::unique_lock<std::recursive_mutex> LockGuard(Mutex);
690 }
692 std::unique_lock<std::recursive_mutex> LockGuard(Mutex);
694 }
695 const DWARFDebugNames &getDebugNames() override {
696 std::unique_lock<std::recursive_mutex> LockGuard(Mutex);
698 }
700 std::unique_lock<std::recursive_mutex> LockGuard(Mutex);
702 }
704 std::unique_lock<std::recursive_mutex> LockGuard(Mutex);
706 }
708 std::unique_lock<std::recursive_mutex> LockGuard(Mutex);
710 }
712 std::unique_lock<std::recursive_mutex> LockGuard(Mutex);
714 }
715 std::shared_ptr<DWARFContext>
716 getDWOContext(StringRef AbsolutePath) override {
717 std::unique_lock<std::recursive_mutex> LockGuard(Mutex);
719 }
721 getTypeUnitMap(bool IsDWO) override {
722 std::unique_lock<std::recursive_mutex> LockGuard(Mutex);
724 }
725};
726
727
728
729DWARFContext::DWARFContext(std::unique_ptr<const DWARFObject> DObj,
730 std::string DWPName,
731 std::function<void(Error)> RecoverableErrorHandler,
732 std::function<void(Error)> WarningHandler,
733 bool ThreadSafe)
735 RecoverableErrorHandler(RecoverableErrorHandler),
736 WarningHandler(WarningHandler), DObj(std::move(DObj)) {
737 if (ThreadSafe)
738 State.reset(new ThreadSafeState(*this, DWPName));
739 else
740 State.reset(new ThreadUnsafeDWARFContextState(*this, DWPName));
741 }
742
744
745/// Dump the UUID load command.
746static void dumpUUID(raw_ostream &OS, const ObjectFile &Obj) {
747 auto *MachO = dyn_cast<MachOObjectFile>(&Obj);
748 if (!MachO)
749 return;
750 for (auto LC : MachO->load_commands()) {
752 if (LC.C.cmd == MachO::LC_UUID) {
753 if (LC.C.cmdsize < sizeof(UUID) + sizeof(LC.C)) {
754 OS << "error: UUID load command is too short.\n";
755 return;
756 }
757 OS << "UUID: ";
758 memcpy(&UUID, LC.Ptr+sizeof(LC.C), sizeof(UUID));
760 Triple T = MachO->getArchTriple();
761 OS << " (" << T.getArchName() << ')';
762 OS << ' ' << MachO->getFileName() << '\n';
763 }
764 }
765}
766
768 std::vector<std::optional<StrOffsetsContributionDescriptor>>;
769
770// Collect all the contributions to the string offsets table from all units,
771// sort them by their starting offsets and remove duplicates.
774 ContributionCollection Contributions;
775 for (const auto &U : Units)
776 if (const auto &C = U->getStringOffsetsTableContribution())
777 Contributions.push_back(C);
778 // Sort the contributions so that any invalid ones are placed at
779 // the start of the contributions vector. This way they are reported
780 // first.
781 llvm::sort(Contributions,
782 [](const std::optional<StrOffsetsContributionDescriptor> &L,
783 const std::optional<StrOffsetsContributionDescriptor> &R) {
784 if (L && R)
785 return L->Base < R->Base;
786 return R.has_value();
787 });
788
789 // Uniquify contributions, as it is possible that units (specifically
790 // type units in dwo or dwp files) share contributions. We don't want
791 // to report them more than once.
792 Contributions.erase(
793 std::unique(Contributions.begin(), Contributions.end(),
794 [](const std::optional<StrOffsetsContributionDescriptor> &L,
795 const std::optional<StrOffsetsContributionDescriptor> &R) {
796 if (L && R)
797 return L->Base == R->Base && L->Size == R->Size;
798 return false;
799 }),
800 Contributions.end());
801 return Contributions;
802}
803
804// Dump a DWARF string offsets section. This may be a DWARF v5 formatted
805// string offsets section, where each compile or type unit contributes a
806// number of entries (string offsets), with each contribution preceded by
807// a header containing size and version number. Alternatively, it may be a
808// monolithic series of string offsets, as generated by the pre-DWARF v5
809// implementation of split DWARF; however, in that case we still need to
810// collect contributions of units because the size of the offsets (4 or 8
811// bytes) depends on the format of the referencing unit (DWARF32 or DWARF64).
814 const DWARFObject &Obj,
815 const DWARFSection &StringOffsetsSection,
816 StringRef StringSection,
818 bool LittleEndian) {
819 auto Contributions = collectContributionData(Units);
820 DWARFDataExtractor StrOffsetExt(Obj, StringOffsetsSection, LittleEndian, 0);
821 DataExtractor StrData(StringSection, LittleEndian, 0);
822 uint64_t SectionSize = StringOffsetsSection.Data.size();
823 uint64_t Offset = 0;
824 for (auto &Contribution : Contributions) {
825 // Report an ill-formed contribution.
826 if (!Contribution) {
827 OS << "error: invalid contribution to string offsets table in section ."
828 << SectionName << ".\n";
829 return;
830 }
831
832 dwarf::DwarfFormat Format = Contribution->getFormat();
833 int OffsetDumpWidth = 2 * dwarf::getDwarfOffsetByteSize(Format);
834 uint16_t Version = Contribution->getVersion();
835 uint64_t ContributionHeader = Contribution->Base;
836 // In DWARF v5 there is a contribution header that immediately precedes
837 // the string offsets base (the location we have previously retrieved from
838 // the CU DIE's DW_AT_str_offsets attribute). The header is located either
839 // 8 or 16 bytes before the base, depending on the contribution's format.
840 if (Version >= 5)
841 ContributionHeader -= Format == DWARF32 ? 8 : 16;
842
843 // Detect overlapping contributions.
844 if (Offset > ContributionHeader) {
847 "overlapping contributions to string offsets table in section .%s.",
848 SectionName.data()));
849 }
850 // Report a gap in the table.
851 if (Offset < ContributionHeader) {
852 OS << format("0x%8.8" PRIx64 ": Gap, length = ", Offset);
853 OS << (ContributionHeader - Offset) << "\n";
854 }
855 OS << format("0x%8.8" PRIx64 ": ", ContributionHeader);
856 // In DWARF v5 the contribution size in the descriptor does not equal
857 // the originally encoded length (it does not contain the length of the
858 // version field and the padding, a total of 4 bytes). Add them back in
859 // for reporting.
860 OS << "Contribution size = " << (Contribution->Size + (Version < 5 ? 0 : 4))
861 << ", Format = " << dwarf::FormatString(Format)
862 << ", Version = " << Version << "\n";
863
864 Offset = Contribution->Base;
865 unsigned EntrySize = Contribution->getDwarfOffsetByteSize();
866 while (Offset - Contribution->Base < Contribution->Size) {
867 OS << format("0x%8.8" PRIx64 ": ", Offset);
868 uint64_t StringOffset =
869 StrOffsetExt.getRelocatedValue(EntrySize, &Offset);
870 OS << format("%0*" PRIx64 " ", OffsetDumpWidth, StringOffset);
871 const char *S = StrData.getCStr(&StringOffset);
872 if (S)
873 OS << format("\"%s\"", S);
874 OS << "\n";
875 }
876 }
877 // Report a gap at the end of the table.
878 if (Offset < SectionSize) {
879 OS << format("0x%8.8" PRIx64 ": Gap, length = ", Offset);
880 OS << (SectionSize - Offset) << "\n";
881 }
882}
883
884// Dump the .debug_addr section.
886 DIDumpOptions DumpOpts, uint16_t Version,
887 uint8_t AddrSize) {
888 uint64_t Offset = 0;
889 while (AddrData.isValidOffset(Offset)) {
890 DWARFDebugAddrTable AddrTable;
891 uint64_t TableOffset = Offset;
892 if (Error Err = AddrTable.extract(AddrData, &Offset, Version, AddrSize,
893 DumpOpts.WarningHandler)) {
894 DumpOpts.RecoverableErrorHandler(std::move(Err));
895 // Keep going after an error, if we can, assuming that the length field
896 // could be read. If it couldn't, stop reading the section.
897 if (auto TableLength = AddrTable.getFullLength()) {
898 Offset = TableOffset + *TableLength;
899 continue;
900 }
901 break;
902 }
903 AddrTable.dump(OS, DumpOpts);
904 }
905}
906
907// Dump the .debug_rnglists or .debug_rnglists.dwo section (DWARF v5).
909 raw_ostream &OS, DWARFDataExtractor &rnglistData,
910 llvm::function_ref<std::optional<object::SectionedAddress>(uint32_t)>
911 LookupPooledAddress,
912 DIDumpOptions DumpOpts) {
913 uint64_t Offset = 0;
914 while (rnglistData.isValidOffset(Offset)) {
916 uint64_t TableOffset = Offset;
917 if (Error Err = Rnglists.extract(rnglistData, &Offset)) {
918 DumpOpts.RecoverableErrorHandler(std::move(Err));
919 uint64_t Length = Rnglists.length();
920 // Keep going after an error, if we can, assuming that the length field
921 // could be read. If it couldn't, stop reading the section.
922 if (Length == 0)
923 break;
924 Offset = TableOffset + Length;
925 } else {
926 Rnglists.dump(rnglistData, OS, LookupPooledAddress, DumpOpts);
927 }
928 }
929}
930
931
934 std::optional<uint64_t> DumpOffset) {
935 uint64_t Offset = 0;
936
937 while (Data.isValidOffset(Offset)) {
938 DWARFListTableHeader Header(".debug_loclists", "locations");
939 if (Error E = Header.extract(Data, &Offset)) {
940 DumpOpts.RecoverableErrorHandler(std::move(E));
941 return;
942 }
943
944 Header.dump(Data, OS, DumpOpts);
945
946 uint64_t EndOffset = Header.length() + Header.getHeaderOffset();
947 Data.setAddressSize(Header.getAddrSize());
948 DWARFDebugLoclists Loc(Data, Header.getVersion());
949 if (DumpOffset) {
950 if (DumpOffset >= Offset && DumpOffset < EndOffset) {
951 Offset = *DumpOffset;
952 Loc.dumpLocationList(&Offset, OS, /*BaseAddr=*/std::nullopt, Obj,
953 nullptr, DumpOpts, /*Indent=*/0);
954 OS << "\n";
955 return;
956 }
957 } else {
958 Loc.dumpRange(Offset, EndOffset - Offset, OS, Obj, DumpOpts);
959 }
960 Offset = EndOffset;
961 }
962}
963
965 DWARFDataExtractor Data, bool GnuStyle) {
966 DWARFDebugPubTable Table;
967 Table.extract(Data, GnuStyle, DumpOpts.RecoverableErrorHandler);
968 Table.dump(OS);
969}
970
972 raw_ostream &OS, DIDumpOptions DumpOpts,
973 std::array<std::optional<uint64_t>, DIDT_ID_Count> DumpOffsets) {
974 uint64_t DumpType = DumpOpts.DumpType;
975
976 StringRef Extension = sys::path::extension(DObj->getFileName());
977 bool IsDWO = (Extension == ".dwo") || (Extension == ".dwp");
978
979 // Print UUID header.
980 const auto *ObjFile = DObj->getFile();
981 if (DumpType & DIDT_UUID)
982 dumpUUID(OS, *ObjFile);
983
984 // Print a header for each explicitly-requested section.
985 // Otherwise just print one for non-empty sections.
986 // Only print empty .dwo section headers when dumping a .dwo file.
987 bool Explicit = DumpType != DIDT_All && !IsDWO;
988 bool ExplicitDWO = Explicit && IsDWO;
989 auto shouldDump = [&](bool Explicit, const char *Name, unsigned ID,
990 StringRef Section) -> std::optional<uint64_t> * {
991 unsigned Mask = 1U << ID;
992 bool Should = (DumpType & Mask) && (Explicit || !Section.empty());
993 if (!Should)
994 return nullptr;
995 OS << "\n" << Name << " contents:\n";
996 return &DumpOffsets[ID];
997 };
998
999 // Dump individual sections.
1000 if (shouldDump(Explicit, ".debug_abbrev", DIDT_ID_DebugAbbrev,
1001 DObj->getAbbrevSection()))
1003 if (shouldDump(ExplicitDWO, ".debug_abbrev.dwo", DIDT_ID_DebugAbbrev,
1004 DObj->getAbbrevDWOSection()))
1006
1007 auto dumpDebugInfo = [&](const char *Name, unit_iterator_range Units) {
1008 OS << '\n' << Name << " contents:\n";
1009 if (auto DumpOffset = DumpOffsets[DIDT_ID_DebugInfo])
1010 for (const auto &U : Units)
1011 U->getDIEForOffset(*DumpOffset)
1012 .dump(OS, 0, DumpOpts.noImplicitRecursion());
1013 else
1014 for (const auto &U : Units)
1015 U->dump(OS, DumpOpts);
1016 };
1017 if ((DumpType & DIDT_DebugInfo)) {
1018 if (Explicit || getNumCompileUnits())
1019 dumpDebugInfo(".debug_info", info_section_units());
1020 if (ExplicitDWO || getNumDWOCompileUnits())
1021 dumpDebugInfo(".debug_info.dwo", dwo_info_section_units());
1022 }
1023
1024 auto dumpDebugType = [&](const char *Name, unit_iterator_range Units) {
1025 OS << '\n' << Name << " contents:\n";
1026 for (const auto &U : Units)
1027 if (auto DumpOffset = DumpOffsets[DIDT_ID_DebugTypes])
1028 U->getDIEForOffset(*DumpOffset)
1029 .dump(OS, 0, DumpOpts.noImplicitRecursion());
1030 else
1031 U->dump(OS, DumpOpts);
1032 };
1033 if ((DumpType & DIDT_DebugTypes)) {
1034 if (Explicit || getNumTypeUnits())
1035 dumpDebugType(".debug_types", types_section_units());
1036 if (ExplicitDWO || getNumDWOTypeUnits())
1037 dumpDebugType(".debug_types.dwo", dwo_types_section_units());
1038 }
1039
1040 DIDumpOptions LLDumpOpts = DumpOpts;
1041 if (LLDumpOpts.Verbose)
1042 LLDumpOpts.DisplayRawContents = true;
1043
1044 if (const auto *Off = shouldDump(Explicit, ".debug_loc", DIDT_ID_DebugLoc,
1045 DObj->getLocSection().Data)) {
1046 getDebugLoc()->dump(OS, *DObj, LLDumpOpts, *Off);
1047 }
1048 if (const auto *Off =
1049 shouldDump(Explicit, ".debug_loclists", DIDT_ID_DebugLoclists,
1050 DObj->getLoclistsSection().Data)) {
1051 DWARFDataExtractor Data(*DObj, DObj->getLoclistsSection(), isLittleEndian(),
1052 0);
1053 dumpLoclistsSection(OS, LLDumpOpts, Data, *DObj, *Off);
1054 }
1055 if (const auto *Off =
1056 shouldDump(ExplicitDWO, ".debug_loclists.dwo", DIDT_ID_DebugLoclists,
1057 DObj->getLoclistsDWOSection().Data)) {
1058 DWARFDataExtractor Data(*DObj, DObj->getLoclistsDWOSection(),
1059 isLittleEndian(), 0);
1060 dumpLoclistsSection(OS, LLDumpOpts, Data, *DObj, *Off);
1061 }
1062
1063 if (const auto *Off =
1064 shouldDump(ExplicitDWO, ".debug_loc.dwo", DIDT_ID_DebugLoc,
1065 DObj->getLocDWOSection().Data)) {
1066 DWARFDataExtractor Data(*DObj, DObj->getLocDWOSection(), isLittleEndian(),
1067 4);
1068 DWARFDebugLoclists Loc(Data, /*Version=*/4);
1069 if (*Off) {
1070 uint64_t Offset = **Off;
1072 /*BaseAddr=*/std::nullopt, *DObj, nullptr,
1073 LLDumpOpts,
1074 /*Indent=*/0);
1075 OS << "\n";
1076 } else {
1077 Loc.dumpRange(0, Data.getData().size(), OS, *DObj, LLDumpOpts);
1078 }
1079 }
1080
1081 if (const std::optional<uint64_t> *Off =
1082 shouldDump(Explicit, ".debug_frame", DIDT_ID_DebugFrame,
1083 DObj->getFrameSection().Data)) {
1085 (*DF)->dump(OS, DumpOpts, *Off);
1086 else
1087 RecoverableErrorHandler(DF.takeError());
1088 }
1089
1090 if (const std::optional<uint64_t> *Off =
1091 shouldDump(Explicit, ".eh_frame", DIDT_ID_DebugFrame,
1092 DObj->getEHFrameSection().Data)) {
1094 (*DF)->dump(OS, DumpOpts, *Off);
1095 else
1096 RecoverableErrorHandler(DF.takeError());
1097 }
1098
1099 if (shouldDump(Explicit, ".debug_macro", DIDT_ID_DebugMacro,
1100 DObj->getMacroSection().Data)) {
1101 if (auto Macro = getDebugMacro())
1102 Macro->dump(OS);
1103 }
1104
1105 if (shouldDump(Explicit, ".debug_macro.dwo", DIDT_ID_DebugMacro,
1106 DObj->getMacroDWOSection())) {
1107 if (auto MacroDWO = getDebugMacroDWO())
1108 MacroDWO->dump(OS);
1109 }
1110
1111 if (shouldDump(Explicit, ".debug_macinfo", DIDT_ID_DebugMacro,
1112 DObj->getMacinfoSection())) {
1113 if (auto Macinfo = getDebugMacinfo())
1114 Macinfo->dump(OS);
1115 }
1116
1117 if (shouldDump(Explicit, ".debug_macinfo.dwo", DIDT_ID_DebugMacro,
1118 DObj->getMacinfoDWOSection())) {
1119 if (auto MacinfoDWO = getDebugMacinfoDWO())
1120 MacinfoDWO->dump(OS);
1121 }
1122
1123 if (shouldDump(Explicit, ".debug_aranges", DIDT_ID_DebugAranges,
1124 DObj->getArangesSection())) {
1125 uint64_t offset = 0;
1126 DWARFDataExtractor arangesData(DObj->getArangesSection(), isLittleEndian(),
1127 0);
1129 while (arangesData.isValidOffset(offset)) {
1130 if (Error E =
1131 set.extract(arangesData, &offset, DumpOpts.WarningHandler)) {
1132 RecoverableErrorHandler(std::move(E));
1133 break;
1134 }
1135 set.dump(OS);
1136 }
1137 }
1138
1139 auto DumpLineSection = [&](DWARFDebugLine::SectionParser Parser,
1140 DIDumpOptions DumpOpts,
1141 std::optional<uint64_t> DumpOffset) {
1142 while (!Parser.done()) {
1143 if (DumpOffset && Parser.getOffset() != *DumpOffset) {
1144 Parser.skip(DumpOpts.WarningHandler, DumpOpts.WarningHandler);
1145 continue;
1146 }
1147 OS << "debug_line[" << format("0x%8.8" PRIx64, Parser.getOffset())
1148 << "]\n";
1149 Parser.parseNext(DumpOpts.WarningHandler, DumpOpts.WarningHandler, &OS,
1150 DumpOpts.Verbose);
1151 }
1152 };
1153
1154 auto DumpStrSection = [&](StringRef Section) {
1155 DataExtractor StrData(Section, isLittleEndian(), 0);
1156 uint64_t Offset = 0;
1157 uint64_t StrOffset = 0;
1158 while (StrData.isValidOffset(Offset)) {
1159 Error Err = Error::success();
1160 const char *CStr = StrData.getCStr(&Offset, &Err);
1161 if (Err) {
1162 DumpOpts.WarningHandler(std::move(Err));
1163 return;
1164 }
1165 OS << format("0x%8.8" PRIx64 ": \"", StrOffset);
1166 OS.write_escaped(CStr);
1167 OS << "\"\n";
1168 StrOffset = Offset;
1169 }
1170 };
1171
1172 if (const auto *Off = shouldDump(Explicit, ".debug_line", DIDT_ID_DebugLine,
1173 DObj->getLineSection().Data)) {
1174 DWARFDataExtractor LineData(*DObj, DObj->getLineSection(), isLittleEndian(),
1175 0);
1177 DumpLineSection(Parser, DumpOpts, *Off);
1178 }
1179
1180 if (const auto *Off =
1181 shouldDump(ExplicitDWO, ".debug_line.dwo", DIDT_ID_DebugLine,
1182 DObj->getLineDWOSection().Data)) {
1183 DWARFDataExtractor LineData(*DObj, DObj->getLineDWOSection(),
1184 isLittleEndian(), 0);
1186 DumpLineSection(Parser, DumpOpts, *Off);
1187 }
1188
1189 if (shouldDump(Explicit, ".debug_cu_index", DIDT_ID_DebugCUIndex,
1190 DObj->getCUIndexSection())) {
1191 getCUIndex().dump(OS);
1192 }
1193
1194 if (shouldDump(Explicit, ".debug_tu_index", DIDT_ID_DebugTUIndex,
1195 DObj->getTUIndexSection())) {
1196 getTUIndex().dump(OS);
1197 }
1198
1199 if (shouldDump(Explicit, ".debug_str", DIDT_ID_DebugStr,
1200 DObj->getStrSection()))
1201 DumpStrSection(DObj->getStrSection());
1202
1203 if (shouldDump(ExplicitDWO, ".debug_str.dwo", DIDT_ID_DebugStr,
1204 DObj->getStrDWOSection()))
1205 DumpStrSection(DObj->getStrDWOSection());
1206
1207 if (shouldDump(Explicit, ".debug_line_str", DIDT_ID_DebugLineStr,
1208 DObj->getLineStrSection()))
1209 DumpStrSection(DObj->getLineStrSection());
1210
1211 if (shouldDump(Explicit, ".debug_addr", DIDT_ID_DebugAddr,
1212 DObj->getAddrSection().Data)) {
1213 DWARFDataExtractor AddrData(*DObj, DObj->getAddrSection(),
1214 isLittleEndian(), 0);
1215 dumpAddrSection(OS, AddrData, DumpOpts, getMaxVersion(), getCUAddrSize());
1216 }
1217
1218 if (shouldDump(Explicit, ".debug_ranges", DIDT_ID_DebugRanges,
1219 DObj->getRangesSection().Data)) {
1220 uint8_t savedAddressByteSize = getCUAddrSize();
1221 DWARFDataExtractor rangesData(*DObj, DObj->getRangesSection(),
1222 isLittleEndian(), savedAddressByteSize);
1223 uint64_t offset = 0;
1224 DWARFDebugRangeList rangeList;
1225 while (rangesData.isValidOffset(offset)) {
1226 if (Error E = rangeList.extract(rangesData, &offset)) {
1227 DumpOpts.RecoverableErrorHandler(std::move(E));
1228 break;
1229 }
1230 rangeList.dump(OS);
1231 }
1232 }
1233
1234 auto LookupPooledAddress =
1235 [&](uint32_t Index) -> std::optional<SectionedAddress> {
1236 const auto &CUs = compile_units();
1237 auto I = CUs.begin();
1238 if (I == CUs.end())
1239 return std::nullopt;
1240 return (*I)->getAddrOffsetSectionItem(Index);
1241 };
1242
1243 if (shouldDump(Explicit, ".debug_rnglists", DIDT_ID_DebugRnglists,
1244 DObj->getRnglistsSection().Data)) {
1245 DWARFDataExtractor RnglistData(*DObj, DObj->getRnglistsSection(),
1246 isLittleEndian(), 0);
1247 dumpRnglistsSection(OS, RnglistData, LookupPooledAddress, DumpOpts);
1248 }
1249
1250 if (shouldDump(ExplicitDWO, ".debug_rnglists.dwo", DIDT_ID_DebugRnglists,
1251 DObj->getRnglistsDWOSection().Data)) {
1252 DWARFDataExtractor RnglistData(*DObj, DObj->getRnglistsDWOSection(),
1253 isLittleEndian(), 0);
1254 dumpRnglistsSection(OS, RnglistData, LookupPooledAddress, DumpOpts);
1255 }
1256
1257 if (shouldDump(Explicit, ".debug_pubnames", DIDT_ID_DebugPubnames,
1258 DObj->getPubnamesSection().Data)) {
1259 DWARFDataExtractor PubTableData(*DObj, DObj->getPubnamesSection(),
1260 isLittleEndian(), 0);
1261 dumpPubTableSection(OS, DumpOpts, PubTableData, /*GnuStyle=*/false);
1262 }
1263
1264 if (shouldDump(Explicit, ".debug_pubtypes", DIDT_ID_DebugPubtypes,
1265 DObj->getPubtypesSection().Data)) {
1266 DWARFDataExtractor PubTableData(*DObj, DObj->getPubtypesSection(),
1267 isLittleEndian(), 0);
1268 dumpPubTableSection(OS, DumpOpts, PubTableData, /*GnuStyle=*/false);
1269 }
1270
1271 if (shouldDump(Explicit, ".debug_gnu_pubnames", DIDT_ID_DebugGnuPubnames,
1272 DObj->getGnuPubnamesSection().Data)) {
1273 DWARFDataExtractor PubTableData(*DObj, DObj->getGnuPubnamesSection(),
1274 isLittleEndian(), 0);
1275 dumpPubTableSection(OS, DumpOpts, PubTableData, /*GnuStyle=*/true);
1276 }
1277
1278 if (shouldDump(Explicit, ".debug_gnu_pubtypes", DIDT_ID_DebugGnuPubtypes,
1279 DObj->getGnuPubtypesSection().Data)) {
1280 DWARFDataExtractor PubTableData(*DObj, DObj->getGnuPubtypesSection(),
1281 isLittleEndian(), 0);
1282 dumpPubTableSection(OS, DumpOpts, PubTableData, /*GnuStyle=*/true);
1283 }
1284
1285 if (shouldDump(Explicit, ".debug_str_offsets", DIDT_ID_DebugStrOffsets,
1286 DObj->getStrOffsetsSection().Data))
1288 OS, DumpOpts, "debug_str_offsets", *DObj, DObj->getStrOffsetsSection(),
1289 DObj->getStrSection(), normal_units(), isLittleEndian());
1290 if (shouldDump(ExplicitDWO, ".debug_str_offsets.dwo", DIDT_ID_DebugStrOffsets,
1291 DObj->getStrOffsetsDWOSection().Data))
1292 dumpStringOffsetsSection(OS, DumpOpts, "debug_str_offsets.dwo", *DObj,
1293 DObj->getStrOffsetsDWOSection(),
1294 DObj->getStrDWOSection(), dwo_units(),
1295 isLittleEndian());
1296
1297 if (shouldDump(Explicit, ".gdb_index", DIDT_ID_GdbIndex,
1298 DObj->getGdbIndexSection())) {
1299 getGdbIndex().dump(OS);
1300 }
1301
1302 if (shouldDump(Explicit, ".apple_names", DIDT_ID_AppleNames,
1303 DObj->getAppleNamesSection().Data))
1305
1306 if (shouldDump(Explicit, ".apple_types", DIDT_ID_AppleTypes,
1307 DObj->getAppleTypesSection().Data))
1309
1310 if (shouldDump(Explicit, ".apple_namespaces", DIDT_ID_AppleNamespaces,
1311 DObj->getAppleNamespacesSection().Data))
1313
1314 if (shouldDump(Explicit, ".apple_objc", DIDT_ID_AppleObjC,
1315 DObj->getAppleObjCSection().Data))
1316 getAppleObjC().dump(OS);
1317 if (shouldDump(Explicit, ".debug_names", DIDT_ID_DebugNames,
1318 DObj->getNamesSection().Data))
1320}
1321
1323 bool IsDWO) {
1324 DWARFUnitVector &DWOUnits = State->getDWOUnits();
1325 if (const auto &TUI = getTUIndex()) {
1326 if (const auto *R = TUI.getFromHash(Hash))
1327 return dyn_cast_or_null<DWARFTypeUnit>(
1328 DWOUnits.getUnitForIndexEntry(*R));
1329 return nullptr;
1330 }
1331 const DenseMap<uint64_t, DWARFTypeUnit *> &Map = State->getTypeUnitMap(IsDWO);
1332 auto Iter = Map.find(Hash);
1333 if (Iter != Map.end())
1334 return Iter->second;
1335 return nullptr;
1336}
1337
1339 DWARFUnitVector &DWOUnits = State->getDWOUnits(LazyParse);
1340
1341 if (const auto &CUI = getCUIndex()) {
1342 if (const auto *R = CUI.getFromHash(Hash))
1343 return dyn_cast_or_null<DWARFCompileUnit>(
1344 DWOUnits.getUnitForIndexEntry(*R));
1345 return nullptr;
1346 }
1347
1348 // If there's no index, just search through the CUs in the DWO - there's
1349 // probably only one unless this is something like LTO - though an in-process
1350 // built/cached lookup table could be used in that case to improve repeated
1351 // lookups of different CUs in the DWO.
1352 for (const auto &DWOCU : dwo_compile_units()) {
1353 // Might not have parsed DWO ID yet.
1354 if (!DWOCU->getDWOId()) {
1355 if (std::optional<uint64_t> DWOId =
1356 toUnsigned(DWOCU->getUnitDIE().find(DW_AT_GNU_dwo_id)))
1357 DWOCU->setDWOId(*DWOId);
1358 else
1359 // No DWO ID?
1360 continue;
1361 }
1362 if (DWOCU->getDWOId() == Hash)
1363 return dyn_cast<DWARFCompileUnit>(DWOCU.get());
1364 }
1365 return nullptr;
1366}
1367
1369 if (auto *CU = State->getNormalUnits().getUnitForOffset(Offset))
1370 return CU->getDIEForOffset(Offset);
1371 return DWARFDie();
1372}
1373
1375 bool Success = true;
1376 DWARFVerifier verifier(OS, *this, DumpOpts);
1377
1378 Success &= verifier.handleDebugAbbrev();
1379 if (DumpOpts.DumpType & DIDT_DebugCUIndex)
1380 Success &= verifier.handleDebugCUIndex();
1381 if (DumpOpts.DumpType & DIDT_DebugTUIndex)
1382 Success &= verifier.handleDebugTUIndex();
1383 if (DumpOpts.DumpType & DIDT_DebugInfo)
1384 Success &= verifier.handleDebugInfo();
1385 if (DumpOpts.DumpType & DIDT_DebugLine)
1386 Success &= verifier.handleDebugLine();
1387 if (DumpOpts.DumpType & DIDT_DebugStrOffsets)
1388 Success &= verifier.handleDebugStrOffsets();
1389 Success &= verifier.handleAccelTables();
1390 return Success;
1391}
1392
1394 return State->getCUIndex();
1395}
1396
1398 return State->getTUIndex();
1399}
1400
1402 return State->getGdbIndex();
1403}
1404
1406 return State->getDebugAbbrev();
1407}
1408
1410 return State->getDebugAbbrevDWO();
1411}
1412
1414 return State->getDebugLoc();
1415}
1416
1418 return State->getDebugAranges();
1419}
1420
1422 return State->getDebugFrame();
1423}
1424
1426 return State->getEHFrame();
1427}
1428
1430 return State->getDebugMacro();
1431}
1432
1434 return State->getDebugMacroDWO();
1435}
1436
1438 return State->getDebugMacinfo();
1439}
1440
1442 return State->getDebugMacinfoDWO();
1443}
1444
1445
1447 return State->getDebugNames();
1448}
1449
1451 return State->getAppleNames();
1452}
1453
1455 return State->getAppleTypes();
1456}
1457
1459 return State->getAppleNamespaces();
1460}
1461
1463 return State->getAppleObjC();
1464}
1465
1469 getLineTableForUnit(U, WarningHandler);
1470 if (!ExpectedLineTable) {
1471 WarningHandler(ExpectedLineTable.takeError());
1472 return nullptr;
1473 }
1474 return *ExpectedLineTable;
1475}
1476
1478 DWARFUnit *U, function_ref<void(Error)> RecoverableErrorHandler) {
1479 return State->getLineTableForUnit(U, RecoverableErrorHandler);
1480}
1481
1483 return State->clearLineTableForUnit(U);
1484}
1485
1486DWARFUnitVector &DWARFContext::getDWOUnits(bool Lazy) {
1487 return State->getDWOUnits(Lazy);
1488}
1489
1491 return dyn_cast_or_null<DWARFCompileUnit>(
1492 State->getNormalUnits().getUnitForOffset(Offset));
1493}
1494
1497 return getCompileUnitForOffset(CUOffset);
1498}
1499
1502 if (DWARFCompileUnit *OffsetCU = getCompileUnitForOffset(CUOffset))
1503 return OffsetCU;
1504
1505 // Global variables are often missed by the above search, for one of two
1506 // reasons:
1507 // 1. .debug_aranges may not include global variables. On clang, it seems we
1508 // put the globals in the aranges, but this isn't true for gcc.
1509 // 2. Even if the global variable is in a .debug_arange, global variables
1510 // may not be captured in the [start, end) addresses described by the
1511 // parent compile unit.
1512 //
1513 // So, we walk the CU's and their child DI's manually, looking for the
1514 // specific global variable.
1515 for (std::unique_ptr<DWARFUnit> &CU : compile_units()) {
1516 if (CU->getVariableForAddress(Address)) {
1517 return static_cast<DWARFCompileUnit *>(CU.get());
1518 }
1519 }
1520 return nullptr;
1521}
1522
1524 DIEsForAddress Result;
1525
1527 if (!CU)
1528 return Result;
1529
1530 Result.CompileUnit = CU;
1531 Result.FunctionDIE = CU->getSubroutineForAddress(Address);
1532
1533 std::vector<DWARFDie> Worklist;
1534 Worklist.push_back(Result.FunctionDIE);
1535 while (!Worklist.empty()) {
1536 DWARFDie DIE = Worklist.back();
1537 Worklist.pop_back();
1538
1539 if (!DIE.isValid())
1540 continue;
1541
1542 if (DIE.getTag() == DW_TAG_lexical_block &&
1543 DIE.addressRangeContainsAddress(Address)) {
1544 Result.BlockDIE = DIE;
1545 break;
1546 }
1547
1548 append_range(Worklist, DIE);
1549 }
1550
1551 return Result;
1552}
1553
1554/// TODO: change input parameter from "uint64_t Address"
1555/// into "SectionedAddress Address"
1559 std::string &FunctionName, std::string &StartFile, uint32_t &StartLine,
1560 std::optional<uint64_t> &StartAddress) {
1561 // The address may correspond to instruction in some inlined function,
1562 // so we have to build the chain of inlined functions and take the
1563 // name of the topmost function in it.
1564 SmallVector<DWARFDie, 4> InlinedChain;
1565 CU->getInlinedChainForAddress(Address, InlinedChain);
1566 if (InlinedChain.empty())
1567 return false;
1568
1569 const DWARFDie &DIE = InlinedChain[0];
1570 bool FoundResult = false;
1571 const char *Name = nullptr;
1572 if (Kind != FunctionNameKind::None && (Name = DIE.getSubroutineName(Kind))) {
1573 FunctionName = Name;
1574 FoundResult = true;
1575 }
1576 std::string DeclFile = DIE.getDeclFile(FileNameKind);
1577 if (!DeclFile.empty()) {
1578 StartFile = DeclFile;
1579 FoundResult = true;
1580 }
1581 if (auto DeclLineResult = DIE.getDeclLine()) {
1582 StartLine = DeclLineResult;
1583 FoundResult = true;
1584 }
1585 if (auto LowPcAddr = toSectionedAddress(DIE.find(DW_AT_low_pc)))
1586 StartAddress = LowPcAddr->Address;
1587 return FoundResult;
1588}
1589
1590static std::optional<int64_t>
1592 std::optional<unsigned> FrameBaseReg) {
1593 if (!Expr.empty() &&
1594 (Expr[0] == DW_OP_fbreg ||
1595 (FrameBaseReg && Expr[0] == DW_OP_breg0 + *FrameBaseReg))) {
1596 unsigned Count;
1597 int64_t Offset = decodeSLEB128(Expr.data() + 1, &Count, Expr.end());
1598 // A single DW_OP_fbreg or DW_OP_breg.
1599 if (Expr.size() == Count + 1)
1600 return Offset;
1601 // Same + DW_OP_deref (Fortran arrays look like this).
1602 if (Expr.size() == Count + 2 && Expr[Count + 1] == DW_OP_deref)
1603 return Offset;
1604 // Fallthrough. Do not accept ex. (DW_OP_breg W29, DW_OP_stack_value)
1605 }
1606 return std::nullopt;
1607}
1608
1609void DWARFContext::addLocalsForDie(DWARFCompileUnit *CU, DWARFDie Subprogram,
1610 DWARFDie Die, std::vector<DILocal> &Result) {
1611 if (Die.getTag() == DW_TAG_variable ||
1612 Die.getTag() == DW_TAG_formal_parameter) {
1613 DILocal Local;
1614 if (const char *Name = Subprogram.getSubroutineName(DINameKind::ShortName))
1615 Local.FunctionName = Name;
1616
1617 std::optional<unsigned> FrameBaseReg;
1618 if (auto FrameBase = Subprogram.find(DW_AT_frame_base))
1619 if (std::optional<ArrayRef<uint8_t>> Expr = FrameBase->getAsBlock())
1620 if (!Expr->empty() && (*Expr)[0] >= DW_OP_reg0 &&
1621 (*Expr)[0] <= DW_OP_reg31) {
1622 FrameBaseReg = (*Expr)[0] - DW_OP_reg0;
1623 }
1624
1625 if (Expected<std::vector<DWARFLocationExpression>> Loc =
1626 Die.getLocations(DW_AT_location)) {
1627 for (const auto &Entry : *Loc) {
1628 if (std::optional<int64_t> FrameOffset =
1629 getExpressionFrameOffset(Entry.Expr, FrameBaseReg)) {
1630 Local.FrameOffset = *FrameOffset;
1631 break;
1632 }
1633 }
1634 } else {
1635 // FIXME: missing DW_AT_location is OK here, but other errors should be
1636 // reported to the user.
1637 consumeError(Loc.takeError());
1638 }
1639
1640 if (auto TagOffsetAttr = Die.find(DW_AT_LLVM_tag_offset))
1641 Local.TagOffset = TagOffsetAttr->getAsUnsignedConstant();
1642
1643 if (auto Origin =
1644 Die.getAttributeValueAsReferencedDie(DW_AT_abstract_origin))
1645 Die = Origin;
1646 if (auto NameAttr = Die.find(DW_AT_name))
1647 if (std::optional<const char *> Name = dwarf::toString(*NameAttr))
1648 Local.Name = *Name;
1649 if (auto Type = Die.getAttributeValueAsReferencedDie(DW_AT_type))
1650 Local.Size = Type.getTypeSize(getCUAddrSize());
1651 if (auto DeclFileAttr = Die.find(DW_AT_decl_file)) {
1652 if (const auto *LT = CU->getContext().getLineTableForUnit(CU))
1653 LT->getFileNameByIndex(
1654 *DeclFileAttr->getAsUnsignedConstant(), CU->getCompilationDir(),
1655 DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath,
1656 Local.DeclFile);
1657 }
1658 if (auto DeclLineAttr = Die.find(DW_AT_decl_line))
1659 Local.DeclLine = *DeclLineAttr->getAsUnsignedConstant();
1660
1661 Result.push_back(Local);
1662 return;
1663 }
1664
1665 if (Die.getTag() == DW_TAG_inlined_subroutine)
1666 if (auto Origin =
1667 Die.getAttributeValueAsReferencedDie(DW_AT_abstract_origin))
1668 Subprogram = Origin;
1669
1670 for (auto Child : Die)
1671 addLocalsForDie(CU, Subprogram, Child, Result);
1672}
1673
1674std::vector<DILocal>
1676 std::vector<DILocal> Result;
1678 if (!CU)
1679 return Result;
1680
1681 DWARFDie Subprogram = CU->getSubroutineForAddress(Address.Address);
1682 if (Subprogram.isValid())
1683 addLocalsForDie(CU, Subprogram, Subprogram, Result);
1684 return Result;
1685}
1686
1689 DILineInfo Result;
1691 if (!CU)
1692 return Result;
1693
1695 CU, Address.Address, Spec.FNKind, Spec.FLIKind, Result.FunctionName,
1696 Result.StartFileName, Result.StartLine, Result.StartAddress);
1697 if (Spec.FLIKind != FileLineInfoKind::None) {
1698 if (const DWARFLineTable *LineTable = getLineTableForUnit(CU)) {
1699 LineTable->getFileLineInfoForAddress(
1700 {Address.Address, Address.SectionIndex}, CU->getCompilationDir(),
1701 Spec.FLIKind, Result);
1702 }
1703 }
1704
1705 return Result;
1706}
1707
1710 DILineInfo Result;
1712 if (!CU)
1713 return Result;
1714
1715 if (DWARFDie Die = CU->getVariableForAddress(Address.Address)) {
1716 Result.FileName = Die.getDeclFile(FileLineInfoKind::AbsoluteFilePath);
1717 Result.Line = Die.getDeclLine();
1718 }
1719
1720 return Result;
1721}
1722
1725 DILineInfoTable Lines;
1727 if (!CU)
1728 return Lines;
1729
1730 uint32_t StartLine = 0;
1731 std::string StartFileName;
1732 std::string FunctionName(DILineInfo::BadString);
1733 std::optional<uint64_t> StartAddress;
1735 Spec.FLIKind, FunctionName,
1736 StartFileName, StartLine, StartAddress);
1737
1738 // If the Specifier says we don't need FileLineInfo, just
1739 // return the top-most function at the starting address.
1740 if (Spec.FLIKind == FileLineInfoKind::None) {
1741 DILineInfo Result;
1742 Result.FunctionName = FunctionName;
1743 Result.StartFileName = StartFileName;
1744 Result.StartLine = StartLine;
1745 Result.StartAddress = StartAddress;
1746 Lines.push_back(std::make_pair(Address.Address, Result));
1747 return Lines;
1748 }
1749
1750 const DWARFLineTable *LineTable = getLineTableForUnit(CU);
1751
1752 // Get the index of row we're looking for in the line table.
1753 std::vector<uint32_t> RowVector;
1754 if (!LineTable->lookupAddressRange({Address.Address, Address.SectionIndex},
1755 Size, RowVector)) {
1756 return Lines;
1757 }
1758
1759 for (uint32_t RowIndex : RowVector) {
1760 // Take file number and line/column from the row.
1761 const DWARFDebugLine::Row &Row = LineTable->Rows[RowIndex];
1762 DILineInfo Result;
1763 LineTable->getFileNameByIndex(Row.File, CU->getCompilationDir(),
1764 Spec.FLIKind, Result.FileName);
1765 Result.FunctionName = FunctionName;
1766 Result.Line = Row.Line;
1767 Result.Column = Row.Column;
1768 Result.StartFileName = StartFileName;
1769 Result.StartLine = StartLine;
1770 Result.StartAddress = StartAddress;
1771 Lines.push_back(std::make_pair(Row.Address.Address, Result));
1772 }
1773
1774 return Lines;
1775}
1776
1780 DIInliningInfo InliningInfo;
1781
1783 if (!CU)
1784 return InliningInfo;
1785
1786 const DWARFLineTable *LineTable = nullptr;
1787 SmallVector<DWARFDie, 4> InlinedChain;
1788 CU->getInlinedChainForAddress(Address.Address, InlinedChain);
1789 if (InlinedChain.size() == 0) {
1790 // If there is no DIE for address (e.g. it is in unavailable .dwo file),
1791 // try to at least get file/line info from symbol table.
1792 if (Spec.FLIKind != FileLineInfoKind::None) {
1793 DILineInfo Frame;
1794 LineTable = getLineTableForUnit(CU);
1795 if (LineTable && LineTable->getFileLineInfoForAddress(
1796 {Address.Address, Address.SectionIndex},
1797 CU->getCompilationDir(), Spec.FLIKind, Frame))
1798 InliningInfo.addFrame(Frame);
1799 }
1800 return InliningInfo;
1801 }
1802
1803 uint32_t CallFile = 0, CallLine = 0, CallColumn = 0, CallDiscriminator = 0;
1804 for (uint32_t i = 0, n = InlinedChain.size(); i != n; i++) {
1805 DWARFDie &FunctionDIE = InlinedChain[i];
1806 DILineInfo Frame;
1807 // Get function name if necessary.
1808 if (const char *Name = FunctionDIE.getSubroutineName(Spec.FNKind))
1809 Frame.FunctionName = Name;
1810 if (auto DeclLineResult = FunctionDIE.getDeclLine())
1811 Frame.StartLine = DeclLineResult;
1812 Frame.StartFileName = FunctionDIE.getDeclFile(Spec.FLIKind);
1813 if (auto LowPcAddr = toSectionedAddress(FunctionDIE.find(DW_AT_low_pc)))
1814 Frame.StartAddress = LowPcAddr->Address;
1815 if (Spec.FLIKind != FileLineInfoKind::None) {
1816 if (i == 0) {
1817 // For the topmost frame, initialize the line table of this
1818 // compile unit and fetch file/line info from it.
1819 LineTable = getLineTableForUnit(CU);
1820 // For the topmost routine, get file/line info from line table.
1821 if (LineTable)
1822 LineTable->getFileLineInfoForAddress(
1823 {Address.Address, Address.SectionIndex}, CU->getCompilationDir(),
1824 Spec.FLIKind, Frame);
1825 } else {
1826 // Otherwise, use call file, call line and call column from
1827 // previous DIE in inlined chain.
1828 if (LineTable)
1829 LineTable->getFileNameByIndex(CallFile, CU->getCompilationDir(),
1830 Spec.FLIKind, Frame.FileName);
1831 Frame.Line = CallLine;
1832 Frame.Column = CallColumn;
1833 Frame.Discriminator = CallDiscriminator;
1834 }
1835 // Get call file/line/column of a current DIE.
1836 if (i + 1 < n) {
1837 FunctionDIE.getCallerFrame(CallFile, CallLine, CallColumn,
1838 CallDiscriminator);
1839 }
1840 }
1841 InliningInfo.addFrame(Frame);
1842 }
1843 return InliningInfo;
1844}
1845
1846std::shared_ptr<DWARFContext>
1848 return State->getDWOContext(AbsolutePath);
1849}
1850
1851static Error createError(const Twine &Reason, llvm::Error E) {
1852 return make_error<StringError>(Reason + toString(std::move(E)),
1854}
1855
1856/// SymInfo contains information about symbol: it's address
1857/// and section index which is -1LL for absolute symbols.
1858struct SymInfo {
1861};
1862
1863/// Returns the address of symbol relocation used against and a section index.
1864/// Used for futher relocations computation. Symbol's section load address is
1866 const RelocationRef &Reloc,
1867 const LoadedObjectInfo *L,
1868 std::map<SymbolRef, SymInfo> &Cache) {
1869 SymInfo Ret = {0, (uint64_t)-1LL};
1872
1873 std::map<SymbolRef, SymInfo>::iterator CacheIt = Cache.end();
1874 // First calculate the address of the symbol or section as it appears
1875 // in the object file
1876 if (Sym != Obj.symbol_end()) {
1877 bool New;
1878 std::tie(CacheIt, New) = Cache.insert({*Sym, {0, 0}});
1879 if (!New)
1880 return CacheIt->second;
1881
1882 Expected<uint64_t> SymAddrOrErr = Sym->getAddress();
1883 if (!SymAddrOrErr)
1884 return createError("failed to compute symbol address: ",
1885 SymAddrOrErr.takeError());
1886
1887 // Also remember what section this symbol is in for later
1888 auto SectOrErr = Sym->getSection();
1889 if (!SectOrErr)
1890 return createError("failed to get symbol section: ",
1891 SectOrErr.takeError());
1892
1893 RSec = *SectOrErr;
1894 Ret.Address = *SymAddrOrErr;
1895 } else if (auto *MObj = dyn_cast<MachOObjectFile>(&Obj)) {
1896 RSec = MObj->getRelocationSection(Reloc.getRawDataRefImpl());
1897 Ret.Address = RSec->getAddress();
1898 }
1899
1900 if (RSec != Obj.section_end())
1901 Ret.SectionIndex = RSec->getIndex();
1902
1903 // If we are given load addresses for the sections, we need to adjust:
1904 // SymAddr = (Address of Symbol Or Section in File) -
1905 // (Address of Section in File) +
1906 // (Load Address of Section)
1907 // RSec is now either the section being targeted or the section
1908 // containing the symbol being targeted. In either case,
1909 // we need to perform the same computation.
1910 if (L && RSec != Obj.section_end())
1911 if (uint64_t SectionLoadAddress = L->getSectionLoadAddress(*RSec))
1912 Ret.Address += SectionLoadAddress - RSec->getAddress();
1913
1914 if (CacheIt != Cache.end())
1915 CacheIt->second = Ret;
1916
1917 return Ret;
1918}
1919
1921 const RelocationRef &Reloc) {
1922 const MachOObjectFile *MachObj = dyn_cast<MachOObjectFile>(&Obj);
1923 if (!MachObj)
1924 return false;
1925 // MachO also has relocations that point to sections and
1926 // scattered relocations.
1927 auto RelocInfo = MachObj->getRelocation(Reloc.getRawDataRefImpl());
1928 return MachObj->isRelocationScattered(RelocInfo);
1929}
1930
1931namespace {
1932struct DWARFSectionMap final : public DWARFSection {
1933 RelocAddrMap Relocs;
1934};
1935
1936class DWARFObjInMemory final : public DWARFObject {
1937 bool IsLittleEndian;
1938 uint8_t AddressSize;
1939 StringRef FileName;
1940 const object::ObjectFile *Obj = nullptr;
1941 std::vector<SectionName> SectionNames;
1942
1943 using InfoSectionMap = MapVector<object::SectionRef, DWARFSectionMap,
1944 std::map<object::SectionRef, unsigned>>;
1945
1946 InfoSectionMap InfoSections;
1947 InfoSectionMap TypesSections;
1948 InfoSectionMap InfoDWOSections;
1949 InfoSectionMap TypesDWOSections;
1950
1951 DWARFSectionMap LocSection;
1952 DWARFSectionMap LoclistsSection;
1953 DWARFSectionMap LoclistsDWOSection;
1954 DWARFSectionMap LineSection;
1955 DWARFSectionMap RangesSection;
1956 DWARFSectionMap RnglistsSection;
1957 DWARFSectionMap StrOffsetsSection;
1958 DWARFSectionMap LineDWOSection;
1959 DWARFSectionMap FrameSection;
1960 DWARFSectionMap EHFrameSection;
1961 DWARFSectionMap LocDWOSection;
1962 DWARFSectionMap StrOffsetsDWOSection;
1963 DWARFSectionMap RangesDWOSection;
1964 DWARFSectionMap RnglistsDWOSection;
1965 DWARFSectionMap AddrSection;
1966 DWARFSectionMap AppleNamesSection;
1967 DWARFSectionMap AppleTypesSection;
1968 DWARFSectionMap AppleNamespacesSection;
1969 DWARFSectionMap AppleObjCSection;
1970 DWARFSectionMap NamesSection;
1971 DWARFSectionMap PubnamesSection;
1972 DWARFSectionMap PubtypesSection;
1973 DWARFSectionMap GnuPubnamesSection;
1974 DWARFSectionMap GnuPubtypesSection;
1975 DWARFSectionMap MacroSection;
1976
1977 DWARFSectionMap *mapNameToDWARFSection(StringRef Name) {
1979 .Case("debug_loc", &LocSection)
1980 .Case("debug_loclists", &LoclistsSection)
1981 .Case("debug_loclists.dwo", &LoclistsDWOSection)
1982 .Case("debug_line", &LineSection)
1983 .Case("debug_frame", &FrameSection)
1984 .Case("eh_frame", &EHFrameSection)
1985 .Case("debug_str_offsets", &StrOffsetsSection)
1986 .Case("debug_ranges", &RangesSection)
1987 .Case("debug_rnglists", &RnglistsSection)
1988 .Case("debug_loc.dwo", &LocDWOSection)
1989 .Case("debug_line.dwo", &LineDWOSection)
1990 .Case("debug_names", &NamesSection)
1991 .Case("debug_rnglists.dwo", &RnglistsDWOSection)
1992 .Case("debug_str_offsets.dwo", &StrOffsetsDWOSection)
1993 .Case("debug_addr", &AddrSection)
1994 .Case("apple_names", &AppleNamesSection)
1995 .Case("debug_pubnames", &PubnamesSection)
1996 .Case("debug_pubtypes", &PubtypesSection)
1997 .Case("debug_gnu_pubnames", &GnuPubnamesSection)
1998 .Case("debug_gnu_pubtypes", &GnuPubtypesSection)
1999 .Case("apple_types", &AppleTypesSection)
2000 .Case("apple_namespaces", &AppleNamespacesSection)
2001 .Case("apple_namespac", &AppleNamespacesSection)
2002 .Case("apple_objc", &AppleObjCSection)
2003 .Case("debug_macro", &MacroSection)
2004 .Default(nullptr);
2005 }
2006
2007 StringRef AbbrevSection;
2008 StringRef ArangesSection;
2009 StringRef StrSection;
2010 StringRef MacinfoSection;
2011 StringRef MacinfoDWOSection;
2012 StringRef MacroDWOSection;
2013 StringRef AbbrevDWOSection;
2014 StringRef StrDWOSection;
2015 StringRef CUIndexSection;
2016 StringRef GdbIndexSection;
2017 StringRef TUIndexSection;
2018 StringRef LineStrSection;
2019
2020 // A deque holding section data whose iterators are not invalidated when
2021 // new decompressed sections are inserted at the end.
2022 std::deque<SmallString<0>> UncompressedSections;
2023
2024 StringRef *mapSectionToMember(StringRef Name) {
2025 if (DWARFSection *Sec = mapNameToDWARFSection(Name))
2026 return &Sec->Data;
2028 .Case("debug_abbrev", &AbbrevSection)
2029 .Case("debug_aranges", &ArangesSection)
2030 .Case("debug_str", &StrSection)
2031 .Case("debug_macinfo", &MacinfoSection)
2032 .Case("debug_macinfo.dwo", &MacinfoDWOSection)
2033 .Case("debug_macro.dwo", &MacroDWOSection)
2034 .Case("debug_abbrev.dwo", &AbbrevDWOSection)
2035 .Case("debug_str.dwo", &StrDWOSection)
2036 .Case("debug_cu_index", &CUIndexSection)
2037 .Case("debug_tu_index", &TUIndexSection)
2038 .Case("gdb_index", &GdbIndexSection)
2039 .Case("debug_line_str", &LineStrSection)
2040 // Any more debug info sections go here.
2041 .Default(nullptr);
2042 }
2043
2044 /// If Sec is compressed section, decompresses and updates its contents
2045 /// provided by Data. Otherwise leaves it unchanged.
2046 Error maybeDecompress(const object::SectionRef &Sec, StringRef Name,
2047 StringRef &Data) {
2048 if (!Sec.isCompressed())
2049 return Error::success();
2050
2052 Decompressor::create(Name, Data, IsLittleEndian, AddressSize == 8);
2053 if (!Decompressor)
2054 return Decompressor.takeError();
2055
2056 SmallString<0> Out;
2057 if (auto Err = Decompressor->resizeAndDecompress(Out))
2058 return Err;
2059
2060 UncompressedSections.push_back(std::move(Out));
2061 Data = UncompressedSections.back();
2062
2063 return Error::success();
2064 }
2065
2066public:
2067 DWARFObjInMemory(const StringMap<std::unique_ptr<MemoryBuffer>> &Sections,
2068 uint8_t AddrSize, bool IsLittleEndian)
2069 : IsLittleEndian(IsLittleEndian) {
2070 for (const auto &SecIt : Sections) {
2071 if (StringRef *SectionData = mapSectionToMember(SecIt.first()))
2072 *SectionData = SecIt.second->getBuffer();
2073 else if (SecIt.first() == "debug_info")
2074 // Find debug_info and debug_types data by section rather than name as
2075 // there are multiple, comdat grouped, of these sections.
2076 InfoSections[SectionRef()].Data = SecIt.second->getBuffer();
2077 else if (SecIt.first() == "debug_info.dwo")
2078 InfoDWOSections[SectionRef()].Data = SecIt.second->getBuffer();
2079 else if (SecIt.first() == "debug_types")
2080 TypesSections[SectionRef()].Data = SecIt.second->getBuffer();
2081 else if (SecIt.first() == "debug_types.dwo")
2082 TypesDWOSections[SectionRef()].Data = SecIt.second->getBuffer();
2083 }
2084 }
2085 DWARFObjInMemory(const object::ObjectFile &Obj, const LoadedObjectInfo *L,
2086 function_ref<void(Error)> HandleError,
2087 function_ref<void(Error)> HandleWarning,
2089 : IsLittleEndian(Obj.isLittleEndian()),
2090 AddressSize(Obj.getBytesInAddress()), FileName(Obj.getFileName()),
2091 Obj(&Obj) {
2092
2093 StringMap<unsigned> SectionAmountMap;
2094 for (const SectionRef &Section : Obj.sections()) {
2096 if (auto NameOrErr = Section.getName())
2097 Name = *NameOrErr;
2098 else
2099 consumeError(NameOrErr.takeError());
2100
2101 ++SectionAmountMap[Name];
2102 SectionNames.push_back({ Name, true });
2103
2104 // Skip BSS and Virtual sections, they aren't interesting.
2105 if (Section.isBSS() || Section.isVirtual())
2106 continue;
2107
2108 // Skip sections stripped by dsymutil.
2109 if (Section.isStripped())
2110 continue;
2111
2113 Expected<section_iterator> SecOrErr = Section.getRelocatedSection();
2114 if (!SecOrErr) {
2115 HandleError(createError("failed to get relocated section: ",
2116 SecOrErr.takeError()));
2117 continue;
2118 }
2119
2120 // Try to obtain an already relocated version of this section.
2121 // Else use the unrelocated section from the object file. We'll have to
2122 // apply relocations ourselves later.
2123 section_iterator RelocatedSection =
2124 Obj.isRelocatableObject() ? *SecOrErr : Obj.section_end();
2125 if (!L || !L->getLoadedSectionContents(*RelocatedSection, Data)) {
2126 Expected<StringRef> E = Section.getContents();
2127 if (E)
2128 Data = *E;
2129 else
2130 // maybeDecompress below will error.
2131 consumeError(E.takeError());
2132 }
2133
2134 if (auto Err = maybeDecompress(Section, Name, Data)) {
2135 HandleError(createError("failed to decompress '" + Name + "', ",
2136 std::move(Err)));
2137 continue;
2138 }
2139
2140 // Map platform specific debug section names to DWARF standard section
2141 // names.
2142 Name = Name.substr(Name.find_first_not_of("._"));
2144
2145 if (StringRef *SectionData = mapSectionToMember(Name)) {
2146 *SectionData = Data;
2147 if (Name == "debug_ranges") {
2148 // FIXME: Use the other dwo range section when we emit it.
2149 RangesDWOSection.Data = Data;
2150 } else if (Name == "debug_frame" || Name == "eh_frame") {
2151 if (DWARFSection *S = mapNameToDWARFSection(Name))
2152 S->Address = Section.getAddress();
2153 }
2154 } else if (InfoSectionMap *Sections =
2156 .Case("debug_info", &InfoSections)
2157 .Case("debug_info.dwo", &InfoDWOSections)
2158 .Case("debug_types", &TypesSections)
2159 .Case("debug_types.dwo", &TypesDWOSections)
2160 .Default(nullptr)) {
2161 // Find debug_info and debug_types data by section rather than name as
2162 // there are multiple, comdat grouped, of these sections.
2163 DWARFSectionMap &S = (*Sections)[Section];
2164 S.Data = Data;
2165 }
2166
2167 if (RelocatedSection == Obj.section_end() ||
2168 (RelocAction == DWARFContext::ProcessDebugRelocations::Ignore))
2169 continue;
2170
2171 StringRef RelSecName;
2172 if (auto NameOrErr = RelocatedSection->getName())
2173 RelSecName = *NameOrErr;
2174 else
2175 consumeError(NameOrErr.takeError());
2176
2177 // If the section we're relocating was relocated already by the JIT,
2178 // then we used the relocated version above, so we do not need to process
2179 // relocations for it now.
2180 StringRef RelSecData;
2181 if (L && L->getLoadedSectionContents(*RelocatedSection, RelSecData))
2182 continue;
2183
2184 // In Mach-o files, the relocations do not need to be applied if
2185 // there is no load offset to apply. The value read at the
2186 // relocation point already factors in the section address
2187 // (actually applying the relocations will produce wrong results
2188 // as the section address will be added twice).
2189 if (!L && isa<MachOObjectFile>(&Obj))
2190 continue;
2191
2192 if (!Section.relocations().empty() && Name.ends_with(".dwo") &&
2193 RelSecName.startswith(".debug")) {
2194 HandleWarning(createError("unexpected relocations for dwo section '" +
2195 RelSecName + "'"));
2196 }
2197
2198 // TODO: Add support for relocations in other sections as needed.
2199 // Record relocations for the debug_info and debug_line sections.
2200 RelSecName = RelSecName.substr(RelSecName.find_first_not_of("._"));
2201 DWARFSectionMap *Sec = mapNameToDWARFSection(RelSecName);
2202 RelocAddrMap *Map = Sec ? &Sec->Relocs : nullptr;
2203 if (!Map) {
2204 // Find debug_info and debug_types relocs by section rather than name
2205 // as there are multiple, comdat grouped, of these sections.
2206 if (RelSecName == "debug_info")
2207 Map = &static_cast<DWARFSectionMap &>(InfoSections[*RelocatedSection])
2208 .Relocs;
2209 else if (RelSecName == "debug_types")
2210 Map =
2211 &static_cast<DWARFSectionMap &>(TypesSections[*RelocatedSection])
2212 .Relocs;
2213 else
2214 continue;
2215 }
2216
2217 if (Section.relocation_begin() == Section.relocation_end())
2218 continue;
2219
2220 // Symbol to [address, section index] cache mapping.
2221 std::map<SymbolRef, SymInfo> AddrCache;
2222 SupportsRelocation Supports;
2224 std::tie(Supports, Resolver) = getRelocationResolver(Obj);
2225 for (const RelocationRef &Reloc : Section.relocations()) {
2226 // FIXME: it's not clear how to correctly handle scattered
2227 // relocations.
2228 if (isRelocScattered(Obj, Reloc))
2229 continue;
2230
2231 Expected<SymInfo> SymInfoOrErr =
2232 getSymbolInfo(Obj, Reloc, L, AddrCache);
2233 if (!SymInfoOrErr) {
2234 HandleError(SymInfoOrErr.takeError());
2235 continue;
2236 }
2237
2238 // Check if Resolver can handle this relocation type early so as not to
2239 // handle invalid cases in DWARFDataExtractor.
2240 //
2241 // TODO Don't store Resolver in every RelocAddrEntry.
2242 if (Supports && Supports(Reloc.getType())) {
2243 auto I = Map->try_emplace(
2244 Reloc.getOffset(),
2246 SymInfoOrErr->SectionIndex, Reloc, SymInfoOrErr->Address,
2247 std::optional<object::RelocationRef>(), 0, Resolver});
2248 // If we didn't successfully insert that's because we already had a
2249 // relocation for that offset. Store it as a second relocation in the
2250 // same RelocAddrEntry instead.
2251 if (!I.second) {
2252 RelocAddrEntry &entry = I.first->getSecond();
2253 if (entry.Reloc2) {
2254 HandleError(createError(
2255 "At most two relocations per offset are supported"));
2256 }
2257 entry.Reloc2 = Reloc;
2258 entry.SymbolValue2 = SymInfoOrErr->Address;
2259 }
2260 } else {
2262 Reloc.getTypeName(Type);
2263 // FIXME: Support more relocations & change this to an error
2264 HandleWarning(
2265 createError("failed to compute relocation: " + Type + ", ",
2266 errorCodeToError(object_error::parse_failed)));
2267 }
2268 }
2269 }
2270
2271 for (SectionName &S : SectionNames)
2272 if (SectionAmountMap[S.Name] > 1)
2273 S.IsNameUnique = false;
2274 }
2275
2276 std::optional<RelocAddrEntry> find(const DWARFSection &S,
2277 uint64_t Pos) const override {
2278 auto &Sec = static_cast<const DWARFSectionMap &>(S);
2279 RelocAddrMap::const_iterator AI = Sec.Relocs.find(Pos);
2280 if (AI == Sec.Relocs.end())
2281 return std::nullopt;
2282 return AI->second;
2283 }
2284
2285 const object::ObjectFile *getFile() const override { return Obj; }
2286
2287 ArrayRef<SectionName> getSectionNames() const override {
2288 return SectionNames;
2289 }
2290
2291 bool isLittleEndian() const override { return IsLittleEndian; }
2292 StringRef getAbbrevDWOSection() const override { return AbbrevDWOSection; }
2293 const DWARFSection &getLineDWOSection() const override {
2294 return LineDWOSection;
2295 }
2296 const DWARFSection &getLocDWOSection() const override {
2297 return LocDWOSection;
2298 }
2299 StringRef getStrDWOSection() const override { return StrDWOSection; }
2300 const DWARFSection &getStrOffsetsDWOSection() const override {
2301 return StrOffsetsDWOSection;
2302 }
2303 const DWARFSection &getRangesDWOSection() const override {
2304 return RangesDWOSection;
2305 }
2306 const DWARFSection &getRnglistsDWOSection() const override {
2307 return RnglistsDWOSection;
2308 }
2309 const DWARFSection &getLoclistsDWOSection() const override {
2310 return LoclistsDWOSection;
2311 }
2312 const DWARFSection &getAddrSection() const override { return AddrSection; }
2313 StringRef getCUIndexSection() const override { return CUIndexSection; }
2314 StringRef getGdbIndexSection() const override { return GdbIndexSection; }
2315 StringRef getTUIndexSection() const override { return TUIndexSection; }
2316
2317 // DWARF v5
2318 const DWARFSection &getStrOffsetsSection() const override {
2319 return StrOffsetsSection;
2320 }
2321 StringRef getLineStrSection() const override { return LineStrSection; }
2322
2323 // Sections for DWARF5 split dwarf proposal.
2324 void forEachInfoDWOSections(
2325 function_ref<void(const DWARFSection &)> F) const override {
2326 for (auto &P : InfoDWOSections)
2327 F(P.second);
2328 }
2329 void forEachTypesDWOSections(
2330 function_ref<void(const DWARFSection &)> F) const override {
2331 for (auto &P : TypesDWOSections)
2332 F(P.second);
2333 }
2334
2335 StringRef getAbbrevSection() const override { return AbbrevSection; }
2336 const DWARFSection &getLocSection() const override { return LocSection; }
2337 const DWARFSection &getLoclistsSection() const override { return LoclistsSection; }
2338 StringRef getArangesSection() const override { return ArangesSection; }
2339 const DWARFSection &getFrameSection() const override {
2340 return FrameSection;
2341 }
2342 const DWARFSection &getEHFrameSection() const override {
2343 return EHFrameSection;
2344 }
2345 const DWARFSection &getLineSection() const override { return LineSection; }
2346 StringRef getStrSection() const override { return StrSection; }
2347 const DWARFSection &getRangesSection() const override { return RangesSection; }
2348 const DWARFSection &getRnglistsSection() const override {
2349 return RnglistsSection;
2350 }
2351 const DWARFSection &getMacroSection() const override { return MacroSection; }
2352 StringRef getMacroDWOSection() const override { return MacroDWOSection; }
2353 StringRef getMacinfoSection() const override { return MacinfoSection; }
2354 StringRef getMacinfoDWOSection() const override { return MacinfoDWOSection; }
2355 const DWARFSection &getPubnamesSection() const override { return PubnamesSection; }
2356 const DWARFSection &getPubtypesSection() const override { return PubtypesSection; }
2357 const DWARFSection &getGnuPubnamesSection() const override {
2358 return GnuPubnamesSection;
2359 }
2360 const DWARFSection &getGnuPubtypesSection() const override {
2361 return GnuPubtypesSection;
2362 }
2363 const DWARFSection &getAppleNamesSection() const override {
2364 return AppleNamesSection;
2365 }
2366 const DWARFSection &getAppleTypesSection() const override {
2367 return AppleTypesSection;
2368 }
2369 const DWARFSection &getAppleNamespacesSection() const override {
2370 return AppleNamespacesSection;
2371 }
2372 const DWARFSection &getAppleObjCSection() const override {
2373 return AppleObjCSection;
2374 }
2375 const DWARFSection &getNamesSection() const override {
2376 return NamesSection;
2377 }
2378
2379 StringRef getFileName() const override { return FileName; }
2380 uint8_t getAddressSize() const override { return AddressSize; }
2381 void forEachInfoSections(
2382 function_ref<void(const DWARFSection &)> F) const override {
2383 for (auto &P : InfoSections)
2384 F(P.second);
2385 }
2386 void forEachTypesSections(
2387 function_ref<void(const DWARFSection &)> F) const override {
2388 for (auto &P : TypesSections)
2389 F(P.second);
2390 }
2391};
2392} // namespace
2393
2394std::unique_ptr<DWARFContext>
2396 ProcessDebugRelocations RelocAction,
2397 const LoadedObjectInfo *L, std::string DWPName,
2398 std::function<void(Error)> RecoverableErrorHandler,
2399 std::function<void(Error)> WarningHandler,
2400 bool ThreadSafe) {
2401 auto DObj = std::make_unique<DWARFObjInMemory>(
2402 Obj, L, RecoverableErrorHandler, WarningHandler, RelocAction);
2403 return std::make_unique<DWARFContext>(std::move(DObj),
2404 std::move(DWPName),
2405 RecoverableErrorHandler,
2406 WarningHandler,
2407 ThreadSafe);
2408}
2409
2410std::unique_ptr<DWARFContext>
2411DWARFContext::create(const StringMap<std::unique_ptr<MemoryBuffer>> &Sections,
2412 uint8_t AddrSize, bool isLittleEndian,
2413 std::function<void(Error)> RecoverableErrorHandler,
2414 std::function<void(Error)> WarningHandler,
2415 bool ThreadSafe) {
2416 auto DObj =
2417 std::make_unique<DWARFObjInMemory>(Sections, AddrSize, isLittleEndian);
2418 return std::make_unique<DWARFContext>(
2419 std::move(DObj), "", RecoverableErrorHandler, WarningHandler, ThreadSafe);
2420}
2421
2423 // In theory, different compile units may have different address byte
2424 // sizes, but for simplicity we just use the address byte size of the
2425 // first compile unit. In practice the address size field is repeated across
2426 // various DWARF headers (at least in version 5) to make it easier to dump
2427 // them independently, not to enable varying the address size.
2428 auto CUs = compile_units();
2429 return CUs.empty() ? 0 : (*CUs.begin())->getAddressByteSize();
2430}
#define Success
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")
@ Default
Definition: DwarfDebug.cpp:87
This file contains constants used for implementing Dwarf debug support.
std::string Name
uint64_t Size
Symbol * Sym
Definition: ELF_riscv.cpp:468
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
This file implements a map that provides insertion order iteration.
LLVMContext & Context
#define P(N)
This file contains some templates that are useful if you are working with the STL at all.
raw_pwrite_stream & OS
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
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
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),...
Definition: ArrayRef.h:41
iterator end() const
Definition: ArrayRef.h:154
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:165
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:160
const T * data() const
Definition: ArrayRef.h:162
A structured debug information entry.
Definition: DIE.h:819
dwarf::Tag getTag() const
Definition: DIE.h:855
A format-neutral container for inlined code description.
Definition: DIContext.h:92
void addFrame(const DILineInfo &Frame)
Definition: DIContext.h:112
DWARFContextState This structure contains all member variables for DWARFContext that need to be prote...
Definition: DWARFContext.h:57
MacroSecType
Helper enum to distinguish between macro[.dwo] and macinfo[.dwo] section.
Definition: DWARFContext.h:61
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...
Definition: DWARFContext.h:48
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()
Definition: DWARFContext.h:423
DWARFGdbIndex & getGdbIndex()
unsigned getNumCompileUnits()
Get the number of compile units in this context.
Definition: DWARFContext.h:234
~DWARFContext() override
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.
Definition: DWARFContext.h:239
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.
Definition: DWARFContext.h:187
const AppleAcceleratorTable & getAppleObjC()
Get a reference to the parsed accelerator table object.
const DWARFUnitIndex & getTUIndex()
unsigned getMaxVersion()
Definition: DWARFContext.h:272
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
Definition: DWARFContext.h:352
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.
Definition: DWARFContext.h:249
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
Definition: DWARFContext.h:391
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.
Definition: DWARFContext.h:219
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.
Definition: DWARFContext.h:212
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.
Definition: DWARFContext.h:195
unit_iterator_range types_section_units()
Get units from .debug_types in this context.
Definition: DWARFContext.h:180
std::shared_ptr< DWARFContext > getDWOContext(StringRef AbsolutePath)
DWARFCompileUnit * getDWOCompileUnitForHash(uint64_t Hash)
unsigned getNumDWOCompileUnits()
Get the number of compile units in the DWO context.
Definition: DWARFContext.h:244
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.
Definition: DWARFContext.h:168
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.
Definition: DWARFContext.h:201
DataExtractor getStringDWOExtractor() const
Definition: DWARFContext.h:355
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.
Definition: DWARFContext.h:228
const DWARFObject & getDWARFObj() const
Definition: DWARFContext.h:146
A DataExtractor (typically for an in-memory copy of an object-file section) plus a relocation map for...
uint64_t getRelocatedValue(uint32_t Size, uint64_t *Off, uint64_t *SectionIndex=nullptr, Error *Err=nullptr) const
Extracts a value and applies a relocation to the result if one exists for the given offset.
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
void generate(DWARFContext *CTX)
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.
Definition: DWARFDie.h:42
DWARFDie getAttributeValueAsReferencedDie(dwarf::Attribute Attr) const
Extract the specified attribute from this DIE as the referenced DIE.
Definition: DWARFDie.cpp:304
std::optional< DWARFFormValue > find(dwarf::Attribute Attr) const
Extract the specified attribute from this DIE.
Definition: DWARFDie.cpp:247
const char * getSubroutineName(DINameKind Kind) const
If a DIE represents a subprogram (or inlined subroutine), returns its mangled name (or short name,...
Definition: DWARFDie.cpp:436
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...
Definition: DWARFDie.cpp:481
std::string getDeclFile(DILineInfoSpecifier::FileLineInfoKind Kind) const
Definition: DWARFDie.cpp:474
uint64_t getDeclLine() const
Returns the declaration line (start line) for a DIE, assuming it specifies a subprogram.
Definition: DWARFDie.cpp:469
dwarf::Tag getTag() const
Definition: DWARFDie.h:71
Expected< DWARFLocationExpressionsVector > getLocations(dwarf::Attribute Attr) const
Definition: DWARFDie.cpp:406
bool isValid() const
Definition: DWARFDie.h:50
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
A class representing the header of a list table such as the range list table in the ....
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
Definition: DWARFObject.h:31
virtual StringRef getAbbrevDWOSection() const
Definition: DWARFObject.h:64
virtual const DWARFSection & getFrameSection() const
Definition: DWARFObject.h:44
virtual const DWARFSection & getNamesSection() const
Definition: DWARFObject.h:80
virtual const DWARFSection & getAppleNamespacesSection() const
Definition: DWARFObject.h:77
virtual StringRef getMacroDWOSection() const
Definition: DWARFObject.h:52
virtual void forEachInfoDWOSections(function_ref< void(const DWARFSection &)> F) const
Definition: DWARFObject.h:61
virtual const DWARFSection & getAppleTypesSection() const
Definition: DWARFObject.h:76
virtual void forEachInfoSections(function_ref< void(const DWARFSection &)> F) const
Definition: DWARFObject.h:37
virtual StringRef getMacinfoDWOSection() const
Definition: DWARFObject.h:54
virtual const DWARFSection & getAppleNamesSection() const
Definition: DWARFObject.h:75
virtual const DWARFSection & getEHFrameSection() const
Definition: DWARFObject.h:45
virtual void forEachTypesSections(function_ref< void(const DWARFSection &)> F) const
Definition: DWARFObject.h:39
virtual StringRef getMacinfoSection() const
Definition: DWARFObject.h:53
virtual const DWARFSection & getLocSection() const
Definition: DWARFObject.h:41
virtual const DWARFSection & getAppleObjCSection() const
Definition: DWARFObject.h:81
virtual void forEachTypesDWOSections(function_ref< void(const DWARFSection &)> F) const
Definition: DWARFObject.h:63
virtual const DWARFSection & getMacroSection() const
Definition: DWARFObject.h:51
virtual StringRef getStrSection() const
Definition: DWARFObject.h:48
virtual uint8_t getAddressSize() const
Definition: DWARFObject.h:35
void dump(raw_ostream &OS) const
Describe a collection of units.
Definition: DWARFUnit.h:126
void finishedInfoUnits()
Indicate that parsing .debug_info[.dwo] is done, and remaining units will be from ....
Definition: DWARFUnit.h:172
void addUnitsForSection(DWARFContext &C, const DWARFSection &Section, DWARFSectionKind SectionKind)
Read units from a .debug_info or .debug_types section.
Definition: DWARFUnit.cpp:42
void addUnitsForDWOSection(DWARFContext &C, const DWARFSection &DWOSection, DWARFSectionKind SectionKind, bool Lazy=false)
Read units from a .debug_info.dwo or .debug_types.dwo section.
Definition: DWARFUnit.cpp:53
DWARFUnit * getUnitForIndexEntry(const DWARFUnitIndex::Entry &E)
Definition: DWARFUnit.cpp:158
A class that verifies DWARF debug information given a DWARF Context.
Definition: DWARFVerifier.h:34
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,...
const char * getCStr(uint64_t *OffsetPtr, Error *Err=nullptr) const
Extract a C string from *offset_ptr.
bool isValidOffset(uint64_t offset) const
Test the validity of offset.
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
static ErrorSuccess success()
Create a success value.
Definition: Error.h:334
Tagged union holding either a T or a Error.
Definition: Error.h:474
Error takeError()
Take ownership of the stored error.
Definition: Error.h:601
reference get()
Returns a reference to the stored T value.
Definition: Error.h:571
An inferface for inquiring the load address of a loaded object file to be used by the DIContext imple...
Definition: DIContext.h:271
This class implements a map that also provides access to all stored values in a deterministic order.
Definition: MapVector.h:36
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
Definition: Record.h:2190
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:26
bool empty() const
Definition: SmallVector.h:94
size_t size() const
Definition: SmallVector.h:91
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1200
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:112
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:575
constexpr size_t size() const
size - Get the string size.
Definition: StringRef.h:137
bool startswith(StringRef Prefix) const
Definition: StringRef.h:261
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.
Definition: StringRef.cpp:251
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:44
StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:69
R Default(T Value)
Definition: StringSwitch.h:182
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
static Twine utohexstr(const uint64_t &Val)
Definition: Twine.h:416
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
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.
Definition: Decompressor.h:21
Error resizeAndDecompress(T &Out)
Resize the buffer and uncompress section data into it.
Definition: Decompressor.h:33
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.
Definition: ObjectFile.h:229
virtual section_iterator section_end() const =0
section_iterator_range sections() const
Definition: ObjectFile.h:328
static Expected< OwningBinary< ObjectFile > > createObjectFile(StringRef ObjectPath)
Definition: ObjectFile.cpp:198
virtual StringRef mapDebugSectionName(StringRef Name) const
Maps a debug section name to a standard DWARF section name.
Definition: ObjectFile.h:353
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...
Definition: ObjectFile.h:52
symbol_iterator getSymbol() const
Definition: ObjectFile.h:622
DataRefImpl getRawDataRefImpl() const
Definition: ObjectFile.h:634
This is a value type class that represents a single section in the list of sections in the object fil...
Definition: ObjectFile.h:81
uint64_t getIndex() const
Definition: ObjectFile.h:523
bool isCompressed() const
Definition: ObjectFile.h:544
uint64_t getAddress() const
Definition: ObjectFile.h:519
Expected< StringRef > getName() const
Definition: ObjectFile.h:515
virtual basic_symbol_iterator symbol_end() const =0
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
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.
Definition: raw_ostream.h:283
StringRef FormatString(DwarfFormat Format)
Definition: Dwarf.cpp:826
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
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.
Definition: Dwarf.h:91
@ DWARF32
Definition: Dwarf.h:91
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.
Definition: Dwarf.h:730
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)
Definition: Error.h:84
bool(*)(uint64_t) SupportsRelocation
std::pair< SupportsRelocation, RelocationResolver > getRelocationResolver(const ObjectFile &Obj)
StringRef extension(StringRef path, Style style=Style::native)
Get extension.
Definition: Path.cpp:592
SmartMutex< false > Mutex
Mutex - A standard, always enforced mutex.
Definition: Mutex.h:66
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:440
@ Length
Definition: DWP.cpp:440
void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner={})
Log all errors (if any) in E to OS.
Definition: Error.cpp:65
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1747
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition: Error.cpp:90
void append_range(Container &C, Range &&R)
Wrapper function to append a range to a container.
Definition: STLExtras.h:2037
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.
Definition: LEB128.h:161
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition: Error.h:1244
@ DW_SECT_EXT_TYPES
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:1652
static Error createError(const Twine &Err)
Definition: APFloat.cpp:357
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:125
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...
Definition: DIContext.h:140
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1854
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
Definition: Error.cpp:103
@ DIDT_ID_Count
Definition: DIContext.h:176
@ DIDT_All
Definition: DIContext.h:183
@ DIDT_UUID
Definition: DIContext.h:188
void consumeError(Error Err)
Consume a Error without doing anything.
Definition: Error.h:1041
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
SymInfo contains information about symbol: it's address and section index which is -1LL for absolute ...
uint64_t Address
uint64_t SectionIndex
Container for dump options that control which debug information will be dumped.
Definition: DIContext.h:193
std::function< void(Error)> WarningHandler
Definition: DIContext.h:230
std::function< void(Error)> RecoverableErrorHandler
Definition: DIContext.h:228
DIDumpOptions noImplicitRecursion() const
Return the options with RecurseDepth set to 0 unless explicitly required.
Definition: DIContext.h:219
Controls which fields of DILineInfo container should be filled with data.
Definition: DIContext.h:144
DINameKind FunctionNameKind
Definition: DIContext.h:155
A format-neutral container for source line information.
Definition: DIContext.h:32
static constexpr const char *const BadString
Definition: DIContext.h:34
std::optional< uint64_t > StartAddress
Definition: DIContext.h:48
uint32_t Discriminator
Definition: DIContext.h:51
uint32_t Line
Definition: DIContext.h:45
std::string FileName
Definition: DIContext.h:37
std::string FunctionName
Definition: DIContext.h:38
uint32_t Column
Definition: DIContext.h:46
uint32_t StartLine
Definition: DIContext.h:47
std::string StartFileName
Definition: DIContext.h:39
Wraps the returned DIEs for a given address.
Definition: DWARFContext.h:363
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.
Definition: DWARFRelocMap.h:21
std::optional< object::RelocationRef > Reloc2
Definition: DWARFRelocMap.h:25