LLVM 17.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;
46
47/// Base class describing the header of any kind of "unit." Some information
48/// is specific to certain unit types. We separate this class out so we can
49/// parse the header before deciding what specific kind of unit to construct.
51 // Offset within section.
52 uint64_t Offset = 0;
53 // Version, address size, and DWARF format.
55 uint64_t Length = 0;
56 uint64_t AbbrOffset = 0;
57
58 // For DWO units only.
59 const DWARFUnitIndex::Entry *IndexEntry = nullptr;
60
61 // For type units only.
62 uint64_t TypeHash = 0;
63 uint64_t TypeOffset = 0;
64
65 // For v5 split or skeleton compile units only.
66 std::optional<uint64_t> DWOId;
67
68 // Unit type as parsed, or derived from the section kind.
69 uint8_t UnitType = 0;
70
71 // Size as parsed. uint8_t for compactness.
72 uint8_t Size = 0;
73
74public:
75 /// Parse a unit header from \p debug_info starting at \p offset_ptr.
76 /// Note that \p SectionKind is used as a hint to guess the unit type
77 /// for DWARF formats prior to DWARFv5. In DWARFv5 the unit type is
78 /// explicitly defined in the header and the hint is ignored.
79 bool extract(DWARFContext &Context, const DWARFDataExtractor &debug_info,
81 // For units in DWARF Package File, remember the index entry and update
82 // the abbreviation offset read by extract().
83 bool applyIndexEntry(const DWARFUnitIndex::Entry *Entry);
84 uint64_t getOffset() const { return Offset; }
85 const dwarf::FormParams &getFormParams() const { return FormParams; }
88 uint8_t getAddressByteSize() const { return FormParams.AddrSize; }
89 uint8_t getRefAddrByteSize() const { return FormParams.getRefAddrByteSize(); }
90 uint8_t getDwarfOffsetByteSize() const {
92 }
93 uint64_t getLength() const { return Length; }
94 uint64_t getAbbrOffset() const { return AbbrOffset; }
95 std::optional<uint64_t> getDWOId() const { return DWOId; }
96 void setDWOId(uint64_t Id) {
97 assert((!DWOId || *DWOId == Id) && "setting DWOId to a different value");
98 DWOId = Id;
99 }
100 const DWARFUnitIndex::Entry *getIndexEntry() const { return IndexEntry; }
101 uint64_t getTypeHash() const { return TypeHash; }
102 uint64_t getTypeOffset() const { return TypeOffset; }
103 uint8_t getUnitType() const { return UnitType; }
104 bool isTypeUnit() const {
105 return UnitType == dwarf::DW_UT_type || UnitType == dwarf::DW_UT_split_type;
106 }
107 uint8_t getSize() const { return Size; }
110 }
112 return Offset + Length + getUnitLengthFieldByteSize();
113 }
114};
115
116const DWARFUnitIndex &getDWARFUnitIndex(DWARFContext &Context,
117 DWARFSectionKind Kind);
118
119bool isCompileUnit(const std::unique_ptr<DWARFUnit> &U);
120
121/// Describe a collection of units. Intended to hold all units either from
122/// .debug_info and .debug_types, or from .debug_info.dwo and .debug_types.dwo.
123class DWARFUnitVector final : public SmallVector<std::unique_ptr<DWARFUnit>, 1> {
124 std::function<std::unique_ptr<DWARFUnit>(uint64_t, DWARFSectionKind,
125 const DWARFSection *,
126 const DWARFUnitIndex::Entry *)>
127 Parser;
128 int NumInfoUnits = -1;
129
130public:
134
136 decltype(make_filter_range(std::declval<iterator_range>(), isCompileUnit));
137
140
141 /// Read units from a .debug_info or .debug_types section. Calls made
142 /// before finishedInfoUnits() are assumed to be for .debug_info sections,
143 /// calls after finishedInfoUnits() are for .debug_types sections. Caller
144 /// must not mix calls to addUnitsForSection and addUnitsForDWOSection.
145 void addUnitsForSection(DWARFContext &C, const DWARFSection &Section,
147 /// Read units from a .debug_info.dwo or .debug_types.dwo section. Calls
148 /// made before finishedInfoUnits() are assumed to be for .debug_info.dwo
149 /// sections, calls after finishedInfoUnits() are for .debug_types.dwo
150 /// sections. Caller must not mix calls to addUnitsForSection and
151 /// addUnitsForDWOSection.
152 void addUnitsForDWOSection(DWARFContext &C, const DWARFSection &DWOSection,
153 DWARFSectionKind SectionKind, bool Lazy = false);
154
155 /// Add an existing DWARFUnit to this UnitVector. This is used by the DWARF
156 /// verifier to process unit separately.
157 DWARFUnit *addUnit(std::unique_ptr<DWARFUnit> Unit);
158
159 /// Returns number of all units held by this instance.
160 unsigned getNumUnits() const { return size(); }
161 /// Returns number of units from all .debug_info[.dwo] sections.
162 unsigned getNumInfoUnits() const {
163 return NumInfoUnits == -1 ? size() : NumInfoUnits;
164 }
165 /// Returns number of units from all .debug_types[.dwo] sections.
166 unsigned getNumTypesUnits() const { return size() - NumInfoUnits; }
167 /// Indicate that parsing .debug_info[.dwo] is done, and remaining units
168 /// will be from .debug_types[.dwo].
169 void finishedInfoUnits() { NumInfoUnits = size(); }
170
171private:
172 void addUnitsImpl(DWARFContext &Context, const DWARFObject &Obj,
173 const DWARFSection &Section, const DWARFDebugAbbrev *DA,
174 const DWARFSection *RS, const DWARFSection *LocSection,
175 StringRef SS, const DWARFSection &SOS,
176 const DWARFSection *AOS, const DWARFSection &LS, bool LE,
177 bool IsDWO, bool Lazy, DWARFSectionKind SectionKind);
178};
179
180/// Represents base address of the CU.
181/// Represents a unit's contribution to the string offsets table.
184 /// The contribution size not including the header.
186 /// Format and version.
188
190 uint8_t Version, dwarf::DwarfFormat Format)
191 : Base(Base), Size(Size), FormParams({Version, 0, Format}) {}
193
194 uint8_t getVersion() const { return FormParams.Version; }
196 uint8_t getDwarfOffsetByteSize() const {
198 }
199 /// Determine whether a contribution to the string offsets table is
200 /// consistent with the relevant section size and that its length is
201 /// a multiple of the size of one of its entries.
204};
205
207 DWARFContext &Context;
208 /// Section containing this DWARFUnit.
209 const DWARFSection &InfoSection;
210
211 DWARFUnitHeader Header;
212 const DWARFDebugAbbrev *Abbrev;
213 const DWARFSection *RangeSection;
214 uint64_t RangeSectionBase;
215 uint64_t LocSectionBase;
216
217 /// Location table of this unit.
218 std::unique_ptr<DWARFLocationTable> LocTable;
219
220 const DWARFSection &LineSection;
221 StringRef StringSection;
222 const DWARFSection &StringOffsetSection;
223 const DWARFSection *AddrOffsetSection;
224 DWARFUnit *SU;
225 std::optional<uint64_t> AddrOffsetSectionBase;
226 bool IsLittleEndian;
227 bool IsDWO;
228 const DWARFUnitVector &UnitVector;
229
230 /// Start, length, and DWARF format of the unit's contribution to the string
231 /// offsets table (DWARF v5).
232 std::optional<StrOffsetsContributionDescriptor>
233 StringOffsetsTableContribution;
234
235 mutable const DWARFAbbreviationDeclarationSet *Abbrevs;
236 std::optional<object::SectionedAddress> BaseAddr;
237 /// The compile unit debug information entry items.
238 std::vector<DWARFDebugInfoEntry> DieArray;
239
240 /// Map from range's start address to end address and corresponding DIE.
241 /// IntervalMap does not support range removal, as a result, we use the
242 /// std::map::upper_bound for address range lookup.
243 std::map<uint64_t, std::pair<uint64_t, DWARFDie>> AddrDieMap;
244
245 /// Map from the location (interpreted DW_AT_location) of a DW_TAG_variable,
246 /// to the end address and the corresponding DIE.
247 std::map<uint64_t, std::pair<uint64_t, DWARFDie>> VariableDieMap;
248 DenseSet<uint64_t> RootsParsedForVariables;
249
250 using die_iterator_range =
252
253 std::shared_ptr<DWARFUnit> DWO;
254
255protected:
256 /// Return the index of a \p Die entry inside the unit's DIE vector.
257 ///
258 /// It is illegal to call this method with a DIE that hasn't be
259 /// created by this unit. In other word, it's illegal to call this
260 /// method on a DIE that isn't accessible by following
261 /// children/sibling links starting from this unit's getUnitDIE().
263 auto First = DieArray.data();
264 assert(Die >= First && Die < First + DieArray.size());
265 return Die - First;
266 }
267
268 /// Return DWARFDebugInfoEntry for the specified index \p Index.
270 assert(Index < DieArray.size());
271 return &DieArray[Index];
272 }
273
274 const DWARFDebugInfoEntry *
275 getParentEntry(const DWARFDebugInfoEntry *Die) const;
276 const DWARFDebugInfoEntry *
277 getSiblingEntry(const DWARFDebugInfoEntry *Die) const;
278 const DWARFDebugInfoEntry *
280 const DWARFDebugInfoEntry *
281 getFirstChildEntry(const DWARFDebugInfoEntry *Die) const;
282 const DWARFDebugInfoEntry *
283 getLastChildEntry(const DWARFDebugInfoEntry *Die) const;
284
285 const DWARFUnitHeader &getHeader() const { return Header; }
286
287 /// Find the unit's contribution to the string offsets table and determine its
288 /// length and form. The given offset is expected to be derived from the unit
289 /// DIE's DW_AT_str_offsets_base attribute.
292
293 /// Find the unit's contribution to the string offsets table and determine its
294 /// length and form. The given offset is expected to be 0 in a dwo file or,
295 /// in a dwp file, the start of the unit's contribution to the string offsets
296 /// table section (as determined by the index table).
299
300public:
301 DWARFUnit(DWARFContext &Context, const DWARFSection &Section,
302 const DWARFUnitHeader &Header, const DWARFDebugAbbrev *DA,
303 const DWARFSection *RS, const DWARFSection *LocSection,
304 StringRef SS, const DWARFSection &SOS, const DWARFSection *AOS,
305 const DWARFSection &LS, bool LE, bool IsDWO,
306 const DWARFUnitVector &UnitVector);
307
308 virtual ~DWARFUnit();
309
310 bool isLittleEndian() const { return IsLittleEndian; }
311 bool isDWOUnit() const { return IsDWO; }
312 DWARFContext& getContext() const { return Context; }
313 const DWARFSection &getInfoSection() const { return InfoSection; }
314 uint64_t getOffset() const { return Header.getOffset(); }
316 return Header.getFormParams();
317 }
318 uint16_t getVersion() const { return Header.getVersion(); }
319 uint8_t getAddressByteSize() const { return Header.getAddressByteSize(); }
320 uint8_t getRefAddrByteSize() const { return Header.getRefAddrByteSize(); }
321 uint8_t getDwarfOffsetByteSize() const {
322 return Header.getDwarfOffsetByteSize();
323 }
324 /// Size in bytes of the parsed unit header.
325 uint32_t getHeaderSize() const { return Header.getSize(); }
326 uint64_t getLength() const { return Header.getLength(); }
327 dwarf::DwarfFormat getFormat() const { return Header.getFormat(); }
328 uint8_t getUnitType() const { return Header.getUnitType(); }
329 bool isTypeUnit() const { return Header.isTypeUnit(); }
330 uint64_t getAbbrOffset() const { return Header.getAbbrOffset(); }
331 uint64_t getNextUnitOffset() const { return Header.getNextUnitOffset(); }
332 const DWARFSection &getLineSection() const { return LineSection; }
333 StringRef getStringSection() const { return StringSection; }
335 return StringOffsetSection;
336 }
337
338 void setSkeletonUnit(DWARFUnit *SU) { this->SU = SU; }
339 // Returns itself if not using Split DWARF, or if the unit is a skeleton unit
340 // - otherwise returns the split full unit's corresponding skeleton, if
341 // available.
342 DWARFUnit *getLinkedUnit() { return IsDWO ? SU : this; }
343
345 AddrOffsetSection = AOS;
346 AddrOffsetSectionBase = Base;
347 }
348
349 std::optional<uint64_t> getAddrOffsetSectionBase() const {
350 return AddrOffsetSectionBase;
351 }
352
353 /// Recursively update address to Die map.
355
356 /// Recursively update address to variable Die map.
358
360 RangeSection = RS;
361 RangeSectionBase = Base;
362 }
363
365 return LocSectionBase;
366 }
367
368 std::optional<object::SectionedAddress>
371
373
375 return DataExtractor(StringSection, false, 0);
376 }
377
378 const DWARFLocationTable &getLocationTable() { return *LocTable; }
379
380 /// Extract the range list referenced by this compile unit from the
381 /// .debug_ranges section. If the extraction is unsuccessful, an error
382 /// is returned. Successful extraction requires that the compile unit
383 /// has already been extracted.
384 Error extractRangeList(uint64_t RangeListOffset,
385 DWARFDebugRangeList &RangeList) const;
386 void clear();
387
388 const std::optional<StrOffsetsContributionDescriptor> &
390 return StringOffsetsTableContribution;
391 }
392
394 assert(StringOffsetsTableContribution);
395 return StringOffsetsTableContribution->getDwarfOffsetByteSize();
396 }
397
399 assert(StringOffsetsTableContribution);
400 return StringOffsetsTableContribution->Base;
401 }
402
403 uint64_t getAbbreviationsOffset() const { return Header.getAbbrOffset(); }
404
406
408 switch (UnitType) {
409 case dwarf::DW_UT_compile:
410 return Tag == dwarf::DW_TAG_compile_unit;
411 case dwarf::DW_UT_type:
412 return Tag == dwarf::DW_TAG_type_unit;
413 case dwarf::DW_UT_partial:
414 return Tag == dwarf::DW_TAG_partial_unit;
415 case dwarf::DW_UT_skeleton:
416 return Tag == dwarf::DW_TAG_skeleton_unit;
417 case dwarf::DW_UT_split_compile:
418 case dwarf::DW_UT_split_type:
419 return dwarf::isUnitType(Tag);
420 }
421 return false;
422 }
423
424 std::optional<object::SectionedAddress> getBaseAddress();
425
426 DWARFDie getUnitDIE(bool ExtractUnitDIEOnly = true) {
427 extractDIEsIfNeeded(ExtractUnitDIEOnly);
428 if (DieArray.empty())
429 return DWARFDie();
430 return DWARFDie(this, &DieArray[0]);
431 }
432
433 DWARFDie getNonSkeletonUnitDIE(bool ExtractUnitDIEOnly = true,
434 StringRef DWOAlternativeLocation = {}) {
435 parseDWO(DWOAlternativeLocation);
436 return DWO ? DWO->getUnitDIE(ExtractUnitDIEOnly)
437 : getUnitDIE(ExtractUnitDIEOnly);
438 }
439
440 const char *getCompilationDir();
441 std::optional<uint64_t> getDWOId() {
442 extractDIEsIfNeeded(/*CUDieOnly*/ true);
443 return getHeader().getDWOId();
444 }
445 void setDWOId(uint64_t NewID) { Header.setDWOId(NewID); }
446
447 /// Return a vector of address ranges resulting from a (possibly encoded)
448 /// range list starting at a given offset in the appropriate ranges section.
450
451 /// Return a vector of address ranges retrieved from an encoded range
452 /// list whose offset is found via a table lookup given an index (DWARF v5
453 /// and later).
455
456 /// Return a rangelist's offset based on an index. The index designates
457 /// an entry in the rangelist table's offset array and is supplied by
458 /// DW_FORM_rnglistx.
459 std::optional<uint64_t> getRnglistOffset(uint32_t Index);
460
461 std::optional<uint64_t> getLoclistOffset(uint32_t Index);
462
464
467
468 /// Returns subprogram DIE with address range encompassing the provided
469 /// address. The pointer is alive as long as parsed compile unit DIEs are not
470 /// cleared.
472
473 /// Returns variable DIE for the address provided. The pointer is alive as
474 /// long as parsed compile unit DIEs are not cleared.
476
477 /// getInlinedChainForAddress - fetches inlined chain for a given address.
478 /// Returns empty chain if there is no subprogram containing address. The
479 /// chain is valid as long as parsed compile unit DIEs are not cleared.
481 SmallVectorImpl<DWARFDie> &InlinedChain);
482
483 /// Return the DWARFUnitVector containing this unit.
484 const DWARFUnitVector &getUnitVector() const { return UnitVector; }
485
486 /// Returns the number of DIEs in the unit. Parses the unit
487 /// if necessary.
488 unsigned getNumDIEs() {
489 extractDIEsIfNeeded(false);
490 return DieArray.size();
491 }
492
493 /// Return the index of a DIE inside the unit's DIE vector.
494 ///
495 /// It is illegal to call this method with a DIE that hasn't be
496 /// created by this unit. In other word, it's illegal to call this
497 /// method on a DIE that isn't accessible by following
498 /// children/sibling links starting from this unit's getUnitDIE().
500 return getDIEIndex(D.getDebugInfoEntry());
501 }
502
503 /// Return the DIE object at the given index \p Index.
505 return DWARFDie(this, getDebugInfoEntry(Index));
506 }
507
513
514 /// Return the DIE object for a given offset \p Offset inside the
515 /// unit's DIE vector.
517 if (std::optional<uint32_t> DieIdx = getDIEIndexForOffset(Offset))
518 return DWARFDie(this, &DieArray[*DieIdx]);
519
520 return DWARFDie();
521 }
522
523 /// Return the DIE index for a given offset \p Offset inside the
524 /// unit's DIE vector.
525 std::optional<uint32_t> getDIEIndexForOffset(uint64_t Offset) {
526 extractDIEsIfNeeded(false);
527 auto It =
528 llvm::partition_point(DieArray, [=](const DWARFDebugInfoEntry &DIE) {
529 return DIE.getOffset() < Offset;
530 });
531 if (It != DieArray.end() && It->getOffset() == Offset)
532 return It - DieArray.begin();
533 return std::nullopt;
534 }
535
537 if (auto IndexEntry = Header.getIndexEntry())
538 if (const auto *Contrib = IndexEntry->getContribution(DW_SECT_LINE))
539 return Contrib->getOffset32();
540 return 0;
541 }
542
544 extractDIEsIfNeeded(false);
545 return die_iterator_range(DieArray.begin(), DieArray.end());
546 }
547
548 virtual void dump(raw_ostream &OS, DIDumpOptions DumpOpts) = 0;
549
550 Error tryExtractDIEsIfNeeded(bool CUDieOnly);
551
552private:
553 /// Size in bytes of the .debug_info data associated with this compile unit.
554 size_t getDebugInfoSize() const {
555 return Header.getLength() + Header.getUnitLengthFieldByteSize() -
557 }
558
559 /// extractDIEsIfNeeded - Parses a compile unit and indexes its DIEs if it
560 /// hasn't already been done
561 void extractDIEsIfNeeded(bool CUDieOnly);
562
563 /// extractDIEsToVector - Appends all parsed DIEs to a vector.
564 void extractDIEsToVector(bool AppendCUDie, bool AppendNonCUDIEs,
565 std::vector<DWARFDebugInfoEntry> &DIEs) const;
566
567 /// clearDIEs - Clear parsed DIEs to keep memory usage low.
568 void clearDIEs(bool KeepCUDie);
569
570 /// parseDWO - Parses .dwo file for current compile unit. Returns true if
571 /// it was actually constructed.
572 /// The \p AlternativeLocation specifies an alternative location to get
573 /// the DWARF context for the DWO object; this is the case when it has
574 /// been moved from its original location.
575 bool parseDWO(StringRef AlternativeLocation = {});
576};
577
578inline bool isCompileUnit(const std::unique_ptr<DWARFUnit> &U) {
579 return !U->isTypeUnit();
580}
581
582} // end namespace llvm
583
584#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.
loop extract
LLVMContext & Context
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:746
unsigned getOffset() const
Get the compile/type unit relative offset of this DIE.
Definition: DIE.h:784
DWARFContext This data structure is the top level entity that deals with dwarf debug information pars...
Definition: DWARFContext.h:46
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:50
std::optional< uint64_t > getDWOId() const
Definition: DWARFUnit.h:95
uint64_t getOffset() const
Definition: DWARFUnit.h:84
uint8_t getRefAddrByteSize() const
Definition: DWARFUnit.h:89
uint8_t getUnitType() const
Definition: DWARFUnit.h:103
uint8_t getDwarfOffsetByteSize() const
Definition: DWARFUnit.h:90
bool applyIndexEntry(const DWARFUnitIndex::Entry *Entry)
Definition: DWARFUnit.cpp:348
uint64_t getAbbrOffset() const
Definition: DWARFUnit.h:94
uint8_t getSize() const
Definition: DWARFUnit.h:107
dwarf::DwarfFormat getFormat() const
Definition: DWARFUnit.h:87
uint64_t getTypeHash() const
Definition: DWARFUnit.h:101
uint64_t getLength() const
Definition: DWARFUnit.h:93
uint64_t getTypeOffset() const
Definition: DWARFUnit.h:102
uint16_t getVersion() const
Definition: DWARFUnit.h:86
uint8_t getAddressByteSize() const
Definition: DWARFUnit.h:88
uint64_t getNextUnitOffset() const
Definition: DWARFUnit.h:111
uint8_t getUnitLengthFieldByteSize() const
Definition: DWARFUnit.h:108
const DWARFUnitIndex::Entry * getIndexEntry() const
Definition: DWARFUnit.h:100
bool isTypeUnit() const
Definition: DWARFUnit.h:104
void setDWOId(uint64_t Id)
Definition: DWARFUnit.h:96
const dwarf::FormParams & getFormParams() const
Definition: DWARFUnit.h:85
Describe a collection of units.
Definition: DWARFUnit.h:123
DWARFUnit * addUnit(std::unique_ptr< DWARFUnit > Unit)
Add an existing DWARFUnit to this UnitVector.
Definition: DWARFUnit.cpp:136
unsigned getNumInfoUnits() const
Returns number of units from all .debug_info[.dwo] sections.
Definition: DWARFUnit.h:162
typename UnitVector::iterator iterator
Definition: DWARFUnit.h:132
void finishedInfoUnits()
Indicate that parsing .debug_info[.dwo] is done, and remaining units will be from ....
Definition: DWARFUnit.h:169
unsigned getNumTypesUnits() const
Returns number of units from all .debug_types[.dwo] sections.
Definition: DWARFUnit.h:166
unsigned getNumUnits() const
Returns number of all units held by this instance.
Definition: DWARFUnit.h:160
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:145
decltype(make_filter_range(std::declval< iterator_range >(), isCompileUnit)) compile_unit_range
Definition: DWARFUnit.h:136
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
const DWARFDebugInfoEntry * getDebugInfoEntry(unsigned Index) const
Return DWARFDebugInfoEntry for the specified index Index.
Definition: DWARFUnit.h:269
const DWARFDebugInfoEntry * getSiblingEntry(const DWARFDebugInfoEntry *Die) const
Definition: DWARFUnit.cpp:919
std::optional< uint64_t > getDWOId()
Definition: DWARFUnit.h:441
uint32_t getHeaderSize() const
Size in bytes of the parsed unit header.
Definition: DWARFUnit.h:325
DWARFDie getPreviousSibling(const DWARFDebugInfoEntry *Die)
Definition: DWARFUnit.cpp:933
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:1152
const DWARFLocationTable & getLocationTable()
Definition: DWARFUnit.h:378
unsigned getNumDIEs()
Returns the number of DIEs in the unit.
Definition: DWARFUnit.h:488
const dwarf::FormParams & getFormParams() const
Definition: DWARFUnit.h:315
const DWARFDebugInfoEntry * getParentEntry(const DWARFDebugInfoEntry *Die) const
Definition: DWARFUnit.cpp:897
DWARFDie getFirstChild(const DWARFDebugInfoEntry *Die)
Definition: DWARFUnit.cpp:972
DWARFDie getNonSkeletonUnitDIE(bool ExtractUnitDIEOnly=true, StringRef DWOAlternativeLocation={})
Definition: DWARFUnit.h:433
DWARFDataExtractor getDebugInfoExtractor() const
Definition: DWARFUnit.cpp:202
uint8_t getUnitType() const
Definition: DWARFUnit.h:328
uint64_t getLength() const
Definition: DWARFUnit.h:326
uint8_t getRefAddrByteSize() const
Definition: DWARFUnit.h:320
DWARFDie getSibling(const DWARFDebugInfoEntry *Die)
Definition: DWARFUnit.cpp:911
DataExtractor getStringExtractor() const
Definition: DWARFUnit.h:374
std::optional< uint64_t > getRnglistOffset(uint32_t Index)
Return a rangelist's offset based on an index.
Definition: DWARFUnit.cpp:1188
Error tryExtractDIEsIfNeeded(bool CUDieOnly)
Definition: DWARFUnit.cpp:486
DWARFDie getUnitDIE(bool ExtractUnitDIEOnly=true)
Definition: DWARFUnit.h:426
virtual ~DWARFUnit()
DWARFContext & getContext() const
Definition: DWARFUnit.h:312
uint8_t getAddressByteSize() const
Definition: DWARFUnit.h:319
void setSkeletonUnit(DWARFUnit *SU)
Definition: DWARFUnit.h:338
DWARFDie getVariableForAddress(uint64_t Address)
Returns variable DIE for the address provided.
Definition: DWARFUnit.cpp:839
std::optional< uint64_t > getAddrOffsetSectionBase() const
Definition: DWARFUnit.h:349
const DWARFSection & getInfoSection() const
Definition: DWARFUnit.h:313
void setAddrOffsetSection(const DWARFSection *AOS, uint64_t Base)
Definition: DWARFUnit.h:344
void setDWOId(uint64_t NewID)
Definition: DWARFUnit.h:445
uint64_t getLocSectionBase() const
Definition: DWARFUnit.h:364
void setRangesSection(const DWARFSection *RS, uint64_t Base)
Definition: DWARFUnit.h:359
uint8_t getDwarfStringOffsetsByteSize() const
Definition: DWARFUnit.h:393
const DWARFUnitHeader & getHeader() const
Definition: DWARFUnit.h:285
const DWARFAbbreviationDeclarationSet * getAbbreviations() const
Definition: DWARFUnit.cpp:1042
DWARFDie getDIEForOffset(uint64_t Offset)
Return the DIE object for a given offset Offset inside the unit's DIE vector.
Definition: DWARFUnit.h:516
DWARFDie getParent(const DWARFDebugInfoEntry *Die)
Definition: DWARFUnit.cpp:889
std::optional< uint64_t > getLoclistOffset(uint32_t Index)
Definition: DWARFUnit.cpp:1199
const char * getCompilationDir()
Definition: DWARFUnit.cpp:389
uint32_t getDIEIndex(const DWARFDie &D) const
Return the index of a DIE inside the unit's DIE vector.
Definition: DWARFUnit.h:499
uint32_t getLineTableOffset() const
Definition: DWARFUnit.h:536
uint64_t getStringOffsetsBase() const
Definition: DWARFUnit.h:398
dwarf::DwarfFormat getFormat() const
Definition: DWARFUnit.h:327
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:1139
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:525
uint64_t getAbbreviationsOffset() const
Definition: DWARFUnit.h:403
uint16_t getVersion() const
Definition: DWARFUnit.h:318
void getInlinedChainForAddress(uint64_t Address, SmallVectorImpl< DWARFDie > &InlinedChain)
getInlinedChainForAddress - fetches inlined chain for a given address.
Definition: DWARFUnit.cpp:860
uint64_t getAbbrOffset() const
Definition: DWARFUnit.h:330
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:365
Expected< uint64_t > getStringOffsetSectionItem(uint32_t Index) const
Definition: DWARFUnit.cpp:231
uint32_t getDIEIndex(const DWARFDebugInfoEntry *Die) const
Return the index of a Die entry inside the unit's DIE vector.
Definition: DWARFUnit.h:262
die_iterator_range dies()
Definition: DWARFUnit.h:543
Expected< DWARFLocationExpressionsVector > findLoclistFromOffset(uint64_t Offset)
Definition: DWARFUnit.cpp:697
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:655
bool isLittleEndian() const
Definition: DWARFUnit.h:310
const DWARFDebugInfoEntry * getPreviousSiblingEntry(const DWARFDebugInfoEntry *Die) const
Definition: DWARFUnit.cpp:941
virtual void dump(raw_ostream &OS, DIDumpOptions DumpOpts)=0
const DWARFUnitVector & getUnitVector() const
Return the DWARFUnitVector containing this unit.
Definition: DWARFUnit.h:484
const DWARFDebugInfoEntry * getLastChildEntry(const DWARFDebugInfoEntry *Die) const
Definition: DWARFUnit.cpp:1005
const DWARFSection & getStringOffsetSection() const
Definition: DWARFUnit.h:334
const DWARFSection & getLineSection() const
Definition: DWARFUnit.h:332
StringRef getStringSection() const
Definition: DWARFUnit.h:333
void updateVariableDieMap(DWARFDie Die)
Recursively update address to variable Die map.
Definition: DWARFUnit.cpp:765
DWARFDie getSubroutineForAddress(uint64_t Address)
Returns subprogram DIE with address range encompassing the provided address.
Definition: DWARFUnit.cpp:751
const DWARFDebugInfoEntry * getFirstChildEntry(const DWARFDebugInfoEntry *Die) const
Definition: DWARFUnit.cpp:980
const std::optional< StrOffsetsContributionDescriptor > & getStringOffsetsTableContribution() const
Definition: DWARFUnit.h:389
uint8_t getDwarfOffsetByteSize() const
Definition: DWARFUnit.h:321
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:672
static bool isMatchingUnitTypeAndTag(uint8_t UnitType, dwarf::Tag Tag)
Definition: DWARFUnit.h:407
uint64_t getNextUnitOffset() const
Definition: DWARFUnit.h:331
std::optional< object::SectionedAddress > getBaseAddress()
Definition: DWARFUnit.cpp:1048
Expected< DWARFAddressRangesVector > collectAddressRanges()
Definition: DWARFUnit.cpp:682
std::optional< object::SectionedAddress > getAddrOffsetSectionItem(uint32_t Index) const
Definition: DWARFUnit.cpp:208
DWARFUnit * getLinkedUnit()
Definition: DWARFUnit.h:342
bool isTypeUnit() const
Definition: DWARFUnit.h:329
DWARFDie getDIEAtIndex(unsigned Index)
Return the DIE object at the given index Index.
Definition: DWARFUnit.h:504
uint64_t getOffset() const
Definition: DWARFUnit.h:314
DWARFDie getLastChild(const DWARFDebugInfoEntry *Die)
Definition: DWARFUnit.cpp:997
void updateAddressDieMap(DWARFDie Die)
Recursively update address to Die map.
Definition: DWARFUnit.cpp:720
bool isDWOUnit() const
Definition: DWARFUnit.h:311
Implements a dense probed hash-table based set.
Definition: DenseSet.h:271
Lightweight error class with error context and mandatory checking.
Definition: Error.h:156
Tagged union holding either a T or a Error.
Definition: Error.h:470
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:1200
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
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:757
bool isUnitType(uint8_t UnitType)
Definition: Dwarf.h:557
UnitType
Constants for unit types in DWARF v5.
Definition: Dwarf.h:543
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:406
@ Length
Definition: DWP.cpp:406
const DWARFUnitIndex & getDWARFUnitIndex(DWARFContext &Context, DWARFSectionKind Kind)
Definition: DWARFUnit.cpp:881
auto partition_point(R &&Range, Predicate P)
Binary search for the first iterator in a range where a predicate is false.
Definition: STLExtras.h:2076
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:664
bool isCompileUnit(const std::unique_ptr< DWARFUnit > &U)
Definition: DWARFUnit.h:578
Container for dump options that control which debug information will be dumped.
Definition: DIContext.h:189
Represents base address of the CU.
Definition: DWARFUnit.h:182
Expected< StrOffsetsContributionDescriptor > validateContributionSize(DWARFDataExtractor &DA)
Determine whether a contribution to the string offsets table is consistent with the relevant section ...
Definition: DWARFUnit.cpp:1060
dwarf::DwarfFormat getFormat() const
Definition: DWARFUnit.h:195
uint64_t Size
The contribution size not including the header.
Definition: DWARFUnit.h:185
StrOffsetsContributionDescriptor(uint64_t Base, uint64_t Size, uint8_t Version, dwarf::DwarfFormat Format)
Definition: DWARFUnit.h:189
A helper struct providing information about the byte size of DW_FORM values that vary in size dependi...
Definition: Dwarf.h:731
DwarfFormat Format
Definition: Dwarf.h:734
uint8_t getDwarfOffsetByteSize() const
The size of a reference is determined by the DWARF 32/64-bit format.
Definition: Dwarf.h:749
uint8_t getRefAddrByteSize() const
The definition of the size of form DW_FORM_ref_addr depends on the version.
Definition: Dwarf.h:742