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