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,
72 R.dump(OS, AddressSize);
94 FormValue.
dump(OS, DumpOpts);
103 uint64_t BaseAddr = 0;
105 BaseAddr = BA->Address;
109 OS <<
"error extracting location list.";
117 if (!LoclistsSectionData.
empty()) {
128 uint64_t BaseAddr = 0;
130 BaseAddr = BA->Address;
136 OS <<
"error extracting location list.";
146 OS << TagStr.
substr(7, TagStr.
size() - 12) <<
" ";
152 if (
C.getTag() == DW_TAG_subrange_type) {
158 LB = L->getAsUnsignedConstant();
160 Count = CountV->getAsUnsignedConstant();
162 UB = UpperV->getAsUnsignedConstant();
168 if (LB && *LB == *DefaultLB)
170 if (!LB && !Count && !UB)
172 else if (!LB && (Count || UB) && DefaultLB)
173 OS <<
'[' << (Count ? *Count : *UB - *DefaultLB + 1) <<
']';
185 OS <<
"? + " << *Count;
209 case DW_TAG_array_type:
210 case DW_TAG_pointer_type:
211 case DW_TAG_ptr_to_member_type:
212 case DW_TAG_reference_type:
213 case DW_TAG_rvalue_reference_type:
214 case DW_TAG_subroutine_type:
225 case DW_TAG_subroutine_type: {
231 if (
C.getTag() == DW_TAG_formal_parameter) {
235 dumpTypeName(OS,
C.getAttributeValueAsReferencedDie(DW_AT_type));
241 case DW_TAG_array_type: {
245 case DW_TAG_pointer_type:
248 case DW_TAG_ptr_to_member_type:
256 case DW_TAG_reference_type:
259 case DW_TAG_rvalue_reference_type:
273 const char BaseIndent[] =
" ";
293 if (Attr == DW_AT_decl_file || Attr == DW_AT_call_file) {
296 if (
LT->getFileNameByIndex(
300 File =
'"' + File +
'"';
308 else if (Attr == DW_AT_decl_line || Attr == DW_AT_call_line)
310 else if (Attr == DW_AT_high_pc && !DumpOpts.
ShowForm && !DumpOpts.
Verbose &&
314 uint64_t LowPC, HighPC,
Index;
316 OS <<
format(
"0x%016" PRIx64, HighPC);
318 formValue.
dump(OS, DumpOpts);
320 }
else if (Attr == DW_AT_location || Attr == DW_AT_frame_base ||
321 Attr == DW_AT_data_member_location ||
322 Attr == DW_AT_GNU_call_site_value)
323 dumpLocation(OS, formValue, U,
sizeof(BaseIndent) + Indent + 4, DumpOpts);
325 formValue.
dump(OS, DumpOpts);
332 if (Attr == DW_AT_specification || Attr == DW_AT_abstract_origin) {
333 if (
const char *Name =
336 OS << Space <<
"\"" << Name <<
'\"';
337 }
else if (Attr == DW_AT_type) {
341 }
else if (Attr == DW_AT_APPLE_property_attribute) {
344 }
else if (Attr == DW_AT_ranges) {
348 if (formValue.
getForm() == DW_FORM_rnglistx)
349 if (
auto RangeListOffset =
353 FV.
dump(OS, DumpOpts);
357 sizeof(BaseIndent) + Indent + 4, DumpOpts);
360 <<
toString(RangesOrError.takeError()) <<
'\n';
370 return Tag == DW_TAG_subprogram ||
Tag == DW_TAG_inlined_subroutine;
376 auto AbbrevDecl = getAbbreviationDeclarationPtr();
378 return AbbrevDecl->getAttributeValue(
getOffset(), Attr, *U);
386 auto AbbrevDecl = getAbbreviationDeclarationPtr();
388 for (
auto Attr : Attrs) {
389 if (
auto Value = AbbrevDecl->getAttributeValue(
getOffset(), Attr, *U))
398 std::vector<DWARFDie> Worklist;
399 Worklist.push_back(*
this);
407 while (!Worklist.empty()) {
423 Worklist.push_back(
D);
426 Worklist.push_back(
D);
435 return getAttributeValueAsReferencedDie(*
F);
442 if (
auto SpecUnit = U->getUnitVector().getUnitForOffset(*SpecRef))
443 return SpecUnit->getDIEForOffset(*SpecRef);
453 if (
auto FormValue =
find(DW_AT_high_pc)) {
454 if (
auto Address = FormValue->getAsAddress()) {
458 if (
auto Offset = FormValue->getAsUnsignedConstant()) {
467 uint64_t &SectionIndex)
const {
468 auto F =
find(DW_AT_low_pc);
472 if (
auto HighPcAddr = getHighPC(LowPcAddr->Address)) {
473 LowPC = LowPcAddr->Address;
474 HighPC = *HighPcAddr;
475 SectionIndex = LowPcAddr->SectionIndex;
485 uint64_t LowPC, HighPC,
Index;
486 if (getLowAndHighPC(LowPC, HighPC, Index))
491 if (Value->
getForm() == DW_FORM_rnglistx)
502 if (isSubprogramDIE()) {
503 if (
auto DIERangesOrError = getAddressRanges())
504 Ranges.insert(Ranges.end(), DIERangesOrError.get().begin(),
505 DIERangesOrError.get().end());
511 Child.collectChildrenAddressRanges(Ranges);
515 auto RangesOrError = getAddressRanges();
516 if (!RangesOrError) {
521 for (
const auto &R : RangesOrError.get())
522 if (R.LowPC <= Address && Address < R.HighPC)
528 if (!isSubroutineDIE())
539 findRecursively({DW_AT_MIPS_linkage_name, DW_AT_linkage_name}),
549 return toUnsigned(findRecursively(DW_AT_decl_line), 0);
554 uint32_t &CallDiscriminator)
const {
567 Die.
dump(OS, Indent, DumpOpts);
589 <<
format(
"\n0x%8.8x: ", Offset);
592 auto AbbrevDecl = getAbbreviationDeclarationPtr();
597 OS <<
format(
" [%u] %c", abbrCode,
598 AbbrevDecl->hasChildren() ?
'*' :
' ');
602 for (
const auto &AttrSpec : AbbrevDecl->attributes()) {
603 if (AttrSpec.Form == DW_FORM_implicit_const) {
609 dumpAttribute(OS, *
this, &offset, AttrSpec.Attr, AttrSpec.Form,
619 child.
dump(OS, Indent + 2, ChildDumpOpts);
624 OS <<
"Abbreviation code not found in 'debug_abbrev' class for code: " 628 OS.
indent(Indent) <<
"NULL\n";
671 : Die(D), AttrValue(0),
Index(0) {
673 assert(AbbrDecl &&
"Must have abbreviation declaration");
676 Index = AbbrDecl->getNumAttributes();
680 updateForIndex(*AbbrDecl, 0);
684 void DWARFDie::attribute_iterator::updateForIndex(
689 if (
Index < NumAttrs) {
696 assert(U &&
"Die must have valid DWARF unit");
698 &ParseOffset, U->getFormParams(), U);
700 assert(b &&
"extractValue cannot fail on fully parsed DWARF");
703 assert(
Index == NumAttrs &&
"Indexes should be [0, NumAttrs) only");
710 updateForIndex(*AbbrDecl,
Index + 1);
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
dwarf::Attribute Attr
The attribute enumeration of this attribute.
This class represents lattice values for constants.
bool isSubprogramDIE() const
Returns true if DIE represents a subprogram (not inlined).
An RAII object that temporarily switches an output stream to a specific color.
bool addressRangeContainsAddress(const uint64_t Address) const
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.
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 DWARFSection * getLocSection() const
const DWARFAbbreviationDeclaration * getAbbreviationDeclarationPtr() const
Get the abbreviation declaration for this DIE.
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
static unsigned dumpParentChain(DWARFDie Die, raw_ostream &OS, unsigned Indent, DIDumpOptions DumpOpts)
Helper to dump a DIE with all of its parents, but no siblings.
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.
const dwarf::FormParams & getFormParams() const
DWARFFormValue Value
The form and value for this attribute.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool endswith(StringRef Suffix) const
Check if this string ends with the given Suffix.
amdgpu Simplify well known AMD library false Value Value const Twine & Name
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.
static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die, uint32_t *OffsetPtr, dwarf::Attribute Attr, dwarf::Form Form, unsigned Indent, DIDumpOptions DumpOpts)
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.
const MCRegisterInfo * getRegisterInfo() const
uint32_t getOffset() const
Get the absolute offset into the debug info or types section.
uint8_t getAddressByteSize() const
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
static void dumpApplePropertyAttribute(raw_ostream &OS, uint64_t Val)
dwarf::Form getFormByIndex(uint32_t idx) const
const T & getValue() const LLVM_LVALUE_FUNCTION
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
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)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
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...
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...
Optional< uint64_t > toReference(const Optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an reference.
DWARFDie getLastChild() const
Get the last child of this DIE object.
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
unsigned const MachineRegisterInfo * MRI
std::size_t 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...
virtual uint8_t getAddressSize() const
size_t size() const
size - Get the array size.
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 Optional< LocationList > parseOneLocationList(DataExtractor Data, unsigned *Offset, unsigned Version)
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.
Optional< LocationList > parseOneLocationList(DWARFDataExtractor Data, uint32_t *Offset)
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.
DWARFDie getPreviousSibling() const
Get the previous sibling of this DIE object.
uint32_t Offset
The debug info/types offset for this attribute.
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")
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.
StringRef getLocSectionData() const
A range adaptor for a pair of iterators.
This file contains constants used for implementing Dwarf debug support.
DWARFDataExtractor getDebugInfoExtractor() const
StringRef TagString(unsigned Tag)
LLVM_DUMP_METHOD void dump() const
Convenience zero-argument overload for debugging.
dwarf::Tag getTag() const
virtual ArrayRef< SectionName > getSectionNames() const
Expected< DWARFAddressRangesVector > getAddressRanges() const
Get the address ranges for this DIE.
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.
llvm::Optional< SectionedAddress > getBaseAddress()
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)
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
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.
virtual const DWARFSection & getLoclistsSection() const
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.
DWARFDie getParent() const
Get the parent of this DIE object.
Optional< SectionedAddress > toSectionedAddress(const Optional< DWARFFormValue > &V)
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.