37 using namespace dwarf;
44 assert(Shift < 64 &&
"undefined behavior");
45 uint64_t
Bit = 1ULL << Shift;
47 if (!PropName.empty())
50 OS <<
format(
"DW_APPLE_PROPERTY_0x%" PRIx64, Bit);
60 unsigned AddressSize,
unsigned Indent,
68 R.dump(OS, AddressSize, DumpOpts, &Obj);
90 if (FormValue.
getForm() == DW_FORM_loclistx) {
91 FormValue.
dump(OS, DumpOpts);
94 Offset = *LoclistOffset;
104 FormValue.
dump(OS, DumpOpts);
112 OS << TagStr.
substr(7, TagStr.
size() - 12) <<
" ";
118 if (
C.getTag() == DW_TAG_subrange_type) {
124 LB = L->getAsUnsignedConstant();
126 Count = CountV->getAsUnsignedConstant();
128 UB = UpperV->getAsUnsignedConstant();
134 if (LB && *LB == *DefaultLB)
136 if (!LB && !Count && !UB)
138 else if (!LB && (Count || UB) && DefaultLB)
139 OS <<
'[' << (Count ? *Count : *UB - *DefaultLB + 1) <<
']';
151 OS <<
"? + " << *Count;
175 case DW_TAG_array_type:
176 case DW_TAG_pointer_type:
177 case DW_TAG_ptr_to_member_type:
178 case DW_TAG_reference_type:
179 case DW_TAG_rvalue_reference_type:
180 case DW_TAG_subroutine_type:
191 case DW_TAG_subroutine_type: {
197 if (
C.getTag() == DW_TAG_formal_parameter) {
201 dumpTypeName(OS,
C.getAttributeValueAsReferencedDie(DW_AT_type));
207 case DW_TAG_array_type: {
211 case DW_TAG_pointer_type:
214 case DW_TAG_ptr_to_member_type:
222 case DW_TAG_reference_type:
225 case DW_TAG_rvalue_reference_type:
239 const char BaseIndent[] =
" ";
255 if (Attr == DW_AT_decl_file || Attr == DW_AT_call_file) {
258 if (
LT->getFileNameByIndex(
262 File =
'"' + File +
'"';
270 else if (Attr == DW_AT_decl_line || Attr == DW_AT_call_line)
272 else if (Attr == DW_AT_high_pc && !DumpOpts.
ShowForm && !DumpOpts.
Verbose &&
276 uint64_t LowPC, HighPC,
Index;
278 OS <<
format(
"0x%016" PRIx64, HighPC);
280 FormValue.
dump(OS, DumpOpts);
282 }
else if (Form == dwarf::Form::DW_FORM_exprloc ||
284 dumpLocation(OS, FormValue, U,
sizeof(BaseIndent) + Indent + 4, DumpOpts);
286 FormValue.
dump(OS, DumpOpts);
293 if (Attr == DW_AT_specification || Attr == DW_AT_abstract_origin) {
294 if (
const char *Name =
297 OS << Space <<
"\"" << Name <<
'\"';
298 }
else if (Attr == DW_AT_type) {
302 }
else if (Attr == DW_AT_APPLE_property_attribute) {
305 }
else if (Attr == DW_AT_ranges) {
309 if (FormValue.
getForm() == DW_FORM_rnglistx)
310 if (
auto RangeListOffset =
313 dwarf::DW_FORM_sec_offset, *RangeListOffset);
314 FV.
dump(OS, DumpOpts);
318 sizeof(BaseIndent) + Indent + 4, DumpOpts);
321 <<
toString(RangesOrError.takeError()) <<
'\n';
331 return Tag == DW_TAG_subprogram ||
Tag == DW_TAG_inlined_subroutine;
337 auto AbbrevDecl = getAbbreviationDeclarationPtr();
339 return AbbrevDecl->getAttributeValue(
getOffset(), Attr, *U);
347 auto AbbrevDecl = getAbbreviationDeclarationPtr();
349 for (
auto Attr : Attrs) {
350 if (
auto Value = AbbrevDecl->getAttributeValue(
getOffset(), Attr, *U))
359 std::vector<DWARFDie> Worklist;
360 Worklist.push_back(*
this);
369 while (!Worklist.empty()) {
381 Worklist.push_back(
D);
385 Worklist.push_back(
D);
394 return getAttributeValueAsReferencedDie(*
F);
402 return SpecRef->Unit->getDIEForOffset(SpecRef->Unit->getOffset() + SpecRef->Offset);
403 if (
auto SpecUnit = U->getUnitVector().getUnitForOffset(SpecRef->Offset))
404 return SpecUnit->getDIEForOffset(SpecRef->Offset);
418 if (
auto FormValue =
find(DW_AT_high_pc)) {
419 if (
auto Address = FormValue->getAsAddress()) {
423 if (
auto Offset = FormValue->getAsUnsignedConstant()) {
432 uint64_t &SectionIndex)
const {
433 auto F =
find(DW_AT_low_pc);
437 if (
auto HighPcAddr = getHighPC(LowPcAddr->Address)) {
438 LowPC = LowPcAddr->Address;
439 HighPC = *HighPcAddr;
440 SectionIndex = LowPcAddr->SectionIndex;
450 uint64_t LowPC, HighPC,
Index;
451 if (getLowAndHighPC(LowPC, HighPC, Index))
456 if (Value->
getForm() == DW_FORM_rnglistx)
467 if (isSubprogramDIE()) {
468 if (
auto DIERangesOrError = getAddressRanges())
469 Ranges.insert(Ranges.end(), DIERangesOrError.get().begin(),
470 DIERangesOrError.get().end());
476 Child.collectChildrenAddressRanges(Ranges);
480 auto RangesOrError = getAddressRanges();
481 if (!RangesOrError) {
486 for (
const auto &R : RangesOrError.get())
487 if (R.LowPC <= Address && Address < R.HighPC)
502 if (Location->
getForm() == DW_FORM_loclistx) {
503 if (
auto LoclistOffset = U->getLoclistOffset(Offset))
504 Offset = *LoclistOffset;
507 "Loclist table not found");
509 return U->findLoclistFromOffset(Offset);
524 if (!isSubroutineDIE())
535 findRecursively({DW_AT_MIPS_linkage_name, DW_AT_linkage_name}),
545 return toUnsigned(findRecursively(DW_AT_decl_line), 0);
550 uint32_t &CallDiscriminator)
const {
565 Die.
dump(OS, Indent, DumpOpts);
587 <<
format(
"\n0x%8.8" PRIx64
": ", Offset);
590 auto AbbrevDecl = getAbbreviationDeclarationPtr();
595 OS <<
format(
" [%u] %c", abbrCode,
596 AbbrevDecl->hasChildren() ?
'*' :
' ');
600 for (
const auto &AttrSpec : AbbrevDecl->attributes()) {
601 if (AttrSpec.Form == DW_FORM_implicit_const) {
607 dumpAttribute(OS, *
this, &offset, AttrSpec.Attr, AttrSpec.Form,
617 child.
dump(OS, Indent + 2, ChildDumpOpts);
622 OS <<
"Abbreviation code not found in 'debug_abbrev' class for code: " 626 OS.
indent(Indent) <<
"NULL\n";
671 assert(AbbrDecl &&
"Must have abbreviation declaration");
674 Index = AbbrDecl->getNumAttributes();
678 updateForIndex(*AbbrDecl, 0);
682 void DWARFDie::attribute_iterator::updateForIndex(
687 if (
Index < NumAttrs) {
691 uint64_t ParseOffset = AttrValue.
Offset;
693 assert(U &&
"Die must have valid DWARF unit");
698 assert(
Index == NumAttrs &&
"Indexes should be [0, NumAttrs) only");
705 updateForIndex(*AbbrDecl,
Index + 1);
713 case DW_AT_byte_size:
715 case DW_AT_string_length:
716 case DW_AT_lower_bound:
717 case DW_AT_return_addr:
718 case DW_AT_bit_stride:
719 case DW_AT_upper_bound:
721 case DW_AT_data_member_location:
722 case DW_AT_frame_base:
724 case DW_AT_static_link:
725 case DW_AT_use_location:
726 case DW_AT_vtable_elem_location:
727 case DW_AT_allocated:
728 case DW_AT_associated:
729 case DW_AT_byte_stride:
731 case DW_AT_call_value:
732 case DW_AT_call_origin:
733 case DW_AT_call_target:
734 case DW_AT_call_target_clobbered:
735 case DW_AT_call_data_location:
736 case DW_AT_call_data_value:
738 case DW_AT_GNU_call_site_value:
739 case DW_AT_GNU_call_site_target:
iterator_range< typename GraphTraits< GraphType >::ChildIteratorType > children(const typename GraphTraits< GraphType >::NodeRef &G)
StringRef ApplePropertyString(unsigned)
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
DWARFUnit * getDwarfUnit() const
LLVM_NODISCARD bool endswith(StringRef Suffix) const
Check if this string ends with the given Suffix.
dwarf::Attribute Attr
The attribute enumeration of this attribute.
This class represents lattice values for constants.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
bool isSubprogramDIE() const
Returns true if DIE represents a subprogram (not inlined).
bool dumpLocationList(uint64_t *Offset, raw_ostream &OS, Optional< object::SectionedAddress > BaseAddr, const MCRegisterInfo *MRI, const DWARFObject &Obj, DWARFUnit *U, DIDumpOptions DumpOpts, unsigned Indent) const
Dump the location list at the given Offset.
An RAII object that temporarily switches an output stream to a specific color.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
bool addressRangeContainsAddress(const uint64_t Address) const
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
static raw_ostream & error()
Convenience method for printing "error: " to stderr.
attribute_iterator & operator++()
uint32_t ByteSize
The debug info/types section byte size of the data for this attribute.
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.
const DWARFAbbreviationDeclaration * getAbbreviationDeclarationPtr() const
Get the abbreviation declaration for this DIE.
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
auto formatv(const char *Fmt, Ts &&... Vals) -> formatv_object< decltype(std::make_tuple(detail::build_format_adapter(std::forward< Ts >(Vals))...))>
const DWARFDebugLine::LineTable * getLineTableForUnit(DWARFUnit *U)
Get a pointer to a parsed line table corresponding to a compile unit.
DWARFDie getAttributeValueAsReferencedDie(dwarf::Attribute Attr) const
Extract the specified attribute from this DIE as the referenced DIE.
DINameKind
A DINameKind is passed to name search methods to specify a preference regarding the type of name reso...
Optional< unsigned > LanguageLowerBound(SourceLanguage L)
void dump(raw_ostream &OS, unsigned indent=0, DIDumpOptions DumpOpts=DIDumpOptions()) const
Dump the DIE and all of its attributes to the supplied stream.
DWARFFormValue Value
The form and value for this attribute.
unsigned countTrailingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0's from the least significant bit to the most stopping at the first 1...
iterator_range< iterator > children() const
const char * getCompilationDir()
Optional< uint64_t > getRangesBaseAttribute() const
Extract the range base attribute from this DIE as absolute section offset.
StringRef FormEncodingString(unsigned Encoding)
static StringRef getName(Value *V)
void getCallerFrame(uint32_t &CallFile, uint32_t &CallLine, uint32_t &CallColumn, uint32_t &CallDiscriminator) const
Retrieves values of DW_AT_call_file, DW_AT_call_line and DW_AT_call_column from DIE (or zeroes if the...
Tagged union holding either a T or a Error.
LLVM_NODISCARD StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
const MCRegisterInfo * getRegisterInfo() const
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
uint8_t getAddressByteSize() const
Optional< object::SectionedAddress > toSectionedAddress(const Optional< DWARFFormValue > &V)
static void dumpApplePropertyAttribute(raw_ostream &OS, uint64_t Val)
dwarf::Form getFormByIndex(uint32_t idx) const
StringRef AttributeString(unsigned Attribute)
const T & getValue() const LLVM_LVALUE_FUNCTION
LLVM_NODISCARD size_t size() const
size - Get the string size.
llvm::Optional< object::SectionedAddress > getBaseAddress()
static void dumpRanges(const DWARFObject &Obj, raw_ostream &OS, const DWARFAddressRangesVector &Ranges, unsigned AddressSize, unsigned Indent, const DIDumpOptions &DumpOpts)
static Error getOffset(const SymbolRef &Sym, SectionRef Sec, uint64_t &Result)
bool getLowAndHighPC(uint64_t &LowPC, uint64_t &HighPC, uint64_t &SectionIndex) const
Retrieves DW_AT_low_pc and DW_AT_high_pc from CU.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
uint16_t getVersion() const
DWARFDie getSibling() const
Get the sibling of this DIE object.
StringRef AttributeValueString(uint16_t Attr, unsigned Val)
Returns the symbolic string representing Val when used as a value for attribute Attr.
uint64_t getDeclLine() const
Returns the declaration line (start line) for a DIE, assuming it specifies a subprogram.
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
unsigned ParentRecurseDepth
Container for dump options that control which debug information will be dumped.
attribute_iterator()=delete
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...
DWARFDie getLastChild() const
Get the last child of this DIE object.
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
unsigned const MachineRegisterInfo * MRI
uint64_t Offset
The debug info/types offset for this attribute.
Instrumentation for Order File
size_t size() const
size - Get the array size.
Expected< DWARFLocationExpressionsVector > getLocations(dwarf::Attribute Attr) const
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
bool isSubroutineDIE() const
Returns true if DIE represents a subprogram or an inlined subroutine.
Optional< DWARFFormValue > findRecursively(ArrayRef< dwarf::Attribute > Attrs) const
Extract the first value of any attribute in Attrs from this DIE and recurse into any DW_AT_specificat...
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
DWARFContext & getContext() const
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
void consumeError(Error Err)
Consume a Error without doing anything.
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...
static void dumpArrayType(raw_ostream &OS, const DWARFDie &D)
unsigned getTag(StringRef TagString)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
DWARFDie getUnitDIE(bool ExtractUnitDIEOnly=true)
const char * getName(DINameKind Kind) const
Return the DIE name resolving DW_AT_sepcification or DW_AT_abstract_origin references if necessary...
Color
A "color", which is either even or odd.
Represents a single DWARF expression, whose value is location-dependent.
DWARFDie getPreviousSibling() const
Get the previous sibling of this DIE object.
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< uint64_t > getLocBaseAttribute() const
iterator_range< attribute_iterator > attributes() const
Get an iterator range to all attributes in the current DIE only.
Optional< const char * > toString(const Optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract a string value from it.
A range adaptor for a pair of iterators.
This file contains constants used for implementing Dwarf debug support.
std::vector< DWARFLocationExpression > DWARFLocationExpressionsVector
Represents a set of absolute location expressions.
StringRef TagString(unsigned Tag)
const DWARFLocationTable & getLocationTable()
LLVM_DUMP_METHOD void dump() const
Convenience zero-argument overload for debugging.
dwarf::Tag getTag() const
static bool mayHaveLocationDescription(dwarf::Attribute Attr)
Identifies DWARF attributes that may contain a reference to a DWARF expression.
Expected< DWARFAddressRangesVector > getAddressRanges() const
Get the address ranges for this DIE.
unsigned ChildRecurseDepth
Optional< uint64_t > getRnglistOffset(uint32_t Index)
Return a rangelist's offset based on an index.
bool isLittleEndian() const
const DWARFObject & getDWARFObj() const
Optional< uint64_t > getHighPC(uint64_t LowPC) const
Get the DW_AT_high_pc attribute value as an address.
Optional< uint64_t > getLoclistOffset(uint32_t Index)
static unsigned dumpParentChain(DWARFDie Die, raw_ostream &OS, unsigned Indent, DIDumpOptions DumpOpts, unsigned Depth=0)
Helper to dump a DIE with all of its parents, but no siblings.
dwarf::Attribute getAttrByIndex(uint32_t idx) const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Optional< DWARFFormValue > find(dwarf::Attribute Attr) const
Extract the specified attribute from this DIE.
std::vector< DWARFAddressRange > DWARFAddressRangesVector
DWARFAddressRangesVector - represents a set of absolute address ranges.
LLVM Value Representation.
DWARFDie getFirstChild() const
Get the first child of this DIE object.
static void dumpLocation(raw_ostream &OS, DWARFFormValue &FormValue, DWARFUnit *U, unsigned Indent, DIDumpOptions DumpOpts)
uint64_t getOffset() const
Get the absolute offset into the debug info or types section.
static const Function * getParent(const Value *V)
static void dumpTypeName(raw_ostream &OS, const DWARFDie &D)
Recursively dump the DIE type name when applicable.
This class implements an extremely fast bulk output stream that can only output to a stream...
size_t getNumAttributes() const
static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die, uint64_t *OffsetPtr, dwarf::Attribute Attr, dwarf::Form Form, unsigned Indent, DIDumpOptions DumpOpts)
StringRef - Represent a constant reference to a string, i.e.
const char * getSubroutineName(DINameKind Kind) const
If a DIE represents a subprogram (or inlined subroutine), returns its mangled name (or short name...
Optional< uint64_t > toUnsigned(const Optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an unsigned constant.
static void dumpTypeTagName(raw_ostream &OS, dwarf::Tag T)
Dump the name encoded in the type tag.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
DWARFDie getParent() const
Get the parent of this DIE object.
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...