1 //===- DWARFUnit.cpp ------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "llvm/DebugInfo/DWARF/DWARFUnit.h"
10 #include "llvm/ADT/SmallString.h"
11 #include "llvm/ADT/StringRef.h"
12 #include "llvm/BinaryFormat/Dwarf.h"
13 #include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h"
14 #include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h"
15 #include "llvm/DebugInfo/DWARF/DWARFContext.h"
16 #include "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h"
17 #include "llvm/DebugInfo/DWARF/DWARFDebugInfoEntry.h"
18 #include "llvm/DebugInfo/DWARF/DWARFDebugLoc.h"
19 #include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h"
20 #include "llvm/DebugInfo/DWARF/DWARFDebugRnglists.h"
21 #include "llvm/DebugInfo/DWARF/DWARFDie.h"
22 #include "llvm/DebugInfo/DWARF/DWARFExpression.h"
23 #include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
24 #include "llvm/DebugInfo/DWARF/DWARFListTable.h"
25 #include "llvm/DebugInfo/DWARF/DWARFObject.h"
26 #include "llvm/DebugInfo/DWARF/DWARFSection.h"
27 #include "llvm/DebugInfo/DWARF/DWARFTypeUnit.h"
28 #include "llvm/Object/ObjectFile.h"
29 #include "llvm/Support/DataExtractor.h"
30 #include "llvm/Support/Errc.h"
31 #include "llvm/Support/Path.h"
40 using namespace dwarf
;
42 void DWARFUnitVector::addUnitsForSection(DWARFContext
&C
,
43 const DWARFSection
&Section
,
44 DWARFSectionKind SectionKind
) {
45 const DWARFObject
&D
= C
.getDWARFObj();
46 addUnitsImpl(C
, D
, Section
, C
.getDebugAbbrev(), &D
.getRangesSection(),
47 &D
.getLocSection(), D
.getStrSection(),
48 D
.getStrOffsetsSection(), &D
.getAddrSection(),
49 D
.getLineSection(), D
.isLittleEndian(), false, false,
53 void DWARFUnitVector::addUnitsForDWOSection(DWARFContext
&C
,
54 const DWARFSection
&DWOSection
,
55 DWARFSectionKind SectionKind
,
57 const DWARFObject
&D
= C
.getDWARFObj();
58 addUnitsImpl(C
, D
, DWOSection
, C
.getDebugAbbrevDWO(), &D
.getRangesDWOSection(),
59 &D
.getLocDWOSection(), D
.getStrDWOSection(),
60 D
.getStrOffsetsDWOSection(), &D
.getAddrSection(),
61 D
.getLineDWOSection(), C
.isLittleEndian(), true, Lazy
,
65 void DWARFUnitVector::addUnitsImpl(
66 DWARFContext
&Context
, const DWARFObject
&Obj
, const DWARFSection
&Section
,
67 const DWARFDebugAbbrev
*DA
, const DWARFSection
*RS
,
68 const DWARFSection
*LocSection
, StringRef SS
, const DWARFSection
&SOS
,
69 const DWARFSection
*AOS
, const DWARFSection
&LS
, bool LE
, bool IsDWO
,
70 bool Lazy
, DWARFSectionKind SectionKind
) {
71 DWARFDataExtractor
Data(Obj
, Section
, LE
, 0);
72 // Lazy initialization of Parser, now that we have all section info.
74 Parser
= [=, &Context
, &Obj
, &Section
, &SOS
,
75 &LS
](uint64_t Offset
, DWARFSectionKind SectionKind
,
76 const DWARFSection
*CurSection
,
77 const DWARFUnitIndex::Entry
*IndexEntry
)
78 -> std::unique_ptr
<DWARFUnit
> {
79 const DWARFSection
&InfoSection
= CurSection
? *CurSection
: Section
;
80 DWARFDataExtractor
Data(Obj
, InfoSection
, LE
, 0);
81 if (!Data
.isValidOffset(Offset
))
83 DWARFUnitHeader Header
;
84 if (!Header
.extract(Context
, Data
, &Offset
, SectionKind
))
86 if (!IndexEntry
&& IsDWO
) {
87 const DWARFUnitIndex
&Index
= getDWARFUnitIndex(
88 Context
, Header
.isTypeUnit() ? DW_SECT_EXT_TYPES
: DW_SECT_INFO
);
90 if (Header
.isTypeUnit())
91 IndexEntry
= Index
.getFromHash(Header
.getTypeHash());
92 else if (auto DWOId
= Header
.getDWOId())
93 IndexEntry
= Index
.getFromHash(*DWOId
);
96 IndexEntry
= Index
.getFromOffset(Header
.getOffset());
98 if (IndexEntry
&& !Header
.applyIndexEntry(IndexEntry
))
100 std::unique_ptr
<DWARFUnit
> U
;
101 if (Header
.isTypeUnit())
102 U
= std::make_unique
<DWARFTypeUnit
>(Context
, InfoSection
, Header
, DA
,
103 RS
, LocSection
, SS
, SOS
, AOS
, LS
,
106 U
= std::make_unique
<DWARFCompileUnit
>(Context
, InfoSection
, Header
,
107 DA
, RS
, LocSection
, SS
, SOS
,
108 AOS
, LS
, LE
, IsDWO
, *this);
114 // Find a reasonable insertion point within the vector. We skip over
115 // (a) units from a different section, (b) units from the same section
116 // but with lower offset-within-section. This keeps units in order
117 // within a section, although not necessarily within the object file,
118 // even if we do lazy parsing.
119 auto I
= this->begin();
121 while (Data
.isValidOffset(Offset
)) {
122 if (I
!= this->end() &&
123 (&(*I
)->getInfoSection() != &Section
|| (*I
)->getOffset() == Offset
)) {
127 auto U
= Parser(Offset
, SectionKind
, &Section
, nullptr);
128 // If parsing failed, we're done with this section.
131 Offset
= U
->getNextUnitOffset();
132 I
= std::next(this->insert(I
, std::move(U
)));
136 DWARFUnit
*DWARFUnitVector::addUnit(std::unique_ptr
<DWARFUnit
> Unit
) {
137 auto I
= llvm::upper_bound(*this, Unit
,
138 [](const std::unique_ptr
<DWARFUnit
> &LHS
,
139 const std::unique_ptr
<DWARFUnit
> &RHS
) {
140 return LHS
->getOffset() < RHS
->getOffset();
142 return this->insert(I
, std::move(Unit
))->get();
145 DWARFUnit
*DWARFUnitVector::getUnitForOffset(uint64_t Offset
) const {
146 auto end
= begin() + getNumInfoUnits();
148 std::upper_bound(begin(), end
, Offset
,
149 [](uint64_t LHS
, const std::unique_ptr
<DWARFUnit
> &RHS
) {
150 return LHS
< RHS
->getNextUnitOffset();
152 if (CU
!= end
&& (*CU
)->getOffset() <= Offset
)
158 DWARFUnitVector::getUnitForIndexEntry(const DWARFUnitIndex::Entry
&E
) {
159 const auto *CUOff
= E
.getContribution(DW_SECT_INFO
);
163 uint64_t Offset
= CUOff
->getOffset();
164 auto end
= begin() + getNumInfoUnits();
167 std::upper_bound(begin(), end
, CUOff
->getOffset(),
168 [](uint64_t LHS
, const std::unique_ptr
<DWARFUnit
> &RHS
) {
169 return LHS
< RHS
->getNextUnitOffset();
171 if (CU
!= end
&& (*CU
)->getOffset() <= Offset
)
177 auto U
= Parser(Offset
, DW_SECT_INFO
, nullptr, &E
);
181 auto *NewCU
= U
.get();
182 this->insert(CU
, std::move(U
));
187 DWARFUnit::DWARFUnit(DWARFContext
&DC
, const DWARFSection
&Section
,
188 const DWARFUnitHeader
&Header
, const DWARFDebugAbbrev
*DA
,
189 const DWARFSection
*RS
, const DWARFSection
*LocSection
,
190 StringRef SS
, const DWARFSection
&SOS
,
191 const DWARFSection
*AOS
, const DWARFSection
&LS
, bool LE
,
192 bool IsDWO
, const DWARFUnitVector
&UnitVector
)
193 : Context(DC
), InfoSection(Section
), Header(Header
), Abbrev(DA
),
194 RangeSection(RS
), LineSection(LS
), StringSection(SS
),
195 StringOffsetSection(SOS
), AddrOffsetSection(AOS
), IsLittleEndian(LE
),
196 IsDWO(IsDWO
), UnitVector(UnitVector
) {
200 DWARFUnit::~DWARFUnit() = default;
202 DWARFDataExtractor
DWARFUnit::getDebugInfoExtractor() const {
203 return DWARFDataExtractor(Context
.getDWARFObj(), InfoSection
, IsLittleEndian
,
204 getAddressByteSize());
207 std::optional
<object::SectionedAddress
>
208 DWARFUnit::getAddrOffsetSectionItem(uint32_t Index
) const {
209 if (!AddrOffsetSectionBase
) {
210 auto R
= Context
.info_section_units();
211 // Surprising if a DWO file has more than one skeleton unit in it - this
212 // probably shouldn't be valid, but if a use case is found, here's where to
213 // support it (probably have to linearly search for the matching skeleton CU
215 if (IsDWO
&& hasSingleElement(R
))
216 return (*R
.begin())->getAddrOffsetSectionItem(Index
);
221 uint64_t Offset
= *AddrOffsetSectionBase
+ Index
* getAddressByteSize();
222 if (AddrOffsetSection
->Data
.size() < Offset
+ getAddressByteSize())
224 DWARFDataExtractor
DA(Context
.getDWARFObj(), *AddrOffsetSection
,
225 IsLittleEndian
, getAddressByteSize());
227 uint64_t Address
= DA
.getRelocatedAddress(&Offset
, &Section
);
228 return {{Address
, Section
}};
231 Expected
<uint64_t> DWARFUnit::getStringOffsetSectionItem(uint32_t Index
) const {
232 if (!StringOffsetsTableContribution
)
233 return make_error
<StringError
>(
234 "DW_FORM_strx used without a valid string offsets table",
235 inconvertibleErrorCode());
236 unsigned ItemSize
= getDwarfStringOffsetsByteSize();
237 uint64_t Offset
= getStringOffsetsBase() + Index
* ItemSize
;
238 if (StringOffsetSection
.Data
.size() < Offset
+ ItemSize
)
239 return make_error
<StringError
>("DW_FORM_strx uses index " + Twine(Index
) +
240 ", which is too large",
241 inconvertibleErrorCode());
242 DWARFDataExtractor
DA(Context
.getDWARFObj(), StringOffsetSection
,
244 return DA
.getRelocatedValue(ItemSize
, &Offset
);
247 bool DWARFUnitHeader::extract(DWARFContext
&Context
,
248 const DWARFDataExtractor
&debug_info
,
249 uint64_t *offset_ptr
,
250 DWARFSectionKind SectionKind
) {
251 Offset
= *offset_ptr
;
252 Error Err
= Error::success();
253 IndexEntry
= nullptr;
254 std::tie(Length
, FormParams
.Format
) =
255 debug_info
.getInitialLength(offset_ptr
, &Err
);
256 FormParams
.Version
= debug_info
.getU16(offset_ptr
, &Err
);
257 if (FormParams
.Version
>= 5) {
258 UnitType
= debug_info
.getU8(offset_ptr
, &Err
);
259 FormParams
.AddrSize
= debug_info
.getU8(offset_ptr
, &Err
);
260 AbbrOffset
= debug_info
.getRelocatedValue(
261 FormParams
.getDwarfOffsetByteSize(), offset_ptr
, nullptr, &Err
);
263 AbbrOffset
= debug_info
.getRelocatedValue(
264 FormParams
.getDwarfOffsetByteSize(), offset_ptr
, nullptr, &Err
);
265 FormParams
.AddrSize
= debug_info
.getU8(offset_ptr
, &Err
);
266 // Fake a unit type based on the section type. This isn't perfect,
267 // but distinguishing compile and type units is generally enough.
268 if (SectionKind
== DW_SECT_EXT_TYPES
)
269 UnitType
= DW_UT_type
;
271 UnitType
= DW_UT_compile
;
274 TypeHash
= debug_info
.getU64(offset_ptr
, &Err
);
275 TypeOffset
= debug_info
.getUnsigned(
276 offset_ptr
, FormParams
.getDwarfOffsetByteSize(), &Err
);
277 } else if (UnitType
== DW_UT_split_compile
|| UnitType
== DW_UT_skeleton
)
278 DWOId
= debug_info
.getU64(offset_ptr
, &Err
);
281 Context
.getWarningHandler()(joinErrors(
283 errc::invalid_argument
,
284 "DWARF unit at 0x%8.8" PRIx64
" cannot be parsed:", Offset
),
289 // Header fields all parsed, capture the size of this unit header.
290 assert(*offset_ptr
- Offset
<= 255 && "unexpected header size");
291 Size
= uint8_t(*offset_ptr
- Offset
);
292 uint64_t NextCUOffset
= Offset
+ getUnitLengthFieldByteSize() + getLength();
294 if (!debug_info
.isValidOffset(getNextUnitOffset() - 1)) {
295 Context
.getWarningHandler()(
296 createStringError(errc::invalid_argument
,
297 "DWARF unit from offset 0x%8.8" PRIx64
" incl. "
298 "to offset 0x%8.8" PRIx64
" excl. "
299 "extends past section size 0x%8.8zx",
300 Offset
, NextCUOffset
, debug_info
.size()));
304 if (!DWARFContext::isSupportedVersion(getVersion())) {
305 Context
.getWarningHandler()(createStringError(
306 errc::invalid_argument
,
307 "DWARF unit at offset 0x%8.8" PRIx64
" "
308 "has unsupported version %" PRIu16
", supported are 2-%u",
309 Offset
, getVersion(), DWARFContext::getMaxSupportedVersion()));
313 // Type offset is unit-relative; should be after the header and before
314 // the end of the current unit.
315 if (isTypeUnit() && TypeOffset
< Size
) {
316 Context
.getWarningHandler()(
317 createStringError(errc::invalid_argument
,
318 "DWARF type unit at offset "
320 "has its relocated type_offset 0x%8.8" PRIx64
" "
321 "pointing inside the header",
322 Offset
, Offset
+ TypeOffset
));
326 TypeOffset
>= getUnitLengthFieldByteSize() + getLength()) {
327 Context
.getWarningHandler()(createStringError(
328 errc::invalid_argument
,
329 "DWARF type unit from offset 0x%8.8" PRIx64
" incl. "
330 "to offset 0x%8.8" PRIx64
" excl. has its "
331 "relocated type_offset 0x%8.8" PRIx64
" pointing past the unit end",
332 Offset
, NextCUOffset
, Offset
+ TypeOffset
));
336 if (Error SizeErr
= DWARFContext::checkAddressSizeSupported(
337 getAddressByteSize(), errc::invalid_argument
,
338 "DWARF unit at offset 0x%8.8" PRIx64
, Offset
)) {
339 Context
.getWarningHandler()(std::move(SizeErr
));
343 // Keep track of the highest DWARF version we encounter across all units.
344 Context
.setMaxVersionIfGreater(getVersion());
348 bool DWARFUnitHeader::applyIndexEntry(const DWARFUnitIndex::Entry
*Entry
) {
354 auto *UnitContrib
= IndexEntry
->getContribution();
356 UnitContrib
->getLength() != (getLength() + getUnitLengthFieldByteSize()))
358 auto *AbbrEntry
= IndexEntry
->getContribution(DW_SECT_ABBREV
);
361 AbbrOffset
= AbbrEntry
->getOffset();
365 Error
DWARFUnit::extractRangeList(uint64_t RangeListOffset
,
366 DWARFDebugRangeList
&RangeList
) const {
367 // Require that compile unit is extracted.
368 assert(!DieArray
.empty());
369 DWARFDataExtractor
RangesData(Context
.getDWARFObj(), *RangeSection
,
370 IsLittleEndian
, getAddressByteSize());
371 uint64_t ActualRangeListOffset
= RangeSectionBase
+ RangeListOffset
;
372 return RangeList
.extract(RangesData
, &ActualRangeListOffset
);
375 void DWARFUnit::clear() {
378 RangeSectionBase
= 0;
380 AddrOffsetSectionBase
= std::nullopt
;
389 const char *DWARFUnit::getCompilationDir() {
390 return dwarf::toString(getUnitDIE().find(DW_AT_comp_dir
), nullptr);
393 void DWARFUnit::extractDIEsToVector(
394 bool AppendCUDie
, bool AppendNonCUDies
,
395 std::vector
<DWARFDebugInfoEntry
> &Dies
) const {
396 if (!AppendCUDie
&& !AppendNonCUDies
)
399 // Set the offset to that of the first DIE and calculate the start of the
400 // next compilation unit header.
401 uint64_t DIEOffset
= getOffset() + getHeaderSize();
402 uint64_t NextCUOffset
= getNextUnitOffset();
403 DWARFDebugInfoEntry DIE
;
404 DWARFDataExtractor DebugInfoData
= getDebugInfoExtractor();
405 // The end offset has been already checked by DWARFUnitHeader::extract.
406 assert(DebugInfoData
.isValidOffset(NextCUOffset
- 1));
407 std::vector
<uint32_t> Parents
;
408 std::vector
<uint32_t> PrevSiblings
;
412 ((AppendCUDie
&& Dies
.empty()) || (!AppendCUDie
&& Dies
.size() == 1)) &&
413 "Dies array is not empty");
415 // Fill Parents and Siblings stacks with initial value.
416 Parents
.push_back(UINT32_MAX
);
418 Parents
.push_back(0);
419 PrevSiblings
.push_back(0);
421 // Start to extract dies.
423 assert(Parents
.size() > 0 && "Empty parents stack");
424 assert((Parents
.back() == UINT32_MAX
|| Parents
.back() <= Dies
.size()) &&
425 "Wrong parent index");
427 // Extract die. Stop if any error occurred.
428 if (!DIE
.extractFast(*this, &DIEOffset
, DebugInfoData
, NextCUOffset
,
432 // If previous sibling is remembered then update it`s SiblingIdx field.
433 if (PrevSiblings
.back() > 0) {
434 assert(PrevSiblings
.back() < Dies
.size() &&
435 "Previous sibling index is out of Dies boundaries");
436 Dies
[PrevSiblings
.back()].setSiblingIdx(Dies
.size());
439 // Store die into the Dies vector.
443 if (!AppendNonCUDies
)
445 // The average bytes per DIE entry has been seen to be
446 // around 14-20 so let's pre-reserve the needed memory for
447 // our DIE entries accordingly.
448 Dies
.reserve(Dies
.size() + getDebugInfoSize() / 14);
450 // Remember last previous sibling.
451 PrevSiblings
.back() = Dies
.size();
456 // Check for new children scope.
457 if (const DWARFAbbreviationDeclaration
*AbbrDecl
=
458 DIE
.getAbbreviationDeclarationPtr()) {
459 if (AbbrDecl
->hasChildren()) {
460 if (AppendCUDie
|| !IsCUDie
) {
461 assert(Dies
.size() > 0 && "Dies does not contain any die");
462 Parents
.push_back(Dies
.size() - 1);
463 PrevSiblings
.push_back(0);
466 // Stop if we have single compile unit die w/o children.
469 // NULL DIE: finishes current children scope.
471 PrevSiblings
.pop_back();
477 // Stop when compile unit die is removed from the parents stack.
478 } while (Parents
.size() > 1);
481 void DWARFUnit::extractDIEsIfNeeded(bool CUDieOnly
) {
482 if (Error e
= tryExtractDIEsIfNeeded(CUDieOnly
))
483 Context
.getRecoverableErrorHandler()(std::move(e
));
486 Error
DWARFUnit::tryExtractDIEsIfNeeded(bool CUDieOnly
) {
487 if ((CUDieOnly
&& !DieArray
.empty()) ||
489 return Error::success(); // Already parsed.
491 bool HasCUDie
= !DieArray
.empty();
492 extractDIEsToVector(!HasCUDie
, !CUDieOnly
, DieArray
);
494 if (DieArray
.empty())
495 return Error::success();
497 // If CU DIE was just parsed, copy several attribute values from it.
499 return Error::success();
501 DWARFDie
UnitDie(this, &DieArray
[0]);
502 if (std::optional
<uint64_t> DWOId
=
503 toUnsigned(UnitDie
.find(DW_AT_GNU_dwo_id
)))
504 Header
.setDWOId(*DWOId
);
506 assert(AddrOffsetSectionBase
== std::nullopt
);
507 assert(RangeSectionBase
== 0);
508 assert(LocSectionBase
== 0);
509 AddrOffsetSectionBase
= toSectionOffset(UnitDie
.find(DW_AT_addr_base
));
510 if (!AddrOffsetSectionBase
)
511 AddrOffsetSectionBase
=
512 toSectionOffset(UnitDie
.find(DW_AT_GNU_addr_base
));
513 RangeSectionBase
= toSectionOffset(UnitDie
.find(DW_AT_rnglists_base
), 0);
514 LocSectionBase
= toSectionOffset(UnitDie
.find(DW_AT_loclists_base
), 0);
517 // In general, in DWARF v5 and beyond we derive the start of the unit's
518 // contribution to the string offsets table from the unit DIE's
519 // DW_AT_str_offsets_base attribute. Split DWARF units do not use this
520 // attribute, so we assume that there is a contribution to the string
521 // offsets table starting at offset 0 of the debug_str_offsets.dwo section.
522 // In both cases we need to determine the format of the contribution,
523 // which may differ from the unit's format.
524 DWARFDataExtractor
DA(Context
.getDWARFObj(), StringOffsetSection
,
526 if (IsDWO
|| getVersion() >= 5) {
527 auto StringOffsetOrError
=
528 IsDWO
? determineStringOffsetsTableContributionDWO(DA
)
529 : determineStringOffsetsTableContribution(DA
);
530 if (!StringOffsetOrError
)
531 return createStringError(errc::invalid_argument
,
532 "invalid reference to or invalid content in "
533 ".debug_str_offsets[.dwo]: " +
534 toString(StringOffsetOrError
.takeError()));
536 StringOffsetsTableContribution
= *StringOffsetOrError
;
539 // DWARF v5 uses the .debug_rnglists and .debug_rnglists.dwo sections to
540 // describe address ranges.
541 if (getVersion() >= 5) {
542 // In case of DWP, the base offset from the index has to be added.
544 uint64_t ContributionBaseOffset
= 0;
545 if (auto *IndexEntry
= Header
.getIndexEntry())
546 if (auto *Contrib
= IndexEntry
->getContribution(DW_SECT_RNGLISTS
))
547 ContributionBaseOffset
= Contrib
->getOffset();
549 &Context
.getDWARFObj().getRnglistsDWOSection(),
550 ContributionBaseOffset
+
551 DWARFListTableHeader::getHeaderSize(Header
.getFormat()));
553 setRangesSection(&Context
.getDWARFObj().getRnglistsSection(),
554 toSectionOffset(UnitDie
.find(DW_AT_rnglists_base
),
555 DWARFListTableHeader::getHeaderSize(
556 Header
.getFormat())));
560 // If we are reading a package file, we need to adjust the location list
561 // data based on the index entries.
562 StringRef Data
= Header
.getVersion() >= 5
563 ? Context
.getDWARFObj().getLoclistsDWOSection().Data
564 : Context
.getDWARFObj().getLocDWOSection().Data
;
565 if (auto *IndexEntry
= Header
.getIndexEntry())
566 if (const auto *C
= IndexEntry
->getContribution(
567 Header
.getVersion() >= 5 ? DW_SECT_LOCLISTS
: DW_SECT_EXT_LOC
))
568 Data
= Data
.substr(C
->getOffset(), C
->getLength());
570 DWARFDataExtractor
DWARFData(Data
, IsLittleEndian
, getAddressByteSize());
572 std::make_unique
<DWARFDebugLoclists
>(DWARFData
, Header
.getVersion());
573 LocSectionBase
= DWARFListTableHeader::getHeaderSize(Header
.getFormat());
574 } else if (getVersion() >= 5) {
575 LocTable
= std::make_unique
<DWARFDebugLoclists
>(
576 DWARFDataExtractor(Context
.getDWARFObj(),
577 Context
.getDWARFObj().getLoclistsSection(),
578 IsLittleEndian
, getAddressByteSize()),
581 LocTable
= std::make_unique
<DWARFDebugLoc
>(DWARFDataExtractor(
582 Context
.getDWARFObj(), Context
.getDWARFObj().getLocSection(),
583 IsLittleEndian
, getAddressByteSize()));
586 // Don't fall back to DW_AT_GNU_ranges_base: it should be ignored for
587 // skeleton CU DIE, so that DWARF users not aware of it are not broken.
588 return Error::success();
591 bool DWARFUnit::parseDWO(StringRef DWOAlternativeLocation
) {
596 DWARFDie UnitDie
= getUnitDIE();
599 auto DWOFileName
= getVersion() >= 5
600 ? dwarf::toString(UnitDie
.find(DW_AT_dwo_name
))
601 : dwarf::toString(UnitDie
.find(DW_AT_GNU_dwo_name
));
604 auto CompilationDir
= dwarf::toString(UnitDie
.find(DW_AT_comp_dir
));
605 SmallString
<16> AbsolutePath
;
606 if (sys::path::is_relative(*DWOFileName
) && CompilationDir
&&
608 sys::path::append(AbsolutePath
, *CompilationDir
);
610 sys::path::append(AbsolutePath
, *DWOFileName
);
611 auto DWOId
= getDWOId();
614 auto DWOContext
= Context
.getDWOContext(AbsolutePath
);
616 // Use the alternative location to get the DWARF context for the DWO object.
617 if (DWOAlternativeLocation
.empty())
619 // If the alternative context does not correspond to the original DWO object
620 // (different hashes), the below 'getDWOCompileUnitForHash' call will catch
621 // the issue, with a returned null context.
622 DWOContext
= Context
.getDWOContext(DWOAlternativeLocation
);
627 DWARFCompileUnit
*DWOCU
= DWOContext
->getDWOCompileUnitForHash(*DWOId
);
630 DWO
= std::shared_ptr
<DWARFCompileUnit
>(std::move(DWOContext
), DWOCU
);
631 DWO
->setSkeletonUnit(this);
632 // Share .debug_addr and .debug_ranges section with compile unit in .dwo
633 if (AddrOffsetSectionBase
)
634 DWO
->setAddrOffsetSection(AddrOffsetSection
, *AddrOffsetSectionBase
);
635 if (getVersion() == 4) {
636 auto DWORangesBase
= UnitDie
.getRangesBaseAttribute();
637 DWO
->setRangesSection(RangeSection
, DWORangesBase
.value_or(0));
643 void DWARFUnit::clearDIEs(bool KeepCUDie
) {
644 // Do not use resize() + shrink_to_fit() to free memory occupied by dies.
645 // shrink_to_fit() is a *non-binding* request to reduce capacity() to size().
646 // It depends on the implementation whether the request is fulfilled.
647 // Create a new vector with a small capacity and assign it to the DieArray to
648 // have previous contents freed.
649 DieArray
= (KeepCUDie
&& !DieArray
.empty())
650 ? std::vector
<DWARFDebugInfoEntry
>({DieArray
[0]})
651 : std::vector
<DWARFDebugInfoEntry
>();
654 Expected
<DWARFAddressRangesVector
>
655 DWARFUnit::findRnglistFromOffset(uint64_t Offset
) {
656 if (getVersion() <= 4) {
657 DWARFDebugRangeList RangeList
;
658 if (Error E
= extractRangeList(Offset
, RangeList
))
660 return RangeList
.getAbsoluteRanges(getBaseAddress());
662 DWARFDataExtractor
RangesData(Context
.getDWARFObj(), *RangeSection
,
663 IsLittleEndian
, Header
.getAddressByteSize());
664 DWARFDebugRnglistTable RnglistTable
;
665 auto RangeListOrError
= RnglistTable
.findList(RangesData
, Offset
);
666 if (RangeListOrError
)
667 return RangeListOrError
.get().getAbsoluteRanges(getBaseAddress(), *this);
668 return RangeListOrError
.takeError();
671 Expected
<DWARFAddressRangesVector
>
672 DWARFUnit::findRnglistFromIndex(uint32_t Index
) {
673 if (auto Offset
= getRnglistOffset(Index
))
674 return findRnglistFromOffset(*Offset
);
676 return createStringError(errc::invalid_argument
,
677 "invalid range list table index %d (possibly "
678 "missing the entire range list table)",
682 Expected
<DWARFAddressRangesVector
> DWARFUnit::collectAddressRanges() {
683 DWARFDie UnitDie
= getUnitDIE();
685 return createStringError(errc::invalid_argument
, "No unit DIE");
687 // First, check if unit DIE describes address ranges for the whole unit.
688 auto CUDIERangesOrError
= UnitDie
.getAddressRanges();
689 if (!CUDIERangesOrError
)
690 return createStringError(errc::invalid_argument
,
691 "decoding address ranges: %s",
692 toString(CUDIERangesOrError
.takeError()).c_str());
693 return *CUDIERangesOrError
;
696 Expected
<DWARFLocationExpressionsVector
>
697 DWARFUnit::findLoclistFromOffset(uint64_t Offset
) {
698 DWARFLocationExpressionsVector Result
;
700 Error InterpretationError
= Error::success();
702 Error ParseError
= getLocationTable().visitAbsoluteLocationList(
703 Offset
, getBaseAddress(),
704 [this](uint32_t Index
) { return getAddrOffsetSectionItem(Index
); },
705 [&](Expected
<DWARFLocationExpression
> L
) {
707 Result
.push_back(std::move(*L
));
709 InterpretationError
=
710 joinErrors(L
.takeError(), std::move(InterpretationError
));
711 return !InterpretationError
;
714 if (ParseError
|| InterpretationError
)
715 return joinErrors(std::move(ParseError
), std::move(InterpretationError
));
720 void DWARFUnit::updateAddressDieMap(DWARFDie Die
) {
721 if (Die
.isSubroutineDIE()) {
722 auto DIERangesOrError
= Die
.getAddressRanges();
723 if (DIERangesOrError
) {
724 for (const auto &R
: DIERangesOrError
.get()) {
725 // Ignore 0-sized ranges.
726 if (R
.LowPC
== R
.HighPC
)
728 auto B
= AddrDieMap
.upper_bound(R
.LowPC
);
729 if (B
!= AddrDieMap
.begin() && R
.LowPC
< (--B
)->second
.first
) {
730 // The range is a sub-range of existing ranges, we need to split the
732 if (R
.HighPC
< B
->second
.first
)
733 AddrDieMap
[R
.HighPC
] = B
->second
;
734 if (R
.LowPC
> B
->first
)
735 AddrDieMap
[B
->first
].first
= R
.LowPC
;
737 AddrDieMap
[R
.LowPC
] = std::make_pair(R
.HighPC
, Die
);
740 llvm::consumeError(DIERangesOrError
.takeError());
742 // Parent DIEs are added to the AddrDieMap prior to the Children DIEs to
743 // simplify the logic to update AddrDieMap. The child's range will always
744 // be equal or smaller than the parent's range. With this assumption, when
745 // adding one range into the map, it will at most split a range into 3
747 for (DWARFDie Child
= Die
.getFirstChild(); Child
; Child
= Child
.getSibling())
748 updateAddressDieMap(Child
);
751 DWARFDie
DWARFUnit::getSubroutineForAddress(uint64_t Address
) {
752 extractDIEsIfNeeded(false);
753 if (AddrDieMap
.empty())
754 updateAddressDieMap(getUnitDIE());
755 auto R
= AddrDieMap
.upper_bound(Address
);
756 if (R
== AddrDieMap
.begin())
758 // upper_bound's previous item contains Address.
760 if (Address
>= R
->second
.first
)
762 return R
->second
.second
;
765 void DWARFUnit::updateVariableDieMap(DWARFDie Die
) {
766 for (DWARFDie Child
: Die
) {
767 if (isType(Child
.getTag()))
769 updateVariableDieMap(Child
);
772 if (Die
.getTag() != DW_TAG_variable
)
775 Expected
<DWARFLocationExpressionsVector
> Locations
=
776 Die
.getLocations(DW_AT_location
);
778 // Missing DW_AT_location is fine here.
779 consumeError(Locations
.takeError());
783 uint64_t Address
= UINT64_MAX
;
785 for (const DWARFLocationExpression
&Location
: *Locations
) {
786 uint8_t AddressSize
= getAddressByteSize();
787 DataExtractor
Data(Location
.Expr
, /*IsLittleEndian=*/true, AddressSize
);
788 DWARFExpression
Expr(Data
, AddressSize
);
789 auto It
= Expr
.begin();
790 if (It
== Expr
.end())
793 // Match exactly the main sequence used to describe global variables:
794 // `DW_OP_addr[x] [+ DW_OP_plus_uconst]`. Currently, this is the sequence
795 // that LLVM produces for DILocalVariables and DIGlobalVariables. If, in
796 // future, the DWARF producer (`DwarfCompileUnit::addLocationAttribute()` is
797 // a good starting point) is extended to use further expressions, this code
798 // needs to be updated.
799 uint64_t LocationAddr
;
800 if (It
->getCode() == dwarf::DW_OP_addr
) {
801 LocationAddr
= It
->getRawOperand(0);
802 } else if (It
->getCode() == dwarf::DW_OP_addrx
) {
803 uint64_t DebugAddrOffset
= It
->getRawOperand(0);
804 if (auto Pointer
= getAddrOffsetSectionItem(DebugAddrOffset
)) {
805 LocationAddr
= Pointer
->Address
;
811 // Read the optional 2nd operand, a DW_OP_plus_uconst.
812 if (++It
!= Expr
.end()) {
813 if (It
->getCode() != dwarf::DW_OP_plus_uconst
)
816 LocationAddr
+= It
->getRawOperand(0);
818 // Probe for a 3rd operand, if it exists, bail.
819 if (++It
!= Expr
.end())
823 Address
= LocationAddr
;
827 // Get the size of the global variable. If all else fails (i.e. the global has
828 // no type), then we use a size of one to still allow symbolization of the
831 if (DWARFDie BaseType
= Die
.getAttributeValueAsReferencedDie(DW_AT_type
))
832 if (std::optional
<uint64_t> Size
= Die
.getTypeSize(getAddressByteSize()))
835 if (Address
!= UINT64_MAX
)
836 VariableDieMap
[Address
] = {Address
+ GVSize
, Die
};
839 DWARFDie
DWARFUnit::getVariableForAddress(uint64_t Address
) {
840 extractDIEsIfNeeded(false);
842 auto RootDie
= getUnitDIE();
844 auto RootLookup
= RootsParsedForVariables
.insert(RootDie
.getOffset());
845 if (RootLookup
.second
)
846 updateVariableDieMap(RootDie
);
848 auto R
= VariableDieMap
.upper_bound(Address
);
849 if (R
== VariableDieMap
.begin())
852 // upper_bound's previous item contains Address.
854 if (Address
>= R
->second
.first
)
856 return R
->second
.second
;
860 DWARFUnit::getInlinedChainForAddress(uint64_t Address
,
861 SmallVectorImpl
<DWARFDie
> &InlinedChain
) {
862 assert(InlinedChain
.empty());
863 // Try to look for subprogram DIEs in the DWO file.
865 // First, find the subroutine that contains the given address (the leaf
866 // of inlined chain).
867 DWARFDie SubroutineDIE
=
868 (DWO
? *DWO
: *this).getSubroutineForAddress(Address
);
870 while (SubroutineDIE
) {
871 if (SubroutineDIE
.isSubprogramDIE()) {
872 InlinedChain
.push_back(SubroutineDIE
);
875 if (SubroutineDIE
.getTag() == DW_TAG_inlined_subroutine
)
876 InlinedChain
.push_back(SubroutineDIE
);
877 SubroutineDIE
= SubroutineDIE
.getParent();
881 const DWARFUnitIndex
&llvm::getDWARFUnitIndex(DWARFContext
&Context
,
882 DWARFSectionKind Kind
) {
883 if (Kind
== DW_SECT_INFO
)
884 return Context
.getCUIndex();
885 assert(Kind
== DW_SECT_EXT_TYPES
);
886 return Context
.getTUIndex();
889 DWARFDie
DWARFUnit::getParent(const DWARFDebugInfoEntry
*Die
) {
890 if (const DWARFDebugInfoEntry
*Entry
= getParentEntry(Die
))
891 return DWARFDie(this, Entry
);
896 const DWARFDebugInfoEntry
*
897 DWARFUnit::getParentEntry(const DWARFDebugInfoEntry
*Die
) const {
900 assert(Die
>= DieArray
.data() && Die
< DieArray
.data() + DieArray
.size());
902 if (std::optional
<uint32_t> ParentIdx
= Die
->getParentIdx()) {
903 assert(*ParentIdx
< DieArray
.size() &&
904 "ParentIdx is out of DieArray boundaries");
905 return getDebugInfoEntry(*ParentIdx
);
911 DWARFDie
DWARFUnit::getSibling(const DWARFDebugInfoEntry
*Die
) {
912 if (const DWARFDebugInfoEntry
*Sibling
= getSiblingEntry(Die
))
913 return DWARFDie(this, Sibling
);
918 const DWARFDebugInfoEntry
*
919 DWARFUnit::getSiblingEntry(const DWARFDebugInfoEntry
*Die
) const {
922 assert(Die
>= DieArray
.data() && Die
< DieArray
.data() + DieArray
.size());
924 if (std::optional
<uint32_t> SiblingIdx
= Die
->getSiblingIdx()) {
925 assert(*SiblingIdx
< DieArray
.size() &&
926 "SiblingIdx is out of DieArray boundaries");
927 return &DieArray
[*SiblingIdx
];
933 DWARFDie
DWARFUnit::getPreviousSibling(const DWARFDebugInfoEntry
*Die
) {
934 if (const DWARFDebugInfoEntry
*Sibling
= getPreviousSiblingEntry(Die
))
935 return DWARFDie(this, Sibling
);
940 const DWARFDebugInfoEntry
*
941 DWARFUnit::getPreviousSiblingEntry(const DWARFDebugInfoEntry
*Die
) const {
944 assert(Die
>= DieArray
.data() && Die
< DieArray
.data() + DieArray
.size());
946 std::optional
<uint32_t> ParentIdx
= Die
->getParentIdx();
948 // Die is a root die, there is no previous sibling.
951 assert(*ParentIdx
< DieArray
.size() &&
952 "ParentIdx is out of DieArray boundaries");
953 assert(getDIEIndex(Die
) > 0 && "Die is a root die");
955 uint32_t PrevDieIdx
= getDIEIndex(Die
) - 1;
956 if (PrevDieIdx
== *ParentIdx
)
957 // Immediately previous node is parent, there is no previous sibling.
960 while (DieArray
[PrevDieIdx
].getParentIdx() != *ParentIdx
) {
961 PrevDieIdx
= *DieArray
[PrevDieIdx
].getParentIdx();
963 assert(PrevDieIdx
< DieArray
.size() &&
964 "PrevDieIdx is out of DieArray boundaries");
965 assert(PrevDieIdx
>= *ParentIdx
&&
966 "PrevDieIdx is not a child of parent of Die");
969 return &DieArray
[PrevDieIdx
];
972 DWARFDie
DWARFUnit::getFirstChild(const DWARFDebugInfoEntry
*Die
) {
973 if (const DWARFDebugInfoEntry
*Child
= getFirstChildEntry(Die
))
974 return DWARFDie(this, Child
);
979 const DWARFDebugInfoEntry
*
980 DWARFUnit::getFirstChildEntry(const DWARFDebugInfoEntry
*Die
) const {
983 assert(Die
>= DieArray
.data() && Die
< DieArray
.data() + DieArray
.size());
985 if (!Die
->hasChildren())
988 // TODO: Instead of checking here for invalid die we might reject
989 // invalid dies at parsing stage(DWARFUnit::extractDIEsToVector).
990 // We do not want access out of bounds when parsing corrupted debug data.
991 size_t I
= getDIEIndex(Die
) + 1;
992 if (I
>= DieArray
.size())
997 DWARFDie
DWARFUnit::getLastChild(const DWARFDebugInfoEntry
*Die
) {
998 if (const DWARFDebugInfoEntry
*Child
= getLastChildEntry(Die
))
999 return DWARFDie(this, Child
);
1004 const DWARFDebugInfoEntry
*
1005 DWARFUnit::getLastChildEntry(const DWARFDebugInfoEntry
*Die
) const {
1008 assert(Die
>= DieArray
.data() && Die
< DieArray
.data() + DieArray
.size());
1010 if (!Die
->hasChildren())
1013 if (std::optional
<uint32_t> SiblingIdx
= Die
->getSiblingIdx()) {
1014 assert(*SiblingIdx
< DieArray
.size() &&
1015 "SiblingIdx is out of DieArray boundaries");
1016 assert(DieArray
[*SiblingIdx
- 1].getTag() == dwarf::DW_TAG_null
&&
1017 "Bad end of children marker");
1018 return &DieArray
[*SiblingIdx
- 1];
1021 // If SiblingIdx is set for non-root dies we could be sure that DWARF is
1022 // correct and "end of children marker" must be found. For root die we do not
1023 // have such a guarantee(parsing root die might be stopped if "end of children
1024 // marker" is missing, SiblingIdx is always zero for root die). That is why we
1025 // do not use assertion for checking for "end of children marker" for root
1028 // TODO: Instead of checking here for invalid die we might reject
1029 // invalid dies at parsing stage(DWARFUnit::extractDIEsToVector).
1030 if (getDIEIndex(Die
) == 0 && DieArray
.size() > 1 &&
1031 DieArray
.back().getTag() == dwarf::DW_TAG_null
) {
1032 // For the unit die we might take last item from DieArray.
1033 assert(getDIEIndex(Die
) ==
1034 getDIEIndex(const_cast<DWARFUnit
*>(this)->getUnitDIE()) &&
1036 return &DieArray
.back();
1042 const DWARFAbbreviationDeclarationSet
*DWARFUnit::getAbbreviations() const {
1044 Abbrevs
= Abbrev
->getAbbreviationDeclarationSet(getAbbreviationsOffset());
1048 std::optional
<object::SectionedAddress
> DWARFUnit::getBaseAddress() {
1052 DWARFDie UnitDie
= getUnitDIE();
1053 std::optional
<DWARFFormValue
> PC
=
1054 UnitDie
.find({DW_AT_low_pc
, DW_AT_entry_pc
});
1055 BaseAddr
= toSectionedAddress(PC
);
1059 Expected
<StrOffsetsContributionDescriptor
>
1060 StrOffsetsContributionDescriptor::validateContributionSize(
1061 DWARFDataExtractor
&DA
) {
1062 uint8_t EntrySize
= getDwarfOffsetByteSize();
1063 // In order to ensure that we don't read a partial record at the end of
1064 // the section we validate for a multiple of the entry size.
1065 uint64_t ValidationSize
= alignTo(Size
, EntrySize
);
1066 // Guard against overflow.
1067 if (ValidationSize
>= Size
)
1068 if (DA
.isValidOffsetForDataOfSize((uint32_t)Base
, ValidationSize
))
1070 return createStringError(errc::invalid_argument
, "length exceeds section size");
1073 // Look for a DWARF64-formatted contribution to the string offsets table
1074 // starting at a given offset and record it in a descriptor.
1075 static Expected
<StrOffsetsContributionDescriptor
>
1076 parseDWARF64StringOffsetsTableHeader(DWARFDataExtractor
&DA
, uint64_t Offset
) {
1077 if (!DA
.isValidOffsetForDataOfSize(Offset
, 16))
1078 return createStringError(errc::invalid_argument
, "section offset exceeds section size");
1080 if (DA
.getU32(&Offset
) != dwarf::DW_LENGTH_DWARF64
)
1081 return createStringError(errc::invalid_argument
, "32 bit contribution referenced from a 64 bit unit");
1083 uint64_t Size
= DA
.getU64(&Offset
);
1084 uint8_t Version
= DA
.getU16(&Offset
);
1085 (void)DA
.getU16(&Offset
); // padding
1086 // The encoded length includes the 2-byte version field and the 2-byte
1087 // padding, so we need to subtract them out when we populate the descriptor.
1088 return StrOffsetsContributionDescriptor(Offset
, Size
- 4, Version
, DWARF64
);
1091 // Look for a DWARF32-formatted contribution to the string offsets table
1092 // starting at a given offset and record it in a descriptor.
1093 static Expected
<StrOffsetsContributionDescriptor
>
1094 parseDWARF32StringOffsetsTableHeader(DWARFDataExtractor
&DA
, uint64_t Offset
) {
1095 if (!DA
.isValidOffsetForDataOfSize(Offset
, 8))
1096 return createStringError(errc::invalid_argument
, "section offset exceeds section size");
1098 uint32_t ContributionSize
= DA
.getU32(&Offset
);
1099 if (ContributionSize
>= dwarf::DW_LENGTH_lo_reserved
)
1100 return createStringError(errc::invalid_argument
, "invalid length");
1102 uint8_t Version
= DA
.getU16(&Offset
);
1103 (void)DA
.getU16(&Offset
); // padding
1104 // The encoded length includes the 2-byte version field and the 2-byte
1105 // padding, so we need to subtract them out when we populate the descriptor.
1106 return StrOffsetsContributionDescriptor(Offset
, ContributionSize
- 4, Version
,
1110 static Expected
<StrOffsetsContributionDescriptor
>
1111 parseDWARFStringOffsetsTableHeader(DWARFDataExtractor
&DA
,
1112 llvm::dwarf::DwarfFormat Format
,
1114 StrOffsetsContributionDescriptor Desc
;
1116 case dwarf::DwarfFormat::DWARF64
: {
1118 return createStringError(errc::invalid_argument
, "insufficient space for 64 bit header prefix");
1119 auto DescOrError
= parseDWARF64StringOffsetsTableHeader(DA
, Offset
- 16);
1121 return DescOrError
.takeError();
1122 Desc
= *DescOrError
;
1125 case dwarf::DwarfFormat::DWARF32
: {
1127 return createStringError(errc::invalid_argument
, "insufficient space for 32 bit header prefix");
1128 auto DescOrError
= parseDWARF32StringOffsetsTableHeader(DA
, Offset
- 8);
1130 return DescOrError
.takeError();
1131 Desc
= *DescOrError
;
1135 return Desc
.validateContributionSize(DA
);
1138 Expected
<std::optional
<StrOffsetsContributionDescriptor
>>
1139 DWARFUnit::determineStringOffsetsTableContribution(DWARFDataExtractor
&DA
) {
1141 auto OptOffset
= toSectionOffset(getUnitDIE().find(DW_AT_str_offsets_base
));
1143 return std::nullopt
;
1145 parseDWARFStringOffsetsTableHeader(DA
, Header
.getFormat(), *OptOffset
);
1147 return DescOrError
.takeError();
1148 return *DescOrError
;
1151 Expected
<std::optional
<StrOffsetsContributionDescriptor
>>
1152 DWARFUnit::determineStringOffsetsTableContributionDWO(DWARFDataExtractor
&DA
) {
1154 uint64_t Offset
= 0;
1155 auto IndexEntry
= Header
.getIndexEntry();
1157 IndexEntry
? IndexEntry
->getContribution(DW_SECT_STR_OFFSETS
) : nullptr;
1159 Offset
= C
->getOffset();
1160 if (getVersion() >= 5) {
1161 if (DA
.getData().data() == nullptr)
1162 return std::nullopt
;
1163 Offset
+= Header
.getFormat() == dwarf::DwarfFormat::DWARF32
? 8 : 16;
1164 // Look for a valid contribution at the given offset.
1165 auto DescOrError
= parseDWARFStringOffsetsTableHeader(DA
, Header
.getFormat(), Offset
);
1167 return DescOrError
.takeError();
1168 return *DescOrError
;
1170 // Prior to DWARF v5, we derive the contribution size from the
1171 // index table (in a package file). In a .dwo file it is simply
1172 // the length of the string offsets section.
1173 StrOffsetsContributionDescriptor Desc
;
1175 Desc
= StrOffsetsContributionDescriptor(C
->getOffset(), C
->getLength(), 4,
1176 Header
.getFormat());
1177 else if (!IndexEntry
&& !StringOffsetSection
.Data
.empty())
1178 Desc
= StrOffsetsContributionDescriptor(0, StringOffsetSection
.Data
.size(),
1179 4, Header
.getFormat());
1181 return std::nullopt
;
1182 auto DescOrError
= Desc
.validateContributionSize(DA
);
1184 return DescOrError
.takeError();
1185 return *DescOrError
;
1188 std::optional
<uint64_t> DWARFUnit::getRnglistOffset(uint32_t Index
) {
1189 DataExtractor
RangesData(RangeSection
->Data
, IsLittleEndian
,
1190 getAddressByteSize());
1191 DWARFDataExtractor
RangesDA(Context
.getDWARFObj(), *RangeSection
,
1193 if (std::optional
<uint64_t> Off
= llvm::DWARFListTableHeader::getOffsetEntry(
1194 RangesData
, RangeSectionBase
, getFormat(), Index
))
1195 return *Off
+ RangeSectionBase
;
1196 return std::nullopt
;
1199 std::optional
<uint64_t> DWARFUnit::getLoclistOffset(uint32_t Index
) {
1200 if (std::optional
<uint64_t> Off
= llvm::DWARFListTableHeader::getOffsetEntry(
1201 LocTable
->getData(), LocSectionBase
, getFormat(), Index
))
1202 return *Off
+ LocSectionBase
;
1203 return std::nullopt
;