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