9#ifndef LLVM_DEBUGINFO_DWARF_DWARFUNIT_H
10#define LLVM_DEBUGINFO_DWARF_DWARFUNIT_H
36class DWARFAbbreviationDeclarationSet;
38class DWARFDebugAbbrev;
40class DWARFDebugRangeList;
41class DWARFLocationTable;
66 std::optional<uint64_t> DWOId;
95 std::optional<uint64_t>
getDWOId()
const {
return DWOId; }
97 assert((!DWOId || *DWOId == Id) &&
"setting DWOId to a different value");
105 return UnitType == dwarf::DW_UT_type ||
UnitType == dwarf::DW_UT_split_type;
128 int NumInfoUnits = -1;
163 return NumInfoUnits == -1 ?
size() : NumInfoUnits;
218 std::unique_ptr<DWARFLocationTable> LocTable;
225 std::optional<uint64_t> AddrOffsetSectionBase;
232 std::optional<StrOffsetsContributionDescriptor>
233 StringOffsetsTableContribution;
236 std::optional<object::SectionedAddress> BaseAddr;
238 std::vector<DWARFDebugInfoEntry> DieArray;
243 std::map<uint64_t, std::pair<uint64_t, DWARFDie>> AddrDieMap;
247 std::map<uint64_t, std::pair<uint64_t, DWARFDie>> VariableDieMap;
253 std::shared_ptr<DWARFUnit> DWO;
263 auto First = DieArray.data();
264 assert(Die >= First && Die < First + DieArray.size());
271 return &DieArray[
Index];
316 return Header.getFormParams();
322 return Header.getDwarfOffsetByteSize();
335 return StringOffsetSection;
345 AddrOffsetSection = AOS;
346 AddrOffsetSectionBase =
Base;
350 return AddrOffsetSectionBase;
361 RangeSectionBase =
Base;
365 return LocSectionBase;
368 std::optional<object::SectionedAddress>
388 const std::optional<StrOffsetsContributionDescriptor> &
390 return StringOffsetsTableContribution;
394 assert(StringOffsetsTableContribution);
395 return StringOffsetsTableContribution->getDwarfOffsetByteSize();
399 assert(StringOffsetsTableContribution);
400 return StringOffsetsTableContribution->Base;
409 case dwarf::DW_UT_compile:
410 return Tag == dwarf::DW_TAG_compile_unit;
411 case dwarf::DW_UT_type:
412 return Tag == dwarf::DW_TAG_type_unit;
413 case dwarf::DW_UT_partial:
414 return Tag == dwarf::DW_TAG_partial_unit;
415 case dwarf::DW_UT_skeleton:
416 return Tag == dwarf::DW_TAG_skeleton_unit;
417 case dwarf::DW_UT_split_compile:
418 case dwarf::DW_UT_split_type:
427 extractDIEsIfNeeded(ExtractUnitDIEOnly);
428 if (DieArray.empty())
430 return DWARFDie(
this, &DieArray[0]);
435 parseDWO(DWOAlternativeLocation);
436 return DWO ? DWO->getUnitDIE(ExtractUnitDIEOnly)
442 extractDIEsIfNeeded(
true);
489 extractDIEsIfNeeded(
false);
490 return DieArray.size();
518 return DWARFDie(
this, &DieArray[*DieIdx]);
526 extractDIEsIfNeeded(
false);
531 if (It != DieArray.end() && It->getOffset() ==
Offset)
532 return It - DieArray.begin();
537 if (
auto IndexEntry = Header.getIndexEntry())
538 if (
const auto *Contrib = IndexEntry->getContribution(DW_SECT_LINE))
539 return Contrib->getOffset32();
544 extractDIEsIfNeeded(
false);
554 size_t getDebugInfoSize()
const {
555 return Header.getLength() + Header.getUnitLengthFieldByteSize() -
561 void extractDIEsIfNeeded(
bool CUDieOnly);
564 void extractDIEsToVector(
bool AppendCUDie,
bool AppendNonCUDIEs,
565 std::vector<DWARFDebugInfoEntry> &DIEs)
const;
568 void clearDIEs(
bool KeepCUDie);
575 bool parseDWO(
StringRef AlternativeLocation = {});
579 return !U->isTypeUnit();
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.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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.
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.
void addUnitsForSection(DWARFContext &C, const DWARFSection &Section, DWARFSectionKind SectionKind)
Read units from a .debug_info or .debug_types section.
DWARFUnit * getUnitForOffset(uint64_t Offset) const
decltype(make_filter_range(std::declval< iterator_range >(), isCompileUnit)) compile_unit_range
void addUnitsForDWOSection(DWARFContext &C, const DWARFSection &DWOSection, DWARFSectionKind SectionKind, bool Lazy=false)
Read units from a .debug_info.dwo or .debug_types.dwo section.
DWARFUnit * getUnitForIndexEntry(const DWARFUnitIndex::Entry &E)
const DWARFDebugInfoEntry * getDebugInfoEntry(unsigned Index) const
Return DWARFDebugInfoEntry for the specified index Index.
const DWARFDebugInfoEntry * getSiblingEntry(const DWARFDebugInfoEntry *Die) const
std::optional< uint64_t > getDWOId()
uint32_t getHeaderSize() const
Size in bytes of the parsed unit header.
DWARFDie getPreviousSibling(const DWARFDebugInfoEntry *Die)
Expected< std::optional< StrOffsetsContributionDescriptor > > determineStringOffsetsTableContributionDWO(DWARFDataExtractor &DA)
Find the unit's contribution to the string offsets table and determine its length and form.
const DWARFLocationTable & getLocationTable()
unsigned getNumDIEs()
Returns the number of DIEs in the unit.
const dwarf::FormParams & getFormParams() const
const DWARFDebugInfoEntry * getParentEntry(const DWARFDebugInfoEntry *Die) const
DWARFDie getFirstChild(const DWARFDebugInfoEntry *Die)
DWARFDie getNonSkeletonUnitDIE(bool ExtractUnitDIEOnly=true, StringRef DWOAlternativeLocation={})
DWARFDataExtractor getDebugInfoExtractor() const
uint8_t getUnitType() const
uint64_t getLength() const
uint8_t getRefAddrByteSize() const
DWARFDie getSibling(const DWARFDebugInfoEntry *Die)
DataExtractor getStringExtractor() const
std::optional< uint64_t > getRnglistOffset(uint32_t Index)
Return a rangelist's offset based on an index.
Error tryExtractDIEsIfNeeded(bool CUDieOnly)
DWARFDie getUnitDIE(bool ExtractUnitDIEOnly=true)
DWARFContext & getContext() const
uint8_t getAddressByteSize() const
void setSkeletonUnit(DWARFUnit *SU)
DWARFDie getVariableForAddress(uint64_t Address)
Returns variable DIE for the address provided.
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
const DWARFAbbreviationDeclarationSet * getAbbreviations() const
DWARFDie getDIEForOffset(uint64_t Offset)
Return the DIE object for a given offset Offset inside the unit's DIE vector.
DWARFDie getParent(const DWARFDebugInfoEntry *Die)
std::optional< uint64_t > getLoclistOffset(uint32_t Index)
const char * getCompilationDir()
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
Expected< std::optional< StrOffsetsContributionDescriptor > > determineStringOffsetsTableContribution(DWARFDataExtractor &DA)
Find the unit's contribution to the string offsets table and determine its length and form.
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
void getInlinedChainForAddress(uint64_t Address, SmallVectorImpl< DWARFDie > &InlinedChain)
getInlinedChainForAddress - fetches inlined chain for a given address.
uint64_t getAbbrOffset() const
Error extractRangeList(uint64_t RangeListOffset, DWARFDebugRangeList &RangeList) const
Extract the range list referenced by this compile unit from the .debug_ranges section.
Expected< uint64_t > getStringOffsetSectionItem(uint32_t Index) 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()
Expected< DWARFLocationExpressionsVector > findLoclistFromOffset(uint64_t Offset)
Expected< DWARFAddressRangesVector > findRnglistFromOffset(uint64_t Offset)
Return a vector of address ranges resulting from a (possibly encoded) range list starting at a given ...
bool isLittleEndian() const
const DWARFDebugInfoEntry * getPreviousSiblingEntry(const DWARFDebugInfoEntry *Die) const
virtual void dump(raw_ostream &OS, DIDumpOptions DumpOpts)=0
const DWARFUnitVector & getUnitVector() const
Return the DWARFUnitVector containing this unit.
const DWARFDebugInfoEntry * getLastChildEntry(const DWARFDebugInfoEntry *Die) const
const DWARFSection & getStringOffsetSection() const
const DWARFSection & getLineSection() const
StringRef getStringSection() const
void updateVariableDieMap(DWARFDie Die)
Recursively update address to variable Die map.
DWARFDie getSubroutineForAddress(uint64_t Address)
Returns subprogram DIE with address range encompassing the provided address.
const DWARFDebugInfoEntry * getFirstChildEntry(const DWARFDebugInfoEntry *Die) const
const std::optional< StrOffsetsContributionDescriptor > & getStringOffsetsTableContribution() const
uint8_t getDwarfOffsetByteSize() const
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...
static bool isMatchingUnitTypeAndTag(uint8_t UnitType, dwarf::Tag Tag)
uint64_t getNextUnitOffset() const
std::optional< object::SectionedAddress > getBaseAddress()
Expected< DWARFAddressRangesVector > collectAddressRanges()
std::optional< object::SectionedAddress > getAddrOffsetSectionItem(uint32_t Index) const
DWARFUnit * getLinkedUnit()
DWARFDie getDIEAtIndex(unsigned Index)
Return the DIE object at the given index Index.
uint64_t getOffset() const
DWARFDie getLastChild(const DWARFDebugInfoEntry *Die)
void updateAddressDieMap(DWARFDie Die)
Recursively update address to Die map.
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.
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.
bool isUnitType(uint8_t UnitType)
UnitType
Constants for unit types in DWARF v5.
DwarfFormat
Constants that define the DWARF format as 32 or 64 bit.
This is an optimization pass for GlobalISel generic memory operations.
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.
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
uint8_t getDwarfOffsetByteSize() const
StrOffsetsContributionDescriptor(uint64_t Base, uint64_t Size, uint8_t Version, dwarf::DwarfFormat Format)