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,
70 R.dump(OS, AddressSize);
72 if (SectionNames.
empty() || R.SectionIndex == -1ULL)
76 OS <<
" \"" << Name <<
'\"';
79 if (!SectionNames[R.SectionIndex].IsNameUnique)
80 OS <<
format(
" [%" PRIu64
"]", R.SectionIndex);
100 FormValue.
dump(OS, DumpOpts);
111 uint64_t BaseAddr = 0;
113 BaseAddr = BA->Address;
117 OS <<
"error extracting location list.";
118 }
else if (!LocDWOSection.
Data.
empty()) {
124 OS <<
"error extracting location list.";
134 OS << TagStr.
substr(7, TagStr.
size() - 12) <<
" ";
153 case DW_TAG_array_type:
154 case DW_TAG_pointer_type:
155 case DW_TAG_ptr_to_member_type:
156 case DW_TAG_reference_type:
157 case DW_TAG_rvalue_reference_type:
167 case DW_TAG_array_type:
170 case DW_TAG_pointer_type:
173 case DW_TAG_ptr_to_member_type:
176 case DW_TAG_reference_type:
179 case DW_TAG_rvalue_reference_type:
193 const char BaseIndent[] =
" ";
213 if (Attr == DW_AT_decl_file || Attr == DW_AT_call_file) {
216 if (
LT->getFileNameByIndex(
220 File =
'"' + File +
'"';
228 else if (Attr == DW_AT_decl_line || Attr == DW_AT_call_line)
230 else if (Attr == DW_AT_high_pc && !DumpOpts.
ShowForm && !DumpOpts.
Verbose &&
234 uint64_t LowPC, HighPC,
Index;
236 OS <<
format(
"0x%016" PRIx64, HighPC);
238 formValue.
dump(OS, DumpOpts);
240 }
else if (Attr == DW_AT_location || Attr == DW_AT_frame_base ||
241 Attr == DW_AT_data_member_location ||
242 Attr == DW_AT_GNU_call_site_value)
243 dumpLocation(OS, formValue, U,
sizeof(BaseIndent) + Indent + 4, DumpOpts);
245 formValue.
dump(OS, DumpOpts);
250 if (Attr == DW_AT_specification || Attr == DW_AT_abstract_origin) {
253 OS <<
" \"" << Name <<
'\"';
254 }
else if (Attr == DW_AT_type) {
258 }
else if (Attr == DW_AT_APPLE_property_attribute) {
261 }
else if (Attr == DW_AT_ranges) {
266 if (Value && Value->
getForm() == DW_FORM_rnglistx)
267 if (
auto RangeListOffset =
271 FV.
dump(OS, DumpOpts);
275 sizeof(BaseIndent) + Indent + 4, DumpOpts);
278 <<
toString(RangesOrError.takeError()) <<
'\n';
288 return Tag == DW_TAG_subprogram ||
Tag == DW_TAG_inlined_subroutine;
294 auto AbbrevDecl = getAbbreviationDeclarationPtr();
296 return AbbrevDecl->getAttributeValue(
getOffset(), Attr, *U);
304 auto AbbrevDecl = getAbbreviationDeclarationPtr();
306 for (
auto Attr : Attrs) {
307 if (
auto Value = AbbrevDecl->getAttributeValue(
getOffset(), Attr, *U))
316 std::vector<DWARFDie> Worklist;
317 Worklist.push_back(*
this);
325 while (!Worklist.empty()) {
341 Worklist.push_back(
D);
344 Worklist.push_back(
D);
353 if (
auto SpecUnit = U->getUnitSection().getUnitForOffset(*SpecRef))
354 return SpecUnit->getDIEForOffset(*SpecRef);
364 if (
auto FormValue =
find(DW_AT_high_pc)) {
365 if (
auto Address = FormValue->getAsAddress()) {
369 if (
auto Offset = FormValue->getAsUnsignedConstant()) {
378 uint64_t &SectionIndex)
const {
379 auto F =
find(DW_AT_low_pc);
383 if (
auto HighPcAddr = getHighPC(*LowPcAddr)) {
385 HighPC = *HighPcAddr;
386 SectionIndex =
F->getSectionIndex();
396 uint64_t LowPC, HighPC,
Index;
397 if (getLowAndHighPC(LowPC, HighPC, Index))
402 if (Value->
getForm() == DW_FORM_rnglistx)
413 if (isSubprogramDIE()) {
414 if (
auto DIERangesOrError = getAddressRanges())
415 Ranges.insert(Ranges.end(), DIERangesOrError.get().begin(),
416 DIERangesOrError.get().end());
422 Child.collectChildrenAddressRanges(Ranges);
426 auto RangesOrError = getAddressRanges();
427 if (!RangesOrError) {
432 for (
const auto &R : RangesOrError.get())
433 if (R.LowPC <= Address && Address < R.HighPC)
439 if (!isSubroutineDIE())
450 findRecursively({DW_AT_MIPS_linkage_name, DW_AT_linkage_name}),
460 return toUnsigned(findRecursively(DW_AT_decl_line), 0);
465 uint32_t &CallDiscriminator)
const {
478 Die.
dump(OS, Indent, DumpOpts);
500 <<
format(
"\n0x%8.8x: ", Offset);
503 auto AbbrevDecl = getAbbreviationDeclarationPtr();
508 OS <<
format(
" [%u] %c", abbrCode,
509 AbbrevDecl->hasChildren() ?
'*' :
' ');
513 for (
const auto &AttrSpec : AbbrevDecl->attributes()) {
514 if (AttrSpec.Form == DW_FORM_implicit_const) {
520 dumpAttribute(OS, *
this, &offset, AttrSpec.Attr, AttrSpec.Form,
530 child.
dump(OS, Indent + 2, ChildDumpOpts);
535 OS <<
"Abbreviation code not found in 'debug_abbrev' class for code: " 539 OS.
indent(Indent) <<
"NULL\n";
582 : Die(D), AttrValue(0),
Index(0) {
584 assert(AbbrDecl &&
"Must have abbreviation declaration");
587 Index = AbbrDecl->getNumAttributes();
591 updateForIndex(*AbbrDecl, 0);
595 void DWARFDie::attribute_iterator::updateForIndex(
600 if (
Index < NumAttrs) {
607 assert(U &&
"Die must have valid DWARF unit");
609 &ParseOffset, U->getFormParams(), U);
611 assert(b &&
"extractValue cannot fail on fully parsed DWARF");
614 assert(
Index == NumAttrs &&
"Indexes should be [0, NumAttrs) only");
621 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
virtual const DWARFSection & getLocDWOSection() const
dwarf::Attribute Attr
The attribute enumeration of this attribute.
Compute iterated dominance frontiers using a linear time algorithm.
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 DWARFAbbreviationDeclaration * getAbbreviationDeclarationPtr() const
Get the abbreviation declaration for this DIE.
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
virtual const DWARFSection & getLocSection() const
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.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
DINameKind
A DINameKind is passed to name search methods to specify a preference regarding the type of name reso...
void dump(raw_ostream &OS, unsigned indent=0, DIDumpOptions DumpOpts=DIDumpOptions()) const
Dump the DIE and all of its attributes to the supplied stream.
Optional< uint64_t > toAddress(const Optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an address.
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.
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...
static void dumpTypeName(raw_ostream &OS, const DWARFDie &Die)
Recursively dump the DIE type name when applicable.
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)
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 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 Optional< LocationList > parseOneLocationList(DataExtractor Data, uint32_t *Offset)
llvm::Optional< BaseAddress > getBaseAddress()
unsigned getTag(StringRef TagString)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
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.
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.
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)
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.
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.
bool empty() const
empty - Check if the array is empty.
DWARFDie getParent() const
Get the parent of this DIE object.
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.