9#ifndef LLVM_DEBUGINFO_DWARF_DWARFUNIT_H
10#define LLVM_DEBUGINFO_DWARF_DWARFUNIT_H
36class DWARFAbbreviationDeclarationSet;
38class DWARFDebugAbbrev;
40class DWARFDebugRangeList;
41class DWARFLocationTable;
46namespace dwarf_linker {
71 std::optional<uint64_t> DWOId;
100 std::optional<uint64_t>
getDWOId()
const {
return DWOId; }
102 assert((!DWOId || *DWOId == Id) &&
"setting DWOId to a different value");
110 return UnitType == dwarf::DW_UT_type || UnitType == dwarf::DW_UT_split_type;
133 int NumInfoUnits = -1;
168 return NumInfoUnits == -1 ?
size() : NumInfoUnits;
223 std::unique_ptr<DWARFLocationTable> LocTable;
230 std::optional<uint64_t> AddrOffsetSectionBase;
237 std::optional<StrOffsetsContributionDescriptor>
238 StringOffsetsTableContribution;
241 std::optional<object::SectionedAddress> BaseAddr;
243 std::vector<DWARFDebugInfoEntry> DieArray;
248 std::map<uint64_t, std::pair<uint64_t, DWARFDie>> AddrDieMap;
252 std::map<uint64_t, std::pair<uint64_t, DWARFDie>> VariableDieMap;
258 std::shared_ptr<DWARFUnit> DWO;
270 auto First = DieArray.data();
278 return &DieArray[
Index];
323 return Header.getFormParams();
329 return Header.getDwarfOffsetByteSize();
342 return StringOffsetSection;
352 AddrOffsetSection = AOS;
353 AddrOffsetSectionBase =
Base;
357 return AddrOffsetSectionBase;
362 if (std::optional<uint64_t> AddrOffsetSectionBase =
377 RangeSectionBase =
Base;
381 return LocSectionBase;
384 std::optional<object::SectionedAddress>
404 const std::optional<StrOffsetsContributionDescriptor> &
406 extractDIEsIfNeeded(
true );
407 return StringOffsetsTableContribution;
411 assert(StringOffsetsTableContribution);
412 return StringOffsetsTableContribution->getDwarfOffsetByteSize();
416 assert(StringOffsetsTableContribution);
417 return StringOffsetsTableContribution->Base;
426 case dwarf::DW_UT_compile:
427 return Tag == dwarf::DW_TAG_compile_unit;
428 case dwarf::DW_UT_type:
429 return Tag == dwarf::DW_TAG_type_unit;
430 case dwarf::DW_UT_partial:
431 return Tag == dwarf::DW_TAG_partial_unit;
432 case dwarf::DW_UT_skeleton:
433 return Tag == dwarf::DW_TAG_skeleton_unit;
434 case dwarf::DW_UT_split_compile:
435 case dwarf::DW_UT_split_type:
444 extractDIEsIfNeeded(ExtractUnitDIEOnly);
445 if (DieArray.empty())
447 return DWARFDie(
this, &DieArray[0]);
452 parseDWO(DWOAlternativeLocation);
453 return DWO ? DWO->getUnitDIE(ExtractUnitDIEOnly)
459 extractDIEsIfNeeded(
true);
506 extractDIEsIfNeeded(
false);
507 return DieArray.size();
535 return DWARFDie(
this, &DieArray[*DieIdx]);
543 extractDIEsIfNeeded(
false);
548 if (It != DieArray.end() && It->getOffset() ==
Offset)
549 return It - DieArray.begin();
554 if (
auto IndexEntry = Header.getIndexEntry())
555 if (
const auto *Contrib = IndexEntry->getContribution(DW_SECT_LINE))
556 return Contrib->getOffset32();
561 extractDIEsIfNeeded(
false);
571 size_t getDebugInfoSize()
const {
572 return Header.getLength() + Header.getUnitLengthFieldByteSize() -
578 void extractDIEsIfNeeded(
bool CUDieOnly);
581 void extractDIEsToVector(
bool AppendCUDie,
bool AppendNonCUDIEs,
582 std::vector<DWARFDebugInfoEntry> &DIEs)
const;
585 void clearDIEs(
bool KeepCUDie);
592 bool parseDWO(
StringRef AlternativeLocation = {});
596 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.
std::optional< uint64_t > getIndexedAddressOffset(uint64_t Index)
Returns offset to the indexed address value inside .debug_addr section.
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
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()
const std::optional< StrOffsetsContributionDescriptor > & getStringOffsetsTableContribution()
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.
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.
bool isUnitType(uint8_t UnitType)
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...
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
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
dwarf::FormParams FormParams
Format and version.
uint8_t getDwarfOffsetByteSize() const
StrOffsetsContributionDescriptor(uint64_t Base, uint64_t Size, uint8_t Version, dwarf::DwarfFormat Format)