9#ifndef LLVM_DEBUGINFO_DWARF_DWARFUNIT_H
10#define LLVM_DEBUGINFO_DWARF_DWARFUNIT_H
37class DWARFAbbreviationDeclarationSet;
39class DWARFDebugAbbrev;
41class DWARFDebugRangeList;
42class DWARFLocationTable;
47namespace dwarf_linker {
72 std::optional<uint64_t> DWOId;
102 std::optional<uint64_t>
getDWOId()
const {
return DWOId; }
104 assert((!DWOId || *DWOId == Id) &&
"setting DWOId to a different value");
112 return UnitType == dwarf::DW_UT_type || UnitType == dwarf::DW_UT_split_type;
135 int NumInfoUnits = -1;
172 return NumInfoUnits == -1 ?
size() : NumInfoUnits;
227 std::unique_ptr<DWARFLocationTable> LocTable;
234 std::optional<uint64_t> AddrOffsetSectionBase;
241 std::optional<StrOffsetsContributionDescriptor>
242 StringOffsetsTableContribution;
245 std::optional<object::SectionedAddress> BaseAddr;
247 std::vector<DWARFDebugInfoEntry> DieArray;
252 std::map<uint64_t, std::pair<uint64_t, DWARFDie>> AddrDieMap;
256 std::map<uint64_t, std::pair<uint64_t, DWARFDie>> VariableDieMap;
262 std::shared_ptr<DWARFUnit> DWO;
274 auto First = DieArray.data();
275 assert(Die >= First && Die < First + DieArray.size());
282 return &DieArray[
Index];
327 return Header.getFormParams();
333 return Header.getDwarfOffsetByteSize();
346 return StringOffsetSection;
356 AddrOffsetSection = AOS;
357 AddrOffsetSectionBase =
Base;
361 return AddrOffsetSectionBase;
366 if (std::optional<uint64_t> AddrOffsetSectionBase =
367 getAddrOffsetSectionBase())
368 return *AddrOffsetSectionBase +
Index * getAddressByteSize();
374 void updateAddressDieMap(
DWARFDie Die);
377 void updateVariableDieMap(
DWARFDie Die);
381 RangeSectionBase =
Base;
385 return LocSectionBase;
388 std::optional<object::SectionedAddress>
408 const std::optional<StrOffsetsContributionDescriptor> &
410 extractDIEsIfNeeded(
true );
411 return StringOffsetsTableContribution;
415 assert(StringOffsetsTableContribution);
416 return StringOffsetsTableContribution->getDwarfOffsetByteSize();
420 assert(StringOffsetsTableContribution);
421 return StringOffsetsTableContribution->Base;
430 case dwarf::DW_UT_compile:
431 return Tag == dwarf::DW_TAG_compile_unit;
432 case dwarf::DW_UT_type:
433 return Tag == dwarf::DW_TAG_type_unit;
434 case dwarf::DW_UT_partial:
435 return Tag == dwarf::DW_TAG_partial_unit;
436 case dwarf::DW_UT_skeleton:
437 return Tag == dwarf::DW_TAG_skeleton_unit;
438 case dwarf::DW_UT_split_compile:
439 case dwarf::DW_UT_split_type:
440 return dwarf::isUnitType(Tag);
445 std::optional<object::SectionedAddress> getBaseAddress();
448 extractDIEsIfNeeded(ExtractUnitDIEOnly);
449 if (DieArray.empty())
451 return DWARFDie(
this, &DieArray[0]);
456 parseDWO(DWOAlternativeLocation);
457 return DWO ? DWO->getUnitDIE(ExtractUnitDIEOnly)
458 : getUnitDIE(ExtractUnitDIEOnly);
461 const char *getCompilationDir();
463 extractDIEsIfNeeded(
true);
464 return getHeader().getDWOId();
501 void getInlinedChainForAddress(
uint64_t Address,
510 extractDIEsIfNeeded(
false);
511 return DieArray.size();
521 return getDIEIndex(
D.getDebugInfoEntry());
538 if (std::optional<uint32_t> DieIdx = getDIEIndexForOffset(
Offset))
539 return DWARFDie(
this, &DieArray[*DieIdx]);
547 extractDIEsIfNeeded(
false);
552 if (It != DieArray.end() && It->getOffset() ==
Offset)
553 return It - DieArray.begin();
558 if (
auto IndexEntry = Header.getIndexEntry())
559 if (
const auto *Contrib = IndexEntry->getContribution(DW_SECT_LINE))
560 return Contrib->getOffset32();
565 extractDIEsIfNeeded(
false);
571 Error tryExtractDIEsIfNeeded(
bool CUDieOnly);
575 size_t getDebugInfoSize()
const {
576 return Header.getLength() + Header.getUnitLengthFieldByteSize() -
582 void extractDIEsIfNeeded(
bool CUDieOnly);
585 void extractDIEsToVector(
bool AppendCUDie,
bool AppendNonCUDIEs,
586 std::vector<DWARFDebugInfoEntry> &DIEs)
const;
589 void clearDIEs(
bool KeepCUDie);
596 bool parseDWO(
StringRef AlternativeLocation = {});
600 return !U->isTypeUnit();
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")
This file defines the DenseSet and SmallDenseSet classes.
This file contains constants used for implementing Dwarf debug support.
This file defines the SmallVector class.
A structured debug information entry.
unsigned getOffset() const
Get the compile/type unit relative offset of this DIE.
DWARFContext This data structure is the top level entity that deals with dwarf debug information pars...
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.
An abstract base class for various kinds of location tables (.debug_loc, .debug_loclists,...
Describe a collection of units.
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.
typename UnitVector::iterator iterator
void finishedInfoUnits()
Indicate that parsing .debug_info[.dwo] is done, and remaining units will be from ....
unsigned getNumTypesUnits() const
Returns number of units from all .debug_types[.dwo] sections.
unsigned getNumUnits() const
Returns number of all units held by this instance.
LLVM_ABI void addUnitsForSection(DWARFContext &C, const DWARFSection &Section, DWARFSectionKind SectionKind)
Read units from a .debug_info or .debug_types section.
LLVM_ABI DWARFUnit * getUnitForOffset(uint64_t Offset) const
decltype(make_filter_range(std::declval< iterator_range >(), isCompileUnit)) compile_unit_range
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.
LLVM_ABI DWARFUnit * getUnitForIndexEntry(const DWARFUnitIndex::Entry &E)
const DWARFDebugInfoEntry * getDebugInfoEntry(unsigned Index) const
Return DWARFDebugInfoEntry for the specified index Index.
std::optional< uint64_t > getDWOId()
uint32_t getHeaderSize() const
Size in bytes of the parsed unit header.
const DWARFLocationTable & getLocationTable()
unsigned getNumDIEs()
Returns the number of DIEs in the unit.
const dwarf::FormParams & getFormParams() const
DWARFDie getNonSkeletonUnitDIE(bool ExtractUnitDIEOnly=true, StringRef DWOAlternativeLocation={})
uint8_t getUnitType() const
uint64_t getLength() const
uint8_t getRefAddrByteSize() const
DataExtractor getStringExtractor() const
DWARFDie getUnitDIE(bool ExtractUnitDIEOnly=true)
DWARFContext & getContext() const
uint8_t getAddressByteSize() const
void setSkeletonUnit(DWARFUnit *SU)
std::optional< uint64_t > getAddrOffsetSectionBase() const
const DWARFSection & getInfoSection() const
void setAddrOffsetSection(const DWARFSection *AOS, uint64_t Base)
void setDWOId(uint64_t NewID)
uint64_t getLocSectionBase() const
void setRangesSection(const DWARFSection *RS, uint64_t Base)
uint8_t getDwarfStringOffsetsByteSize() const
const DWARFUnitHeader & getHeader() const
DWARFDie getDIEForOffset(uint64_t Offset)
Return the DIE object for a given offset Offset inside the unit's DIE vector.
uint32_t getDIEIndex(const DWARFDie &D) const
Return the index of a DIE inside the unit's DIE vector.
uint32_t getLineTableOffset() const
uint64_t getStringOffsetsBase() const
dwarf::DwarfFormat getFormat() const
std::optional< uint32_t > getDIEIndexForOffset(uint64_t Offset)
Return the DIE index for a given offset Offset inside the unit's DIE vector.
uint64_t getAbbreviationsOffset() const
uint16_t getVersion() const
std::optional< uint64_t > getIndexedAddressOffset(uint64_t Index)
Returns offset to the indexed address value inside .debug_addr section.
uint64_t getAbbrOffset() const
uint32_t getDIEIndex(const DWARFDebugInfoEntry *Die) const
Return the index of a Die entry inside the unit's DIE vector.
die_iterator_range dies()
bool isLittleEndian() const
virtual void dump(raw_ostream &OS, DIDumpOptions DumpOpts)=0
const DWARFUnitVector & getUnitVector() const
Return the DWARFUnitVector containing this unit.
const DWARFSection & getStringOffsetSection() const
const DWARFSection & getLineSection() const
StringRef getStringSection() const
uint8_t getDwarfOffsetByteSize() const
static bool isMatchingUnitTypeAndTag(uint8_t UnitType, dwarf::Tag Tag)
uint64_t getNextUnitOffset() const
const std::optional< StrOffsetsContributionDescriptor > & getStringOffsetsTableContribution()
DWARFUnit * getLinkedUnit()
DWARFDie getDIEAtIndex(unsigned Index)
Return the DIE object at the given index Index.
uint64_t getOffset() const
Implements a dense probed hash-table based set.
Lightweight error class with error context and mandatory checking.
Tagged union holding either a T or a Error.
SectionKind - This is a simple POD value that classifies the properties of a section.
typename SuperClass::iterator iterator
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
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.
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.
uint8_t getUnitLengthFieldByteSize(DwarfFormat Format)
Get the byte size of the unit length field depending on the DWARF format.
DwarfFormat
Constants that define the DWARF format as 32 or 64 bit.
This is an optimization pass for GlobalISel generic memory operations.
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.
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...
bool isCompileUnit(const std::unique_ptr< DWARFUnit > &U)
Container for dump options that control which debug information will be dumped.
Represents base address of the CU.
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
uint8_t getVersion() const
uint64_t Size
The contribution size not including the header.
StrOffsetsContributionDescriptor()=default
dwarf::FormParams FormParams
Format and version.
uint8_t getDwarfOffsetByteSize() const
StrOffsetsContributionDescriptor(uint64_t Base, uint64_t Size, uint8_t Version, dwarf::DwarfFormat Format)