30 using namespace dwarf;
53 :
Context(DC), InfoSection(Section), Abbrev(DA), RangeSection(RS),
54 LineSection(LS), StringSection(SS), StringOffsetSection(SOS),
55 AddrOffsetSection(AOS), isLittleEndian(LE), isDWO(IsDWO),
56 UnitSection(UnitSection), IndexEntry(IndexEntry) {
63 uint64_t &Result)
const {
74 uint64_t &Result)
const {
76 uint32_t Offset = StringOffsetSectionBase + Index * ItemSize;
77 if (StringOffsetSection.
Data.
size() < Offset + ItemSize)
85 Length = debug_info.
getU32(offset_ptr);
93 AbbrOffset = debug_info.
getU32(offset_ptr);
95 AbbrOffset = debug_info.
getU32(offset_ptr);
101 auto *UnitContrib = IndexEntry->
getOffset();
102 if (!UnitContrib || UnitContrib->Length != (Length + 4))
107 AbbrOffset = AbbrEntry->
Offset;
114 if (!LengthOK || !VersionOK || !AddrSizeOK)
121 return Abbrevs !=
nullptr;
127 Offset = *offset_ptr;
134 *offset_ptr = Offset;
143 assert(!DieArray.empty());
146 uint32_t ActualRangeListOffset = RangeSectionBase + RangeListOffset;
147 return RangeList.
extract(RangesData, &ActualRangeListOffset);
156 RangeSectionBase = 0;
157 AddrOffsetSectionBase = 0;
170 void DWARFUnit::extractDIEsToVector(
171 bool AppendCUDie,
bool AppendNonCUDies,
172 std::vector<DWARFDebugInfoEntry> &Dies)
const {
173 if (!AppendCUDie && !AppendNonCUDies)
185 while (DIE.
extractFast(*
this, &DIEOffset, DebugInfoData, NextCUOffset,
190 if (!AppendNonCUDies)
195 Dies.reserve(Dies.size() + getDebugInfoSize() / 14);
204 if (AbbrDecl->hasChildren())
218 if (DIEOffset > NextCUOffset)
219 fprintf(stderr,
"warning: DWARF compile unit extends beyond its "
220 "bounds cu 0x%8.8x at 0x%8.8x'\n",
getOffset(), DIEOffset);
223 size_t DWARFUnit::extractDIEsIfNeeded(
bool CUDieOnly) {
224 if ((CUDieOnly && !DieArray.empty()) ||
228 bool HasCUDie = !DieArray.empty();
229 extractDIEsToVector(!HasCUDie, !CUDieOnly, DieArray);
231 if (DieArray.empty())
237 auto BaseAddr =
toAddress(UnitDie.
find({DW_AT_low_pc, DW_AT_entry_pc}));
240 AddrOffsetSectionBase =
toSectionOffset(UnitDie.find(DW_AT_GNU_addr_base), 0);
241 RangeSectionBase =
toSectionOffset(UnitDie.find(DW_AT_rnglists_base), 0);
247 StringOffsetSectionBase =
251 StringOffsetSectionBase +=
C->Offset;
257 return DieArray.size();
260 bool DWARFUnit::parseDWO() {
288 DWO = std::shared_ptr<DWARFCompileUnit>(std::move(DWOContext), DWOCU);
290 DWO->setAddrOffsetSection(AddrOffsetSection, AddrOffsetSectionBase);
292 DWO->setRangesSection(RangeSection, DWORangesBase ? *DWORangesBase : 0);
296 void DWARFUnit::clearDIEs(
bool KeepCUDie) {
297 if (DieArray.size() > (
unsigned)KeepCUDie) {
305 std::vector<DWARFDebugInfoEntry> TmpArray;
306 DieArray.swap(TmpArray);
309 DieArray.push_back(TmpArray.front());
319 if (!CUDIERanges.empty()) {
320 CURanges.insert(CURanges.end(), CUDIERanges.begin(), CUDIERanges.end());
330 const bool ClearDIEs = extractDIEsIfNeeded(
false) > 1;
334 bool DWOCreated = parseDWO();
336 DWO->collectAddressRanges(CURanges);
350 if (R.LowPC == R.HighPC)
352 auto B = AddrDieMap.upper_bound(R.LowPC);
353 if (
B != AddrDieMap.begin() && R.LowPC < (--
B)->
second.first) {
356 if (R.HighPC <
B->second.first)
357 AddrDieMap[R.HighPC] =
B->second;
358 if (R.LowPC >
B->first)
359 AddrDieMap[
B->first].first = R.LowPC;
361 AddrDieMap[R.LowPC] = std::make_pair(R.HighPC, Die);
374 extractDIEsIfNeeded(
false);
375 if (AddrDieMap.empty())
377 auto R = AddrDieMap.upper_bound(Address);
378 if (R == AddrDieMap.begin())
382 if (Address >= R->second.first)
384 return R->second.second;
396 (DWO ? DWO.get() :
this)->getSubroutineForAddress(Address);
398 while (SubroutineDIE) {
401 SubroutineDIE = SubroutineDIE.
getParent();
424 const uint32_t ParentDepth = Depth - 1;
425 for (
uint32_t I = getDIEIndex(Die) - 1;
I > 0; --
I) {
426 if (DieArray[
I].getDepth() == ParentDepth)
444 for (
size_t I = getDIEIndex(Die) + 1, EndIdx = DieArray.size();
I < EndIdx;
446 if (DieArray[
I].getDepth() ==
Depth)
const DWARFUnitIndex & getTUIndex()
void getInlinedChainForAddress(uint64_t Address, SmallVectorImpl< DWARFDie > &InlinedChain)
getInlinedChainForAddress - fetches inlined chain for a given address.
void push_back(const T &Elt)
void parseDWO(DWARFContext &C, const DWARFSection &DWOSection, DWARFUnitIndex *Index=nullptr)
uint8_t getDwarfOffsetByteSize() const
uint32_t getDepth() const
DWARFAddressRangesVector getAddressRanges() const
Get the address ranges for this DIE.
void setBaseAddress(uint64_t base_addr)
virtual const DWARFSection & getLineSection()=0
std::shared_ptr< DWARFContext > getDWOContext(StringRef AbsolutePath)
void collectAddressRanges(DWARFAddressRangesVector &CURanges)
bool getStringOffsetSectionItem(uint32_t Index, uint64_t &Result) const
virtual uint32_t getHeaderSize() const
Size in bytes of the unit header.
void collectChildrenAddressRanges(DWARFAddressRangesVector &Ranges) const
Get all address ranges for any DW_TAG_subprogram DIEs in this DIE or any of its children.
DWARFDie getSibling(const DWARFDebugInfoEntry *Die)
bool extractRangeList(uint32_t RangeListOffset, DWARFDebugRangeList &RangeList) const
extractRangeList - extracts the range list referenced by this compile unit from .debug_ranges section...
uint32_t getNextUnitOffset() const
const DWARFDebugAbbrev * getDebugAbbrevDWO()
Get a pointer to the parsed dwo abbreviations object.
virtual StringRef getStringDWOSection()=0
Optional< uint64_t > toAddress(const Optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an address.
virtual const DWARFSection & getRangeDWOSection()=0
DWARFDataExtractor getDebugInfoExtractor() const
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
DWARFUnit(DWARFContext &Context, const DWARFSection &Section, const DWARFDebugAbbrev *DA, const DWARFSection *RS, StringRef SS, const DWARFSection &SOS, const DWARFSection *AOS, const DWARFSection &LS, bool LE, bool IsDWO, const DWARFUnitSectionBase &UnitSection, const DWARFUnitIndex::Entry *IndexEntry=nullptr)
static ManagedStatic< DebugCounter > DC
const char * getCompilationDir()
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
LLVM_NODISCARD bool empty() const
void parse(DWARFContext &C, const DWARFSection &Section)
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
const DWARFDebugAbbrev * getDebugAbbrev()
Get a pointer to the parsed DebugAbbrev object.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
uint16_t getVersion() const
DWARFDie getParent() const
Get the parent of this DIE object.
virtual const DWARFSection & getStringOffsetDWOSection()=0
const DWARFAbbreviationDeclarationSet * getAbbreviationDeclarationSet(uint64_t CUAbbrOffset) const
DWARFDie getSibling() const
Get the sibling of this DIE object.
Optional< uint64_t > toSectionOffset(const Optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an section offset.
Utility class that carries the DWARF compile/type unit and the debug info entry in an object...
A structured debug information entry.
bool extractFast(const DWARFUnit &U, uint32_t *OffsetPtr)
Extracts a debug info entry, which is a child of a given unit, starting at a given offset...
const SectionContribution * getOffset(DWARFSectionKind Sec) const
virtual const DWARFSection & getAddrSection()=0
DWARFDie getParent(const DWARFDebugInfoEntry *Die)
Optional< DWARFFormValue > find(dwarf::Attribute Attr) const
Extract the specified attribute from this DIE.
const DWARFUnitIndex & getDWARFUnitIndex(DWARFContext &Context, DWARFSectionKind Kind)
UnitType
Constants for unit types in DWARF v5.
DWARFDie getFirstChild() const
Get the first child of this DIE object.
DWARFDie getUnitDIE(bool ExtractUnitDIEOnly=true)
auto find(R &&Range, const T &Val) -> decltype(std::begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
bool extract(DataExtractor debug_info, uint32_t *offset_ptr)
DWARFContext This data structure is the top level entity that deals with dwarf debug information pars...
Optional< const char * > toString(const Optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract a string value from it.
Optional< uint64_t > getRangesBaseAttribute() const
Extract the range base attribute from this DIE as absolute section offset.
bool isSubroutineDIE() const
Returns true if DIE represents a subprogram or an inlined subroutine.
bool getAddrOffsetSectionItem(uint32_t Index, uint64_t &Result) const
static bool isSupportedVersion(unsigned version)
virtual bool extractImpl(DataExtractor debug_info, uint32_t *offset_ptr)
Optional< uint64_t > getDWOId()
bool is_relative(const Twine &path, Style style=Style::native)
Is path relative?
const DWARFAbbreviationDeclaration * getAbbreviationDeclarationPtr() const
void updateAddressDieMap(DWARFDie Die)
Recursively update address to Die map.
virtual const DWARFSection & getStringOffsetSection()=0
DWARF v5.
uint32_t getOffset() const
const DWARFUnitIndex & getCUIndex()
uint8_t getAddressByteSize() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Base class for all DWARFUnitSection classes.
std::vector< DWARFAddressRange > DWARFAddressRangesVector
DWARFAddressRangesVector - represents a set of absolute address ranges.
virtual const DWARFSection & getLineDWOSection()=0
DWARFDebugInfoEntry - A DIE with only the minimum required data.
StringRef - Represent a constant reference to a string, i.e.
virtual StringRef getStringSection()=0
virtual const DWARFSection & getRangeSection()=0
bool extract(const DWARFDataExtractor &data, uint32_t *offset_ptr)
void setMaxVersionIfGreater(unsigned Version)
virtual bool isLittleEndian() const =0
Optional< uint64_t > toUnsigned(const Optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an unsigned constant.