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