LLVM 20.0.0git
DWARFUnit.h
Go to the documentation of this file.
1//===- DWARFUnit.h ----------------------------------------------*- C++ -*-===//
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
9#ifndef LLVM_DEBUGINFO_DWARF_DWARFUNIT_H
10#define LLVM_DEBUGINFO_DWARF_DWARFUNIT_H
11
12#include "llvm/ADT/DenseSet.h"
13#include "llvm/ADT/STLExtras.h"
15#include "llvm/ADT/StringRef.h"
25#include <cassert>
26#include <cstddef>
27#include <cstdint>
28#include <map>
29#include <memory>
30#include <set>
31#include <utility>
32#include <vector>
33
34namespace llvm {
35
36class DWARFAbbreviationDeclarationSet;
37class DWARFContext;
38class DWARFDebugAbbrev;
39class DWARFUnit;
40class DWARFDebugRangeList;
41class DWARFLocationTable;
42class DWARFObject;
43class raw_ostream;
44struct DIDumpOptions;
45struct DWARFSection;
46namespace dwarf_linker {
47namespace parallel {
48class CompileUnit;
49}
50} // namespace dwarf_linker
51
52/// Base class describing the header of any kind of "unit." Some information
53/// is specific to certain unit types. We separate this class out so we can
54/// parse the header before deciding what specific kind of unit to construct.
56 // Offset within section.
57 uint64_t Offset = 0;
58 // Version, address size, and DWARF format.
59 dwarf::FormParams FormParams;
60 uint64_t Length = 0;
61 uint64_t AbbrOffset = 0;
62
63 // For DWO units only.
64 const DWARFUnitIndex::Entry *IndexEntry = nullptr;
65
66 // For type units only.
67 uint64_t TypeHash = 0;
68 uint64_t TypeOffset = 0;
69
70 // For v5 split or skeleton compile units only.
71 std::optional<uint64_t> DWOId;
72
73 // Unit type as parsed, or derived from the section kind.
74 uint8_t UnitType = 0;
75
76 // Size as parsed. uint8_t for compactness.
77 uint8_t Size = 0;
78
79public:
80 /// Parse a unit header from \p debug_info starting at \p offset_ptr.
81 /// Note that \p SectionKind is used as a hint to guess the unit type
82 /// for DWARF formats prior to DWARFv5. In DWARFv5 the unit type is
83 /// explicitly defined in the header and the hint is ignored.
84 Error extract(DWARFContext &Context, const DWARFDataExtractor &debug_info,
86 // For units in DWARF Package File, remember the index entry and update
87 // the abbreviation offset read by extract().
89 uint64_t getOffset() const { return Offset; }
90 const dwarf::FormParams &getFormParams() const { return FormParams; }
91 uint16_t getVersion() const { return FormParams.Version; }
92 dwarf::DwarfFormat getFormat() const { return FormParams.Format; }
93 uint8_t getAddressByteSize() const { return FormParams.AddrSize; }
94 uint8_t getRefAddrByteSize() const { return FormParams.getRefAddrByteSize(); }
96 return FormParams.getDwarfOffsetByteSize();
97 }
98 uint64_t getLength() const { return Length; }
99 uint64_t getAbbrOffset() const { return AbbrOffset; }
100 std::optional<uint64_t> getDWOId() const { return DWOId; }
102 assert((!DWOId || *DWOId == Id) && "setting DWOId to a different value");
103 DWOId = Id;
104 }
105 const DWARFUnitIndex::Entry *getIndexEntry() const { return IndexEntry; }
106 uint64_t getTypeHash() const { return TypeHash; }
107 uint64_t getTypeOffset() const { return TypeOffset; }
108 uint8_t getUnitType() const { return UnitType; }
109 bool isTypeUnit() const {
110 return UnitType == dwarf::DW_UT_type || UnitType == dwarf::DW_UT_split_type;
111 }
112 uint8_t getSize() const { return Size; }
114 return dwarf::getUnitLengthFieldByteSize(FormParams.Format);
115 }
117 return Offset + Length + getUnitLengthFieldByteSize();
118 }
119};
120
121const DWARFUnitIndex &getDWARFUnitIndex(DWARFContext &Context,
122 DWARFSectionKind Kind);
123
124bool isCompileUnit(const std::unique_ptr<DWARFUnit> &U);
125
126/// Describe a collection of units. Intended to hold all units either from
127/// .debug_info and .debug_types, or from .debug_info.dwo and .debug_types.dwo.
128class DWARFUnitVector final : public SmallVector<std::unique_ptr<DWARFUnit>, 1> {
129 std::function<std::unique_ptr<DWARFUnit>(uint64_t, DWARFSectionKind,
130 const DWARFSection *,
131 const DWARFUnitIndex::Entry *)>
132 Parser;
133 int NumInfoUnits = -1;
134
135public:
139
141 decltype(make_filter_range(std::declval<iterator_range>(), isCompileUnit));
142
145
146 /// Read units from a .debug_info or .debug_types section. Calls made
147 /// before finishedInfoUnits() are assumed to be for .debug_info sections,
148 /// calls after finishedInfoUnits() are for .debug_types sections. Caller
149 /// must not mix calls to addUnitsForSection and addUnitsForDWOSection.
150 void addUnitsForSection(DWARFContext &C, const DWARFSection &Section,
152 /// Read units from a .debug_info.dwo or .debug_types.dwo section. Calls
153 /// made before finishedInfoUnits() are assumed to be for .debug_info.dwo
154 /// sections, calls after finishedInfoUnits() are for .debug_types.dwo
155 /// sections. Caller must not mix calls to addUnitsForSection and
156 /// addUnitsForDWOSection.
157 void addUnitsForDWOSection(DWARFContext &C, const DWARFSection &DWOSection,
158 DWARFSectionKind SectionKind, bool Lazy = false);
159
160 /// Add an existing DWARFUnit to this UnitVector. This is used by the DWARF
161 /// verifier to process unit separately.
162 DWARFUnit *addUnit(std::unique_ptr<DWARFUnit> Unit);
163
164 /// Returns number of all units held by this instance.
165 unsigned getNumUnits() const { return size(); }
166 /// Returns number of units from all .debug_info[.dwo] sections.
167 unsigned getNumInfoUnits() const {
168 return NumInfoUnits == -1 ? size() : NumInfoUnits;
169 }
170 /// Returns number of units from all .debug_types[.dwo] sections.
171 unsigned getNumTypesUnits() const { return size() - NumInfoUnits; }
172 /// Indicate that parsing .debug_info[.dwo] is done, and remaining units
173 /// will be from .debug_types[.dwo].
174 void finishedInfoUnits() { NumInfoUnits = size(); }
175
176private:
177 void addUnitsImpl(DWARFContext &Context, const DWARFObject &Obj,
178 const DWARFSection &Section, const DWARFDebugAbbrev *DA,
179 const DWARFSection *RS, const DWARFSection *LocSection,
180 StringRef SS, const DWARFSection &SOS,
181 const DWARFSection *AOS, const DWARFSection &LS, bool LE,
182 bool IsDWO, bool Lazy, DWARFSectionKind SectionKind);
183};
184
185/// Represents base address of the CU.
186/// Represents a unit's contribution to the string offsets table.
189 /// The contribution size not including the header.
191 /// Format and version.
193
196 : Base(Base), Size(Size), FormParams({Version, 0, Format}) {}
198
203 }
204 /// Determine whether a contribution to the string offsets table is
205 /// consistent with the relevant section size and that its length is
206 /// a multiple of the size of one of its entries.
209};
210
212 DWARFContext &Context;
213 /// Section containing this DWARFUnit.
214 const DWARFSection &InfoSection;
215
216 DWARFUnitHeader Header;
217 const DWARFDebugAbbrev *Abbrev;
218 const DWARFSection *RangeSection;
219 uint64_t RangeSectionBase;
220 uint64_t LocSectionBase;
221
222 /// Location table of this unit.
223 std::unique_ptr<DWARFLocationTable> LocTable;
224
225 const DWARFSection &LineSection;
226 StringRef StringSection;
227 const DWARFSection &StringOffsetSection;
228 const DWARFSection *AddrOffsetSection;
229 DWARFUnit *SU;
230 std::optional<uint64_t> AddrOffsetSectionBase;
231 bool IsLittleEndian;
232 bool IsDWO;
233 const DWARFUnitVector &UnitVector;
234
235 /// Start, length, and DWARF format of the unit's contribution to the string
236 /// offsets table (DWARF v5).
237 std::optional<StrOffsetsContributionDescriptor>
238 StringOffsetsTableContribution;
239
240 mutable const DWARFAbbreviationDeclarationSet *Abbrevs;
241 std::optional<object::SectionedAddress> BaseAddr;
242 /// The compile unit debug information entry items.
243 std::vector<DWARFDebugInfoEntry> DieArray;
244
245 /// Map from range's start address to end address and corresponding DIE.
246 /// IntervalMap does not support range removal, as a result, we use the
247 /// std::map::upper_bound for address range lookup.
248 std::map<uint64_t, std::pair<uint64_t, DWARFDie>> AddrDieMap;
249
250 /// Map from the location (interpreted DW_AT_location) of a DW_TAG_variable,
251 /// to the end address and the corresponding DIE.
252 std::map<uint64_t, std::pair<uint64_t, DWARFDie>> VariableDieMap;
253 DenseSet<uint64_t> RootsParsedForVariables;
254
255 using die_iterator_range =
257
258 std::shared_ptr<DWARFUnit> DWO;
259
260protected:
262
263 /// Return the index of a \p Die entry inside the unit's DIE vector.
264 ///
265 /// It is illegal to call this method with a DIE that hasn't be
266 /// created by this unit. In other word, it's illegal to call this
267 /// method on a DIE that isn't accessible by following
268 /// children/sibling links starting from this unit's getUnitDIE().
270 auto First = DieArray.data();
271 assert(Die >= First && Die < First + DieArray.size());
272 return Die - First;
273 }
274
275 /// Return DWARFDebugInfoEntry for the specified index \p Index.
277 assert(Index < DieArray.size());
278 return &DieArray[Index];
279 }
280
281 const DWARFDebugInfoEntry *
282 getParentEntry(const DWARFDebugInfoEntry *Die) const;
283 const DWARFDebugInfoEntry *
284 getSiblingEntry(const DWARFDebugInfoEntry *Die) const;
285 const DWARFDebugInfoEntry *
287 const DWARFDebugInfoEntry *
288 getFirstChildEntry(const DWARFDebugInfoEntry *Die) const;
289 const DWARFDebugInfoEntry *
290 getLastChildEntry(const DWARFDebugInfoEntry *Die) const;
291
292 const DWARFUnitHeader &getHeader() const { return Header; }
293
294 /// Find the unit's contribution to the string offsets table and determine its
295 /// length and form. The given offset is expected to be derived from the unit
296 /// DIE's DW_AT_str_offsets_base attribute.
299
300 /// Find the unit's contribution to the string offsets table and determine its
301 /// length and form. The given offset is expected to be 0 in a dwo file or,
302 /// in a dwp file, the start of the unit's contribution to the string offsets
303 /// table section (as determined by the index table).
306
307public:
308 DWARFUnit(DWARFContext &Context, const DWARFSection &Section,
309 const DWARFUnitHeader &Header, const DWARFDebugAbbrev *DA,
310 const DWARFSection *RS, const DWARFSection *LocSection,
311 StringRef SS, const DWARFSection &SOS, const DWARFSection *AOS,
312 const DWARFSection &LS, bool LE, bool IsDWO,
313 const DWARFUnitVector &UnitVector);
314
315 virtual ~DWARFUnit();
316
317 bool isLittleEndian() const { return IsLittleEndian; }
318 bool isDWOUnit() const { return IsDWO; }
319 DWARFContext& getContext() const { return Context; }
320 const DWARFSection &getInfoSection() const { return InfoSection; }
321 uint64_t getOffset() const { return Header.getOffset(); }
323 return Header.getFormParams();
324 }
325 uint16_t getVersion() const { return Header.getVersion(); }
326 uint8_t getAddressByteSize() const { return Header.getAddressByteSize(); }
327 uint8_t getRefAddrByteSize() const { return Header.getRefAddrByteSize(); }
329 return Header.getDwarfOffsetByteSize();
330 }
331 /// Size in bytes of the parsed unit header.
332 uint32_t getHeaderSize() const { return Header.getSize(); }
333 uint64_t getLength() const { return Header.getLength(); }
334 dwarf::DwarfFormat getFormat() const { return Header.getFormat(); }
335 uint8_t getUnitType() const { return Header.getUnitType(); }
336 bool isTypeUnit() const { return Header.isTypeUnit(); }
337 uint64_t getAbbrOffset() const { return Header.getAbbrOffset(); }
338 uint64_t getNextUnitOffset() const { return Header.getNextUnitOffset(); }
339 const DWARFSection &getLineSection() const { return LineSection; }
340 StringRef getStringSection() const { return StringSection; }
342 return StringOffsetSection;
343 }
344
345 void setSkeletonUnit(DWARFUnit *SU) { this->SU = SU; }
346 // Returns itself if not using Split DWARF, or if the unit is a skeleton unit
347 // - otherwise returns the split full unit's corresponding skeleton, if
348 // available.
349 DWARFUnit *getLinkedUnit() { return IsDWO ? SU : this; }
350
352 AddrOffsetSection = AOS;
353 AddrOffsetSectionBase = Base;
354 }
355
356 std::optional<uint64_t> getAddrOffsetSectionBase() const {
357 return AddrOffsetSectionBase;
358 }
359
360 /// Returns offset to the indexed address value inside .debug_addr section.
361 std::optional<uint64_t> getIndexedAddressOffset(uint64_t Index) {
362 if (std::optional<uint64_t> AddrOffsetSectionBase =
364 return *AddrOffsetSectionBase + Index * getAddressByteSize();
365
366 return std::nullopt;
367 }
368
369 /// Recursively update address to Die map.
371
372 /// Recursively update address to variable Die map.
374
376 RangeSection = RS;
377 RangeSectionBase = Base;
378 }
379
381 return LocSectionBase;
382 }
383
384 std::optional<object::SectionedAddress>
387
389
391 return DataExtractor(StringSection, false, 0);
392 }
393
394 const DWARFLocationTable &getLocationTable() { return *LocTable; }
395
396 /// Extract the range list referenced by this compile unit from the
397 /// .debug_ranges section. If the extraction is unsuccessful, an error
398 /// is returned. Successful extraction requires that the compile unit
399 /// has already been extracted.
400 Error extractRangeList(uint64_t RangeListOffset,
401 DWARFDebugRangeList &RangeList) const;
402 void clear();
403
404 const std::optional<StrOffsetsContributionDescriptor> &
406 extractDIEsIfNeeded(true /*CUDIeOnly*/);
407 return StringOffsetsTableContribution;
408 }
409
411 assert(StringOffsetsTableContribution);
412 return StringOffsetsTableContribution->getDwarfOffsetByteSize();
413 }
414
416 assert(StringOffsetsTableContribution);
417 return StringOffsetsTableContribution->Base;
418 }
419
420 uint64_t getAbbreviationsOffset() const { return Header.getAbbrOffset(); }
421
423
425 switch (UnitType) {
426 case dwarf::DW_UT_compile:
427 return Tag == dwarf::DW_TAG_compile_unit;
428 case dwarf::DW_UT_type:
429 return Tag == dwarf::DW_TAG_type_unit;
430 case dwarf::DW_UT_partial:
431 return Tag == dwarf::DW_TAG_partial_unit;
432 case dwarf::DW_UT_skeleton:
433 return Tag == dwarf::DW_TAG_skeleton_unit;
434 case dwarf::DW_UT_split_compile:
435 case dwarf::DW_UT_split_type:
436 return dwarf::isUnitType(Tag);
437 }
438 return false;
439 }
440
441 std::optional<object::SectionedAddress> getBaseAddress();
442
443 DWARFDie getUnitDIE(bool ExtractUnitDIEOnly = true) {
444 extractDIEsIfNeeded(ExtractUnitDIEOnly);
445 if (DieArray.empty())
446 return DWARFDie();
447 return DWARFDie(this, &DieArray[0]);
448 }
449
450 DWARFDie getNonSkeletonUnitDIE(bool ExtractUnitDIEOnly = true,
451 StringRef DWOAlternativeLocation = {}) {
452 parseDWO(DWOAlternativeLocation);
453 return DWO ? DWO->getUnitDIE(ExtractUnitDIEOnly)
454 : getUnitDIE(ExtractUnitDIEOnly);
455 }
456
457 const char *getCompilationDir();
458 std::optional<uint64_t> getDWOId() {
459 extractDIEsIfNeeded(/*CUDieOnly*/ true);
460 return getHeader().getDWOId();
461 }
462 void setDWOId(uint64_t NewID) { Header.setDWOId(NewID); }
463
464 /// Return a vector of address ranges resulting from a (possibly encoded)
465 /// range list starting at a given offset in the appropriate ranges section.
467
468 /// Return a vector of address ranges retrieved from an encoded range
469 /// list whose offset is found via a table lookup given an index (DWARF v5
470 /// and later).
472
473 /// Return a rangelist's offset based on an index. The index designates
474 /// an entry in the rangelist table's offset array and is supplied by
475 /// DW_FORM_rnglistx.
476 std::optional<uint64_t> getRnglistOffset(uint32_t Index);
477
478 std::optional<uint64_t> getLoclistOffset(uint32_t Index);
479
481
484
485 /// Returns subprogram DIE with address range encompassing the provided
486 /// address. The pointer is alive as long as parsed compile unit DIEs are not
487 /// cleared.
489
490 /// Returns variable DIE for the address provided. The pointer is alive as
491 /// long as parsed compile unit DIEs are not cleared.
493
494 /// getInlinedChainForAddress - fetches inlined chain for a given address.
495 /// Returns empty chain if there is no subprogram containing address. The
496 /// chain is valid as long as parsed compile unit DIEs are not cleared.
498 SmallVectorImpl<DWARFDie> &InlinedChain);
499
500 /// Return the DWARFUnitVector containing this unit.
501 const DWARFUnitVector &getUnitVector() const { return UnitVector; }
502
503 /// Returns the number of DIEs in the unit. Parses the unit
504 /// if necessary.
505 unsigned getNumDIEs() {
506 extractDIEsIfNeeded(false);
507 return DieArray.size();
508 }
509
510 /// Return the index of a DIE inside the unit's DIE vector.
511 ///
512 /// It is illegal to call this method with a DIE that hasn't be
513 /// created by this unit. In other word, it's illegal to call this
514 /// method on a DIE that isn't accessible by following
515 /// children/sibling links starting from this unit's getUnitDIE().
517 return getDIEIndex(D.getDebugInfoEntry());
518 }
519
520 /// Return the DIE object at the given index \p Index.
522 return DWARFDie(this, getDebugInfoEntry(Index));
523 }
524
530
531 /// Return the DIE object for a given offset \p Offset inside the
532 /// unit's DIE vector.
534 if (std::optional<uint32_t> DieIdx = getDIEIndexForOffset(Offset))
535 return DWARFDie(this, &DieArray[*DieIdx]);
536
537 return DWARFDie();
538 }
539
540 /// Return the DIE index for a given offset \p Offset inside the
541 /// unit's DIE vector.
542 std::optional<uint32_t> getDIEIndexForOffset(uint64_t Offset) {
543 extractDIEsIfNeeded(false);
544 auto It =
545 llvm::partition_point(DieArray, [=](const DWARFDebugInfoEntry &DIE) {
546 return DIE.getOffset() < Offset;
547 });
548 if (It != DieArray.end() && It->getOffset() == Offset)
549 return It - DieArray.begin();
550 return std::nullopt;
551 }
552
554 if (auto IndexEntry = Header.getIndexEntry())
555 if (const auto *Contrib = IndexEntry->getContribution(DW_SECT_LINE))
556 return Contrib->getOffset32();
557 return 0;
558 }
559
561 extractDIEsIfNeeded(false);
562 return die_iterator_range(DieArray.begin(), DieArray.end());
563 }
564
565 virtual void dump(raw_ostream &OS, DIDumpOptions DumpOpts) = 0;
566
567 Error tryExtractDIEsIfNeeded(bool CUDieOnly);
568
569private:
570 /// Size in bytes of the .debug_info data associated with this compile unit.
571 size_t getDebugInfoSize() const {
572 return Header.getLength() + Header.getUnitLengthFieldByteSize() -
574 }
575
576 /// extractDIEsIfNeeded - Parses a compile unit and indexes its DIEs if it
577 /// hasn't already been done
578 void extractDIEsIfNeeded(bool CUDieOnly);
579
580 /// extractDIEsToVector - Appends all parsed DIEs to a vector.
581 void extractDIEsToVector(bool AppendCUDie, bool AppendNonCUDIEs,
582 std::vector<DWARFDebugInfoEntry> &DIEs) const;
583
584 /// clearDIEs - Clear parsed DIEs to keep memory usage low.
585 void clearDIEs(bool KeepCUDie);
586
587 /// parseDWO - Parses .dwo file for current compile unit. Returns true if
588 /// it was actually constructed.
589 /// The \p AlternativeLocation specifies an alternative location to get
590 /// the DWARF context for the DWO object; this is the case when it has
591 /// been moved from its original location.
592 bool parseDWO(StringRef AlternativeLocation = {});
593};
594
595inline bool isCompileUnit(const std::unique_ptr<DWARFUnit> &U) {
596 return !U->isTypeUnit();
597}
598
599} // end namespace llvm
600
601#endif // LLVM_DEBUGINFO_DWARF_DWARFUNIT_H
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file defines the DenseSet and SmallDenseSet classes.
This file contains constants used for implementing Dwarf debug support.
uint32_t Index
loop extract
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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 SmallVector class.
A structured debug information entry.
Definition: DIE.h:819
unsigned getOffset() const
Get the compile/type unit relative offset of this DIE.
Definition: DIE.h:857
DWARFContext This data structure is the top level entity that deals with dwarf debug information pars...
Definition: DWARFContext.h:48
A DataExtractor (typically for an in-memory copy of an object-file section) plus a relocation map for...
DWARFDebugInfoEntry - A DIE with only the minimum required data.
Utility class that carries the DWARF compile/type unit and the debug info entry in an object.
Definition: DWARFDie.h:42
An abstract base class for various kinds of location tables (.debug_loc, .debug_loclists,...
Definition: DWARFDebugLoc.h:49
Base class describing the header of any kind of "unit." Some information is specific to certain unit ...
Definition: DWARFUnit.h:55
std::optional< uint64_t > getDWOId() const
Definition: DWARFUnit.h:100
uint64_t getOffset() const
Definition: DWARFUnit.h:89
uint8_t getRefAddrByteSize() const
Definition: DWARFUnit.h:94
uint8_t getUnitType() const
Definition: DWARFUnit.h:108
uint8_t getDwarfOffsetByteSize() const
Definition: DWARFUnit.h:95
uint64_t getAbbrOffset() const
Definition: DWARFUnit.h:99
uint8_t getSize() const
Definition: DWARFUnit.h:112
Error applyIndexEntry(const DWARFUnitIndex::Entry *Entry)
Definition: DWARFUnit.cpp:341
dwarf::DwarfFormat getFormat() const
Definition: DWARFUnit.h:92
uint64_t getTypeHash() const
Definition: DWARFUnit.h:106
uint64_t getLength() const
Definition: DWARFUnit.h:98
uint64_t getTypeOffset() const
Definition: DWARFUnit.h:107
uint16_t getVersion() const
Definition: DWARFUnit.h:91
uint8_t getAddressByteSize() const
Definition: DWARFUnit.h:93
uint64_t getNextUnitOffset() const
Definition: DWARFUnit.h:116
uint8_t getUnitLengthFieldByteSize() const
Definition: DWARFUnit.h:113
const DWARFUnitIndex::Entry * getIndexEntry() const
Definition: DWARFUnit.h:105
bool isTypeUnit() const
Definition: DWARFUnit.h:109
void setDWOId(uint64_t Id)
Definition: DWARFUnit.h:101
const dwarf::FormParams & getFormParams() const
Definition: DWARFUnit.h:90
Describe a collection of units.
Definition: DWARFUnit.h:128
DWARFUnit * addUnit(std::unique_ptr< DWARFUnit > Unit)
Add an existing DWARFUnit to this UnitVector.
Definition: DWARFUnit.cpp:143
unsigned getNumInfoUnits() const
Returns number of units from all .debug_info[.dwo] sections.
Definition: DWARFUnit.h:167
typename UnitVector::iterator iterator
Definition: DWARFUnit.h:137
void finishedInfoUnits()
Indicate that parsing .debug_info[.dwo] is done, and remaining units will be from ....
Definition: DWARFUnit.h:174
unsigned getNumTypesUnits() const
Returns number of units from all .debug_types[.dwo] sections.
Definition: DWARFUnit.h:171
unsigned getNumUnits() const
Returns number of all units held by this instance.
Definition: DWARFUnit.h:165
void addUnitsForSection(DWARFContext &C, const DWARFSection &Section, DWARFSectionKind SectionKind)
Read units from a .debug_info or .debug_types section.
Definition: DWARFUnit.cpp:42
DWARFUnit * getUnitForOffset(uint64_t Offset) const
Definition: DWARFUnit.cpp:152
decltype(make_filter_range(std::declval< iterator_range >(), isCompileUnit)) compile_unit_range
Definition: DWARFUnit.h:141
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:165
const DWARFDebugInfoEntry * getDebugInfoEntry(unsigned Index) const
Return DWARFDebugInfoEntry for the specified index Index.
Definition: DWARFUnit.h:276
const DWARFDebugInfoEntry * getSiblingEntry(const DWARFDebugInfoEntry *Die) const
Definition: DWARFUnit.cpp:931
std::optional< uint64_t > getDWOId()
Definition: DWARFUnit.h:458
uint32_t getHeaderSize() const
Size in bytes of the parsed unit header.
Definition: DWARFUnit.h:332
DWARFDie getPreviousSibling(const DWARFDebugInfoEntry *Die)
Definition: DWARFUnit.cpp:945
Expected< std::optional< StrOffsetsContributionDescriptor > > determineStringOffsetsTableContributionDWO(DWARFDataExtractor &DA)
Find the unit's contribution to the string offsets table and determine its length and form.
Definition: DWARFUnit.cpp:1172
const DWARFLocationTable & getLocationTable()
Definition: DWARFUnit.h:394
unsigned getNumDIEs()
Returns the number of DIEs in the unit.
Definition: DWARFUnit.h:505
const dwarf::FormParams & getFormParams() const
Definition: DWARFUnit.h:322
const DWARFDebugInfoEntry * getParentEntry(const DWARFDebugInfoEntry *Die) const
Definition: DWARFUnit.cpp:909
DWARFDie getFirstChild(const DWARFDebugInfoEntry *Die)
Definition: DWARFUnit.cpp:984
DWARFDie getNonSkeletonUnitDIE(bool ExtractUnitDIEOnly=true, StringRef DWOAlternativeLocation={})
Definition: DWARFUnit.h:450
DWARFDataExtractor getDebugInfoExtractor() const
Definition: DWARFUnit.cpp:209
uint8_t getUnitType() const
Definition: DWARFUnit.h:335
uint64_t getLength() const
Definition: DWARFUnit.h:333
uint8_t getRefAddrByteSize() const
Definition: DWARFUnit.h:327
DWARFDie getSibling(const DWARFDebugInfoEntry *Die)
Definition: DWARFUnit.cpp:923
DataExtractor getStringExtractor() const
Definition: DWARFUnit.h:390
std::optional< uint64_t > getRnglistOffset(uint32_t Index)
Return a rangelist's offset based on an index.
Definition: DWARFUnit.cpp:1208
Error tryExtractDIEsIfNeeded(bool CUDieOnly)
Definition: DWARFUnit.cpp:498
DWARFDie getUnitDIE(bool ExtractUnitDIEOnly=true)
Definition: DWARFUnit.h:443
virtual ~DWARFUnit()
DWARFContext & getContext() const
Definition: DWARFUnit.h:319
uint8_t getAddressByteSize() const
Definition: DWARFUnit.h:326
void setSkeletonUnit(DWARFUnit *SU)
Definition: DWARFUnit.h:345
DWARFDie getVariableForAddress(uint64_t Address)
Returns variable DIE for the address provided.
Definition: DWARFUnit.cpp:851
std::optional< uint64_t > getAddrOffsetSectionBase() const
Definition: DWARFUnit.h:356
const DWARFSection & getInfoSection() const
Definition: DWARFUnit.h:320
void setAddrOffsetSection(const DWARFSection *AOS, uint64_t Base)
Definition: DWARFUnit.h:351
void setDWOId(uint64_t NewID)
Definition: DWARFUnit.h:462
uint64_t getLocSectionBase() const
Definition: DWARFUnit.h:380
void setRangesSection(const DWARFSection *RS, uint64_t Base)
Definition: DWARFUnit.h:375
uint8_t getDwarfStringOffsetsByteSize() const
Definition: DWARFUnit.h:410
const DWARFUnitHeader & getHeader() const
Definition: DWARFUnit.h:292
const DWARFAbbreviationDeclarationSet * getAbbreviations() const
Definition: DWARFUnit.cpp:1054
DWARFDie getDIEForOffset(uint64_t Offset)
Return the DIE object for a given offset Offset inside the unit's DIE vector.
Definition: DWARFUnit.h:533
DWARFDie getParent(const DWARFDebugInfoEntry *Die)
Definition: DWARFUnit.cpp:901
std::optional< uint64_t > getLoclistOffset(uint32_t Index)
Definition: DWARFUnit.cpp:1219
const char * getCompilationDir()
Definition: DWARFUnit.cpp:401
uint32_t getDIEIndex(const DWARFDie &D) const
Return the index of a DIE inside the unit's DIE vector.
Definition: DWARFUnit.h:516
uint32_t getLineTableOffset() const
Definition: DWARFUnit.h:553
uint64_t getStringOffsetsBase() const
Definition: DWARFUnit.h:415
dwarf::DwarfFormat getFormat() const
Definition: DWARFUnit.h:334
Expected< std::optional< StrOffsetsContributionDescriptor > > determineStringOffsetsTableContribution(DWARFDataExtractor &DA)
Find the unit's contribution to the string offsets table and determine its length and form.
Definition: DWARFUnit.cpp:1159
std::optional< uint32_t > getDIEIndexForOffset(uint64_t Offset)
Return the DIE index for a given offset Offset inside the unit's DIE vector.
Definition: DWARFUnit.h:542
uint64_t getAbbreviationsOffset() const
Definition: DWARFUnit.h:420
uint16_t getVersion() const
Definition: DWARFUnit.h:325
void getInlinedChainForAddress(uint64_t Address, SmallVectorImpl< DWARFDie > &InlinedChain)
getInlinedChainForAddress - fetches inlined chain for a given address.
Definition: DWARFUnit.cpp:872
std::optional< uint64_t > getIndexedAddressOffset(uint64_t Index)
Returns offset to the indexed address value inside .debug_addr section.
Definition: DWARFUnit.h:361
uint64_t getAbbrOffset() const
Definition: DWARFUnit.h:337
Error extractRangeList(uint64_t RangeListOffset, DWARFDebugRangeList &RangeList) const
Extract the range list referenced by this compile unit from the .debug_ranges section.
Definition: DWARFUnit.cpp:377
Expected< uint64_t > getStringOffsetSectionItem(uint32_t Index) const
Definition: DWARFUnit.cpp:238
uint32_t getDIEIndex(const DWARFDebugInfoEntry *Die) const
Return the index of a Die entry inside the unit's DIE vector.
Definition: DWARFUnit.h:269
die_iterator_range dies()
Definition: DWARFUnit.h:560
Expected< DWARFLocationExpressionsVector > findLoclistFromOffset(uint64_t Offset)
Definition: DWARFUnit.cpp:709
Expected< DWARFAddressRangesVector > findRnglistFromOffset(uint64_t Offset)
Return a vector of address ranges resulting from a (possibly encoded) range list starting at a given ...
Definition: DWARFUnit.cpp:667
bool isLittleEndian() const
Definition: DWARFUnit.h:317
const DWARFDebugInfoEntry * getPreviousSiblingEntry(const DWARFDebugInfoEntry *Die) const
Definition: DWARFUnit.cpp:953
virtual void dump(raw_ostream &OS, DIDumpOptions DumpOpts)=0
const DWARFUnitVector & getUnitVector() const
Return the DWARFUnitVector containing this unit.
Definition: DWARFUnit.h:501
const DWARFDebugInfoEntry * getLastChildEntry(const DWARFDebugInfoEntry *Die) const
Definition: DWARFUnit.cpp:1017
const DWARFSection & getStringOffsetSection() const
Definition: DWARFUnit.h:341
const DWARFSection & getLineSection() const
Definition: DWARFUnit.h:339
StringRef getStringSection() const
Definition: DWARFUnit.h:340
void updateVariableDieMap(DWARFDie Die)
Recursively update address to variable Die map.
Definition: DWARFUnit.cpp:777
DWARFDie getSubroutineForAddress(uint64_t Address)
Returns subprogram DIE with address range encompassing the provided address.
Definition: DWARFUnit.cpp:763
const DWARFDebugInfoEntry * getFirstChildEntry(const DWARFDebugInfoEntry *Die) const
Definition: DWARFUnit.cpp:992
uint8_t getDwarfOffsetByteSize() const
Definition: DWARFUnit.h:328
Expected< DWARFAddressRangesVector > findRnglistFromIndex(uint32_t Index)
Return a vector of address ranges retrieved from an encoded range list whose offset is found via a ta...
Definition: DWARFUnit.cpp:684
static bool isMatchingUnitTypeAndTag(uint8_t UnitType, dwarf::Tag Tag)
Definition: DWARFUnit.h:424
uint64_t getNextUnitOffset() const
Definition: DWARFUnit.h:338
std::optional< object::SectionedAddress > getBaseAddress()
Definition: DWARFUnit.cpp:1068
const std::optional< StrOffsetsContributionDescriptor > & getStringOffsetsTableContribution()
Definition: DWARFUnit.h:405
Expected< DWARFAddressRangesVector > collectAddressRanges()
Definition: DWARFUnit.cpp:694
std::optional< object::SectionedAddress > getAddrOffsetSectionItem(uint32_t Index) const
Definition: DWARFUnit.cpp:215
DWARFUnit * getLinkedUnit()
Definition: DWARFUnit.h:349
bool isTypeUnit() const
Definition: DWARFUnit.h:336
DWARFDie getDIEAtIndex(unsigned Index)
Return the DIE object at the given index Index.
Definition: DWARFUnit.h:521
uint64_t getOffset() const
Definition: DWARFUnit.h:321
DWARFDie getLastChild(const DWARFDebugInfoEntry *Die)
Definition: DWARFUnit.cpp:1009
void updateAddressDieMap(DWARFDie Die)
Recursively update address to Die map.
Definition: DWARFUnit.cpp:732
bool isDWOUnit() const
Definition: DWARFUnit.h:318
Implements a dense probed hash-table based set.
Definition: DenseSet.h:278
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
Tagged union holding either a T or a Error.
Definition: Error.h:481
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:22
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1196
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
Stores all information related to a compile unit, be it in its original instance of the object file o...
A range adaptor for a pair of iterators.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
uint8_t getUnitLengthFieldByteSize(DwarfFormat Format)
Get the byte size of the unit length field depending on the DWARF format.
Definition: Dwarf.h:1110
bool isUnitType(uint8_t UnitType)
Definition: Dwarf.h:889
DwarfFormat
Constants that define the DWARF format as 32 or 64 bit.
Definition: Dwarf.h:91
@ DWARF32
Definition: Dwarf.h:91
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:480
@ Length
Definition: DWP.cpp:480
const DWARFUnitIndex & getDWARFUnitIndex(DWARFContext &Context, DWARFSectionKind Kind)
Definition: DWARFUnit.cpp:893
auto partition_point(R &&Range, Predicate P)
Binary search for the first iterator in a range where a predicate is false.
Definition: STLExtras.h:2050
DWARFSectionKind
The enum of section identifiers to be used in internal interfaces.
iterator_range< filter_iterator< detail::IterOfRange< RangeT >, PredicateT > > make_filter_range(RangeT &&Range, PredicateT Pred)
Convenience function that takes a range of elements and a predicate, and return a new filter_iterator...
Definition: STLExtras.h:573
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
bool isCompileUnit(const std::unique_ptr< DWARFUnit > &U)
Definition: DWARFUnit.h:595
Container for dump options that control which debug information will be dumped.
Definition: DIContext.h:196
Represents base address of the CU.
Definition: DWARFUnit.h:187
Expected< StrOffsetsContributionDescriptor > validateContributionSize(DWARFDataExtractor &DA)
Determine whether a contribution to the string offsets table is consistent with the relevant section ...
Definition: DWARFUnit.cpp:1080
dwarf::DwarfFormat getFormat() const
Definition: DWARFUnit.h:200
uint64_t Size
The contribution size not including the header.
Definition: DWARFUnit.h:190
dwarf::FormParams FormParams
Format and version.
Definition: DWARFUnit.h:192
StrOffsetsContributionDescriptor(uint64_t Base, uint64_t Size, uint8_t Version, dwarf::DwarfFormat Format)
Definition: DWARFUnit.h:194
A helper struct providing information about the byte size of DW_FORM values that vary in size dependi...
Definition: Dwarf.h:1084
DwarfFormat Format
Definition: Dwarf.h:1087
uint8_t getDwarfOffsetByteSize() const
The size of a reference is determined by the DWARF 32/64-bit format.
Definition: Dwarf.h:1102
uint8_t getRefAddrByteSize() const
The definition of the size of form DW_FORM_ref_addr depends on the version.
Definition: Dwarf.h:1095