32 using namespace dwarf;
57 :
Context(DC), InfoSection(Section), Header(Header), Abbrev(DA),
58 RangeSection(RS), LineSection(LS), StringSection(SS),
59 StringOffsetSection(SOS), AddrOffsetSection(AOS), isLittleEndian(LE),
60 isDWO(IsDWO), UnitSection(UnitSection) {
72 uint64_t &Result)
const {
83 uint64_t &Result)
const {
84 if (!StringOffsetsTableContribution)
88 if (StringOffsetSection.
Data.
size() < Offset + ItemSize)
102 IndexEntry = Index ? Index->
getFromOffset(*offset_ptr) :
nullptr;
103 Length = debug_info.
getU32(offset_ptr);
105 unsigned SizeOfLength = 4;
111 AbbrOffset = debug_info.
getU32(offset_ptr);
125 auto *UnitContrib = IndexEntry->getOffset();
126 if (!UnitContrib || UnitContrib->Length != (Length + 4))
131 AbbrOffset = AbbrEntry->Offset;
134 TypeHash = debug_info.
getU64(offset_ptr);
135 TypeOffset = debug_info.
getU32(offset_ptr);
137 DWOId = debug_info.
getU64(offset_ptr);
140 assert(*offset_ptr -
Offset <= 255 &&
"unexpected header size");
148 : TypeOffset >=
Size && TypeOffset <
getLength() + SizeOfLength;
153 if (!LengthOK || !VersionOK || !AddrSizeOK || !TypeOffsetOK)
173 "Did not detect a valid range list table with base = 0x%x", Offset);
187 assert(!DieArray.empty());
190 uint32_t ActualRangeListOffset = RangeSectionBase + RangeListOffset;
191 return RangeList.
extract(RangesData, &ActualRangeListOffset);
197 RangeSectionBase = 0;
198 AddrOffsetSectionBase = 0;
207 void DWARFUnit::extractDIEsToVector(
208 bool AppendCUDie,
bool AppendNonCUDies,
209 std::vector<DWARFDebugInfoEntry> &Dies)
const {
210 if (!AppendCUDie && !AppendNonCUDies)
222 while (DIE.
extractFast(*
this, &DIEOffset, DebugInfoData, NextCUOffset,
227 if (!AppendNonCUDies)
232 Dies.reserve(Dies.size() + getDebugInfoSize() / 14);
241 if (AbbrDecl->hasChildren())
255 if (DIEOffset > NextCUOffset)
257 "bounds cu 0x%8.8x at 0x%8.8x\n",
261 size_t DWARFUnit::extractDIEsIfNeeded(
bool CUDieOnly) {
262 if ((CUDieOnly && !DieArray.empty()) ||
266 bool HasCUDie = !DieArray.empty();
267 extractDIEsToVector(!HasCUDie, !CUDieOnly, DieArray);
269 if (DieArray.empty())
278 assert(AddrOffsetSectionBase == 0);
279 assert(RangeSectionBase == 0);
280 AddrOffsetSectionBase =
292 uint64_t StringOffsetsContributionBase =
297 StringOffsetsContributionBase +=
C->Offset;
302 StringOffsetsTableContribution =
304 DA, StringOffsetsContributionBase);
307 DA, StringOffsetsContributionBase);
322 if (
auto TableOrError =
324 RngListTable = TableOrError.get();
327 <<
toString(TableOrError.takeError())
332 if (isDWO && RngListTable)
333 RangeSectionBase = RngListTable->getHeaderSize();
341 return DieArray.size();
344 bool DWARFUnit::parseDWO() {
372 DWO = std::shared_ptr<DWARFCompileUnit>(std::move(DWOContext), DWOCU);
374 DWO->setAddrOffsetSection(AddrOffsetSection, AddrOffsetSectionBase);
380 DWO->RngListTable = TableOrError.get();
383 <<
toString(TableOrError.takeError())
385 if (DWO->RngListTable)
386 DWO->RangeSectionBase = DWO->RngListTable->getHeaderSize();
389 DWO->setRangesSection(RangeSection, DWORangesBase ? *DWORangesBase : 0);
395 void DWARFUnit::clearDIEs(
bool KeepCUDie) {
396 if (DieArray.size() > (
unsigned)KeepCUDie) {
397 DieArray.resize((
unsigned)KeepCUDie);
398 DieArray.shrink_to_fit();
412 isLittleEndian, RngListTable->getAddrSize());
413 auto RangeListOrError = RngListTable->findList(RangesData, Offset);
414 if (RangeListOrError)
415 return RangeListOrError.get().getAbsoluteRanges(
getBaseAddress());
416 return RangeListOrError.takeError();
419 return make_error<StringError>(
"missing or invalid range list table",
431 Stream <<
format(
"invalid range list table index %d", Index);
433 Stream <<
"missing or invalid range list table";
443 if (CUDIERangesOrError) {
444 if (!CUDIERangesOrError.get().empty()) {
445 CURanges.insert(CURanges.end(), CUDIERangesOrError.get().begin(),
446 CUDIERangesOrError.get().end());
451 <<
toString(CUDIERangesOrError.takeError()) <<
'\n';
459 const bool ClearDIEs = extractDIEsIfNeeded(
false) > 1;
463 bool DWOCreated = parseDWO();
465 DWO->collectAddressRanges(CURanges);
478 if (DIERangesOrError) {
479 for (
const auto &R : DIERangesOrError.get()) {
481 if (R.LowPC == R.HighPC)
483 auto B = AddrDieMap.upper_bound(R.LowPC);
484 if (
B != AddrDieMap.begin() && R.LowPC < (--
B)->
second.first) {
487 if (R.HighPC <
B->second.first)
488 AddrDieMap[R.HighPC] =
B->second;
489 if (R.LowPC >
B->first)
490 AddrDieMap[
B->first].first = R.LowPC;
492 AddrDieMap[R.LowPC] = std::make_pair(R.HighPC, Die);
507 extractDIEsIfNeeded(
false);
508 if (AddrDieMap.empty())
510 auto R = AddrDieMap.upper_bound(Address);
511 if (R == AddrDieMap.begin())
515 if (Address >= R->second.first)
517 return R->second.second;
535 if (SubroutineDIE.
getTag() == DW_TAG_inlined_subroutine)
537 SubroutineDIE = SubroutineDIE.
getParent();
561 const uint32_t ParentDepth = Depth - 1;
562 for (
uint32_t I = getDIEIndex(Die) - 1;
I > 0; --
I) {
563 if (DieArray[
I].getDepth() == ParentDepth)
581 for (
size_t I = getDIEIndex(Die) + 1, EndIdx = DieArray.size();
I < EndIdx;
583 if (DieArray[
I].getDepth() ==
Depth)
598 for (
size_t I = getDIEIndex(Die);
I > 0;) {
600 if (DieArray[
I].getDepth() == Depth - 1)
602 if (DieArray[
I].getDepth() == Depth)
613 size_t I = getDIEIndex(Die) + 1;
614 if (I >= DieArray.size())
616 return DWARFDie(
this, &DieArray[I]);
624 for (
size_t I = getDIEIndex(Die) + 1, EndIdx = DieArray.size();
I < EndIdx;
626 if (DieArray[
I].getDepth() == Depth + 1 &&
627 DieArray[
I].getTag() == dwarf::DW_TAG_null)
629 assert(DieArray[I].getDepth() > Depth &&
"Not processing children?");
658 uint64_t ValidationSize =
alignTo(
Size, EntrySize);
660 if (ValidationSize >=
Size)
673 if (DA.
getU32(&Offset) != 0xffffffff)
692 if (ContributionSize >= 0xfffffff0)
712 if (!Descriptor && Offset >= 8)
726 return Descriptor ? Descriptor->validateContributionSize(DA) : Descriptor;
734 Size = StringOffsetSection.
Data.
size();
const DWARFAbbreviationDeclarationSet * getAbbreviations() const
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)
virtual const DWARFSection & getAddrSection() const
Compute iterated dominance frontiers using a linear time algorithm.
Represents a unit's contribution to the string offsets table.
bool isSubprogramDIE() const
Returns true if DIE represents a subprogram (not inlined).
std::shared_ptr< DWARFContext > getDWOContext(StringRef AbsolutePath)
void collectAddressRanges(DWARFAddressRangesVector &CURanges)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
static raw_ostream & error()
Convenience method for printing "error: " to stderr.
void collectChildrenAddressRanges(DWARFAddressRangesVector &Ranges) const
Get all address ranges for any DW_TAG_subprogram DIEs in this DIE or any of its children.
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
void parseDWO(DWARFContext &C, const DWARFSection &DWOSection, bool Lazy=false)
DWARFDie getSibling(const DWARFDebugInfoEntry *Die)
static raw_ostream & warning()
Convenience method for printing "warning: " to stderr.
static Optional< StrOffsetsContributionDescriptor > parseDWARF64StringOffsetsTableHeader(DWARFDataExtractor &DA, uint32_t Offset)
Optional< StrOffsetsContributionDescriptor > validateContributionSize(DWARFDataExtractor &DA)
Determine whether a contribution to the string offsets table is consistent with the relevant section ...
uint64_t alignTo(uint64_t Value, uint64_t Align, uint64_t Skew=0)
Returns the next integer (mod 2**64) that is greater than or equal to Value and is a multiple of Alig...
virtual const DWARFSection & getRnglistsDWOSection() const
block Block Frequency true
Optional< StrOffsetsContributionDescriptor > determineStringOffsetsTableContribution(DWARFDataExtractor &DA, uint64_t Offset)
Find the unit's contribution to the string offsets table and determine its length and form...
const DWARFDebugAbbrev * getDebugAbbrevDWO()
Get a pointer to the parsed dwo abbreviations object.
uint8_t getDwarfStringOffsetsByteSize() const
Optional< uint64_t > toAddress(const Optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an address.
DWARFDie getSubroutineForAddress(uint64_t Address)
Returns subprogram DIE with address range encompassing the provided address.
static Optional< StrOffsetsContributionDescriptor > parseDWARF32StringOffsetsTableHeader(DWARFDataExtractor &DA, uint32_t Offset)
virtual bool isLittleEndian() const =0
uint32_t getNextUnitOffset() const
bool getAddrOffsetSectionItem(uint32_t Index, uint64_t &Result) const
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
std::string toString(Error E)
Write all error messages (if any) in E to a string.
static ManagedStatic< DebugCounter > DC
const char * getCompilationDir()
Optional< uint64_t > getRangesBaseAttribute() const
Extract the range base attribute from this DIE as absolute section offset.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Error extractRangeList(uint32_t RangeListOffset, DWARFDebugRangeList &RangeList) const
Extract the range list referenced by this compile unit from the .debug_ranges section.
Tagged union holding either a T or a Error.
virtual const DWARFSection & getStringOffsetDWOSection() const
uint8_t getAddressByteSize() 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.
uint32_t getDepth() const
DWARFDie getLastChild(const DWARFDebugInfoEntry *Die)
uint16_t getVersion() const
DWARFDie getSibling() const
Get the sibling of this DIE object.
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...
DWARFDie getFirstChild(const DWARFDebugInfoEntry *Die)
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...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
virtual const DWARFSection & getStringOffsetSection() const
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
A structured debug information entry.
bool isSubroutineDIE() const
Returns true if DIE represents a subprogram or an inlined subroutine.
Optional< uint64_t > getDWOId()
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 DWARFAbbreviationDeclarationSet * getAbbreviationDeclarationSet(uint64_t CUAbbrOffset) const
DWARFDie getParent(const DWARFDebugInfoEntry *Die)
virtual const DWARFSection & getLineDWOSection() const
SectionKind - This is a simple POD value that classifies the properties of a section.
virtual StringRef getStringSection() const
void setRangesSection(const DWARFSection *RS, uint32_t Base)
virtual StringRef getStringDWOSection() const
uint32_t getHeaderSize() const
Size in bytes of the parsed unit header.
void consumeError(Error Err)
Consume a Error without doing anything.
const DWARFUnitIndex & getDWARFUnitIndex(DWARFContext &Context, DWARFSectionKind Kind)
auto find(R &&Range, const T &Val) -> decltype(adl_begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
DWARFAddressRangesVector getAbsoluteRanges(llvm::Optional< BaseAddress > BaseAddr) const
getAbsoluteRanges - Returns absolute address ranges defined by this range list.
std::string & str()
Flushes the stream contents to the target string and returns the string's reference.
llvm::Optional< BaseAddress > getBaseAddress()
UnitType
Constants for unit types in DWARF v5.
uint64_t getStringOffsetsBase() const
DWARFDie getUnitDIE(bool ExtractUnitDIEOnly=true)
const DWARFAbbreviationDeclaration * getAbbreviationDeclarationPtr() const
static Expected< DWARFDebugRnglistTable > parseRngListTableHeader(DWARFDataExtractor &DA, uint32_t Offset)
Error extractHeaderAndOffsets(DWARFDataExtractor Data, uint32_t *OffsetPtr)
Extract the table header and the array of offsets.
DWARFContext This data structure is the top level entity that deals with dwarf debug information pars...
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
Optional< const char * > toString(const Optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract a string value from it.
virtual const DWARFSection & getRnglistsSection() const
uint32_t getLength() const
DWARFUnit(DWARFContext &Context, const DWARFSection &Section, const DWARFUnitHeader &Header, const DWARFDebugAbbrev *DA, const DWARFSection *RS, StringRef SS, const DWARFSection &SOS, const DWARFSection *AOS, const DWARFSection &LS, bool LE, bool IsDWO, const DWARFUnitSectionBase &UnitSection)
DWARFDataExtractor getDebugInfoExtractor() const
virtual const DWARFSection & getLineSection() const
static bool isSupportedVersion(unsigned version)
virtual const DWARFSection & getRangeDWOSection() const
bool getStringOffsetSectionItem(uint32_t Index, uint64_t &Result) const
dwarf::Tag getTag() const
LLVM_NODISCARD bool empty() const
Expected< DWARFAddressRangesVector > findRnglistFromOffset(uint32_t Offset)
Return a vector of address ranges resulting from a (possibly encoded) range list starting at a given ...
bool is_relative(const Twine &path, Style style=Style::native)
Is path relative?
uint32_t getOffset() const
Expected< DWARFAddressRangesVector > getAddressRanges() const
Get the address ranges for this DIE.
DWARFDie getPreviousSibling(const DWARFDebugInfoEntry *Die)
void updateAddressDieMap(DWARFDie Die)
Recursively update address to Die map.
bool isLittleEndian() const
const DWARFObject & getDWARFObj() const
const DWARFUnitIndex & getCUIndex()
virtual const DWARFSection & getRangeSection() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Base class for all DWARFUnitSection classes.
Optional< DWARFFormValue > find(dwarf::Attribute Attr) const
Extract the specified attribute from this DIE.
A raw_ostream that writes to an std::string.
std::vector< DWARFAddressRange > DWARFAddressRangesVector
DWARFAddressRangesVector - represents a set of absolute address ranges.
DWARFDebugInfoEntry - A DIE with only the minimum required data.
DWARFDie getFirstChild() const
Get the first child of this DIE object.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
Lightweight error class with error context and mandatory checking.
const Entry * getFromOffset(uint32_t Offset) const
StringRef - Represent a constant reference to a string, i.e.
Optional< uint32_t > getRnglistOffset(uint32_t Index)
Return a rangelist's offset based on an index.
uint8_t getDwarfOffsetByteSize() const
void setMaxVersionIfGreater(unsigned Version)
Optional< uint64_t > toUnsigned(const Optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an unsigned constant.
DWARFDie getParent() const
Get the parent of this DIE object.
Error extract(const DWARFDataExtractor &data, uint32_t *offset_ptr)
Optional< StrOffsetsContributionDescriptor > determineStringOffsetsTableContributionDWO(DWARFDataExtractor &DA, uint64_t Offset)
Find the unit's contribution to the string offsets table and determine its length and form...
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...