Go to the documentation of this file.
38 using namespace dwarf;
48 if (!PropName.empty())
51 OS <<
format(
"DW_APPLE_PROPERTY_0x%" PRIx64,
Bit);
61 unsigned AddressSize,
unsigned Indent,
69 R.dump(OS, AddressSize, DumpOpts, &Obj);
77 "bad FORM for location list");
82 if (FormValue.
getForm() == DW_FORM_loclistx) {
83 FormValue.
dump(OS, DumpOpts);
86 Offset = *LoclistOffset;
100 "bad FORM for location expression");
111 return D.getAttributeValueAsReferencedDie(
F).resolveTypeUnitReference();
119 const char BaseIndent[] =
" ";
137 if (Attr == DW_AT_decl_file || Attr == DW_AT_call_file) {
140 if (
LT->getFileNameByIndex(
143 File =
'"' + File +
'"';
151 else if (Attr == DW_AT_decl_line || Attr == DW_AT_call_line)
153 else if (Attr == DW_AT_low_pc &&
157 FormValue.
dump(OS, DumpOpts);
163 }
else if (Attr == DW_AT_high_pc && !DumpOpts.
ShowForm && !DumpOpts.
Verbose &&
171 FormValue.
dump(OS, DumpOpts);
183 FormValue.
dump(OS, DumpOpts);
190 if (Attr == DW_AT_specification || Attr == DW_AT_abstract_origin) {
191 if (
const char *
Name =
194 OS << Space <<
"\"" <<
Name <<
'\"';
195 }
else if (Attr == DW_AT_type || Attr == DW_AT_containing_type) {
197 if (
D && !
D.isNULL()) {
202 }
else if (Attr == DW_AT_APPLE_property_attribute) {
205 }
else if (Attr == DW_AT_ranges) {
209 if (FormValue.
getForm() == DW_FORM_rnglistx)
210 if (
auto RangeListOffset =
213 dwarf::DW_FORM_sec_offset, *RangeListOffset);
214 FV.
dump(OS, DumpOpts);
218 sizeof(BaseIndent) + Indent + 4, DumpOpts);
222 toString(RangesOrError.takeError()).c_str()));
229 std::string *OriginalFullName)
const {
230 const char *NamePtr = getShortName();
233 if (
getTag() == DW_TAG_GNU_template_parameter_pack)
242 return Tag == DW_TAG_subprogram ||
Tag == DW_TAG_inlined_subroutine;
248 auto AbbrevDecl = getAbbreviationDeclarationPtr();
250 return AbbrevDecl->getAttributeValue(
getOffset(), Attr, *U);
258 auto AbbrevDecl = getAbbreviationDeclarationPtr();
260 for (
auto Attr :
Attrs) {
261 if (
auto Value = AbbrevDecl->getAttributeValue(
getOffset(), Attr, *U))
271 Worklist.push_back(*
this);
280 while (!Worklist.empty()) {
291 Worklist.push_back(
D);
295 Worklist.push_back(
D);
304 return getAttributeValueAsReferencedDie(*
F);
313 Result = SpecRef->Unit->getDIEForOffset(SpecRef->Unit->getOffset() +
315 else if (
auto SpecUnit =
316 U->getUnitVector().getUnitForOffset(SpecRef->Offset))
317 Result = SpecUnit->getDIEForOffset(SpecRef->Offset);
323 if (
auto Attr =
find(DW_AT_signature)) {
326 U->getVersion(), *Sig, U->isDWOUnit()))
327 return TU->getDIEForOffset(TU->getTypeOffset() + TU->getOffset());
343 if (LowPC == Tombstone)
345 if (
auto FormValue =
find(DW_AT_high_pc)) {
346 if (
auto Address = FormValue->getAsAddress()) {
350 if (
auto Offset = FormValue->getAsUnsignedConstant()) {
352 return LowPC + *Offset;
360 auto F =
find(DW_AT_low_pc);
364 if (
auto HighPcAddr = getHighPC(LowPcAddr->Address)) {
365 LowPC = LowPcAddr->Address;
366 HighPC = *HighPcAddr;
367 SectionIndex = LowPcAddr->SectionIndex;
378 if (getLowAndHighPC(LowPC, HighPC,
Index))
383 if (
Value->getForm() == DW_FORM_rnglistx)
384 return U->findRnglistFromIndex(*
Value->getAsSectionOffset());
385 return U->findRnglistFromOffset(*
Value->getAsSectionOffset());
391 auto RangesOrError = getAddressRanges();
392 if (!RangesOrError) {
397 for (
const auto &R : RangesOrError.get())
398 if (R.LowPC <= Address && Address < R.HighPC)
413 if (Location->getForm() == DW_FORM_loclistx) {
414 if (
auto LoclistOffset = U->getLoclistOffset(Offset))
415 Offset = *LoclistOffset;
418 "Loclist table not found");
420 return U->findLoclistFromOffset(Offset);
435 if (!isSubroutineDIE())
448 return getShortName();
462 return dwarf::toString(findRecursively({dwarf::DW_AT_MIPS_linkage_name,
463 dwarf::DW_AT_linkage_name}),
468 return toUnsigned(findRecursively(DW_AT_decl_line), 0);
473 if (
auto FormValue = findRecursively(DW_AT_decl_file))
474 if (
auto OptString = FormValue->getAsFile(
Kind))
481 uint32_t &CallDiscriminator)
const {
489 if (
auto SizeAttr =
find(DW_AT_byte_size))
494 case DW_TAG_pointer_type:
495 case DW_TAG_reference_type:
496 case DW_TAG_rvalue_reference_type:
498 case DW_TAG_ptr_to_member_type: {
500 if (
BaseType.getTag() == DW_TAG_subroutine_type)
504 case DW_TAG_const_type:
505 case DW_TAG_immutable_type:
506 case DW_TAG_volatile_type:
507 case DW_TAG_restrict_type:
508 case DW_TAG_typedef: {
513 case DW_TAG_array_type: {
522 if (Child.
getTag() != DW_TAG_subrange_type)
525 if (
auto ElemCountAttr = Child.
find(DW_AT_count))
527 ElemCountAttr->getAsUnsignedConstant())
529 if (
auto UpperBoundAttr = Child.
find(DW_AT_upper_bound))
531 UpperBoundAttr->getAsSignedConstant()) {
532 int64_t LowerBound = 0;
533 if (
auto LowerBoundAttr = Child.
find(DW_AT_lower_bound))
534 LowerBound = LowerBoundAttr->getAsSignedConstant().value_or(0);
535 Size *= *UpperBound - LowerBound + 1;
556 Die.
dump(OS, Indent, DumpOpts);
578 <<
format(
"\n0x%8.8" PRIx64
": ", Offset);
581 auto AbbrevDecl = getAbbreviationDeclarationPtr();
586 OS <<
format(
" [%u] %c", abbrCode,
587 AbbrevDecl->hasChildren() ?
'*' :
' ');
589 OS <<
format(
" (0x%8.8" PRIx64
")",
590 U->getDIEAtIndex(*ParentIdx).getOffset());
604 Child.
dump(OS, Indent + 2, ChildDumpOpts);
609 OS <<
"Abbreviation code not found in 'debug_abbrev' class for code: "
613 OS.
indent(Indent) <<
"NULL\n";
658 assert(AbbrDecl &&
"Must have abbreviation declaration");
661 Index = AbbrDecl->getNumAttributes();
664 AttrValue.
Offset =
D.getOffset() + AbbrDecl->getCodeByteSize();
665 updateForIndex(*AbbrDecl, 0);
669 void DWARFDie::attribute_iterator::updateForIndex(
674 if (
Index < NumAttrs) {
677 AttrValue.Offset += AttrValue.ByteSize;
678 uint64_t ParseOffset = AttrValue.Offset;
684 auto U = Die.getDwarfUnit();
685 assert(U &&
"Die must have valid DWARF unit");
689 AttrValue.ByteSize = ParseOffset - AttrValue.Offset;
691 assert(
Index == NumAttrs &&
"Indexes should be [0, NumAttrs) only");
698 updateForIndex(*AbbrDecl,
Index + 1);
705 case DW_AT_string_length:
706 case DW_AT_return_addr:
707 case DW_AT_data_member_location:
708 case DW_AT_frame_base:
709 case DW_AT_static_link:
711 case DW_AT_use_location:
712 case DW_AT_vtable_elem_location:
723 case DW_AT_byte_size:
724 case DW_AT_bit_offset:
726 case DW_AT_string_length:
727 case DW_AT_lower_bound:
728 case DW_AT_return_addr:
729 case DW_AT_bit_stride:
730 case DW_AT_upper_bound:
732 case DW_AT_data_member_location:
733 case DW_AT_frame_base:
735 case DW_AT_static_link:
736 case DW_AT_use_location:
737 case DW_AT_vtable_elem_location:
738 case DW_AT_allocated:
739 case DW_AT_associated:
740 case DW_AT_data_location:
741 case DW_AT_byte_stride:
743 case DW_AT_call_value:
744 case DW_AT_call_origin:
745 case DW_AT_call_target:
746 case DW_AT_call_target_clobbered:
747 case DW_AT_call_data_location:
748 case DW_AT_call_data_value:
750 case DW_AT_GNU_call_site_value:
751 case DW_AT_GNU_call_site_target:
765 std::string *OriginalFullName) {
std::vector< DWARFLocationExpression > DWARFLocationExpressionsVector
Represents a set of absolute location expressions.
const DWARFDebugLine::LineTable * getLineTableForUnit(DWARFUnit *U)
Get a pointer to a parsed line table corresponding to a compile unit.
static StringRef getName(Value *V)
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
This is an optimization pass for GlobalISel generic memory operations.
DWARFDie getPreviousSibling() const
Get the previous sibling of this DIE object.
Optional< uint64_t > getRangesBaseAttribute() const
Extract the range base attribute from this DIE as absolute section offset.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die, const DWARFAttribute &AttrValue, unsigned Indent, DIDumpOptions DumpOpts)
DWARFFormValue Value
The form and value for this attribute.
const char * getLinkageName() const
Return the DIE linkage name resolving DW_AT_specification or DW_AT_abstract_origin references if nece...
Optional< uint64_t > getRnglistOffset(uint32_t Index)
Return a rangelist's offset based on an index.
LLVM_DUMP_METHOD void dump() const
Convenience zero-argument overload for debugging.
DWARFDie resolveTypeUnitReference() const
dwarf::Attribute Attr
The attribute enumeration of this attribute.
dwarf::Form getFormByIndex(uint32_t idx) const
A raw_ostream that writes to an std::string.
const char * getShortName() const
Return the DIE short name resolving DW_AT_specification or DW_AT_abstract_origin references if necess...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Optional< object::SectionedAddress > toSectionedAddress(const Optional< DWARFFormValue > &V)
const DWARFAbbreviationDeclaration * getAbbreviationDeclarationPtr() const
Get the abbreviation declaration for this DIE.
void appendUnqualifiedName(DWARFDie D, std::string *OriginalFullName=nullptr)
Recursively append the DIE type name when applicable.
dwarf::Attribute getAttrByIndex(uint32_t idx) const
static void dumpLocationList(raw_ostream &OS, const DWARFFormValue &FormValue, DWARFUnit *U, unsigned Indent, DIDumpOptions DumpOpts)
DWARFContext This data structure is the top level entity that deals with dwarf debug information pars...
Represents a single DWARF expression, whose value is location-dependent.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
An RAII object that temporarily switches an output stream to a specific color.
bool addressRangeContainsAddress(const uint64_t Address) const
A structured debug information entry.
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
void print(raw_ostream &OS, DIDumpOptions DumpOpts, const MCRegisterInfo *RegInfo, DWARFUnit *U, bool IsEH=false) const
Deduce and propagate attributes
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
Tagged union holding either a T or a Error.
const DWARFAbbreviationDeclaration * getAbbreviationDeclarationPtr() const
LLVM_NODISCARD T pop_back_val()
const dwarf::FormParams & getFormParams() const
static void dumpLocationExpr(raw_ostream &OS, const DWARFFormValue &FormValue, DWARFUnit *U, unsigned Indent, DIDumpOptions DumpOpts)
void consumeError(Error Err)
Consume a Error without doing anything.
static Error getOffset(const SymbolRef &Sym, SectionRef Sec, uint64_t &Result)
Optional< uint64_t > getLoclistOffset(uint32_t Index)
uint64_t Offset
The debug info/types offset for this attribute.
DWARFDie getLastChild() const
Get the last child of this DIE object.
auto formatv(const char *Fmt, Ts &&... Vals) -> formatv_object< decltype(std::make_tuple(detail::build_format_adapter(std::forward< Ts >(Vals))...))>
Encapsulates a DWARF attribute value and all of the data required to describe the attribute value.
static void dumpRanges(const DWARFObject &Obj, raw_ostream &OS, const DWARFAddressRangesVector &Ranges, unsigned AddressSize, unsigned Indent, const DIDumpOptions &DumpOpts)
DINameKind
A DINameKind is passed to name search methods to specify a preference regarding the type of name reso...
static void dumpApplePropertyAttribute(raw_ostream &OS, uint64_t Val)
uint64_t computeTombstoneAddress(uint8_t AddressByteSize)
StringRef AttributeValueString(uint16_t Attr, unsigned Val)
Returns the symbolic string representing Val when used as a value for attribute Attr.
bool isSubroutineDIE() const
Returns true if DIE represents a subprogram or an inlined subroutine.
unsigned getTag(StringRef TagString)
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.
static DWARFDie resolveReferencedType(DWARFDie D, DWARFFormValue F)
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...
unsigned ChildRecurseDepth
std::string getDeclFile(DILineInfoSpecifier::FileLineInfoKind Kind) const
Optional< uint64_t > toSectionOffset(const Optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an section offset.
This class implements an extremely fast bulk output stream that can only output to a stream.
StringRef FormEncodingString(unsigned Encoding)
void dump(raw_ostream &OS, unsigned indent=0, DIDumpOptions DumpOpts=DIDumpOptions()) const
Dump the DIE and all of its attributes to the supplied stream.
void appendQualifiedName(DWARFDie D)
static std::string getLinkageName(GlobalValue::LinkageTypes LT)
DWARFTypeUnit * getTypeUnitForHash(uint16_t Version, uint64_t Hash, bool IsDWO)
bar al al movzbl eax ret Missed when stored in a memory object
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
uint64_t getDeclLine() const
Returns the declaration line (start line) for a DIE, assuming it specifies a subprogram.
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
Expected< DWARFAddressRangesVector > getAddressRanges() const
Get the address ranges for this DIE.
void dumpTypeUnqualifiedName(const DWARFDie &DIE, raw_ostream &OS, std::string *OriginalFullName=nullptr)
Optional< DWARFFormValue > find(dwarf::Attribute Attr) const
Extract the specified attribute from this DIE.
constexpr uint64_t PointerSize
x86_64 pointer size.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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...
bool getLowAndHighPC(uint64_t &LowPC, uint64_t &HighPC, uint64_t &SectionIndex) const
Retrieves DW_AT_low_pc and DW_AT_high_pc from CU.
Optional< const char * > toString(const Optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract a string value from it.
Expected< DWARFLocationExpressionsVector > getLocations(dwarf::Attribute Attr) const
const char * getCompilationDir()
size_t getNumAttributes() const
bool isLittleEndian() const
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.
bool getAttrIsImplicitConstByIndex(uint32_t idx) const
StringRef - Represent a constant reference to a string, i.e.
DWARFContext & getContext() const
DWARFUnit * getDwarfUnit() const
static const Function * getParent(const Value *V)
const char * getName(DINameKind Kind) const
Return the DIE name resolving DW_AT_specification or DW_AT_abstract_origin references if necessary.
Optional< uint64_t > getLocBaseAttribute() const
StringRef ApplePropertyString(unsigned)
DWARFDie getSibling() const
Get the sibling of this DIE object.
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
static bool mayHaveLocationExpr(dwarf::Attribute Attr)
Identifies DWARF attributes that may contain a reference to a DWARF expression.
unsigned const MachineRegisterInfo * MRI
attribute_iterator & operator++()
DWARFDie getParent() const
Get the parent of this DIE object.
uint8_t getAddressByteSize() const
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
std::vector< DWARFAddressRange > DWARFAddressRangesVector
DWARFAddressRangesVector - represents a set of absolute address ranges.
void dumpTypeQualifiedName(const DWARFDie &DIE, raw_ostream &OS)
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
const MCRegisterInfo * getRegisterInfo() const
void getFullName(raw_string_ostream &, std::string *OriginalFullName=nullptr) const
int64_t getAttrImplicitConstValueByIndex(uint32_t idx) const
Optional< uint64_t > toUnsigned(const Optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an unsigned constant.
DWARFDie getAttributeValueAsReferencedDie(dwarf::Attribute Attr) const
Extract the specified attribute from this DIE as the referenced DIE.
static bool isValid(const char C)
Returns true if C is a valid mangled character: <0-9a-zA-Z_>.
dwarf::Tag getTag() const
llvm::Optional< object::SectionedAddress > getBaseAddress()
iterator_range< attribute_iterator > attributes() const
Get an iterator range to all attributes in the current DIE only.
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
Optional< uint64_t > getTypeSize(uint64_t PointerSize)
Gets the type size (in bytes) for this DIE.
const DWARFObject & getDWARFObj() const
size_t size() const
size - Get the array size.
A range adaptor for a pair of iterators.
attribute_iterator()=delete
const LLVM_NODISCARD char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Optional< uint64_t > getHighPC(uint64_t LowPC) const
Get the DW_AT_high_pc attribute value as an address.
static bool mayHaveLocationList(dwarf::Attribute Attr)
Identify DWARF attributes that may contain a pointer to a location list.
Utility class that carries the DWARF compile/type unit and the debug info entry in an object.
bool isSubprogramDIE() const
Returns true if DIE represents a subprogram (not inlined).
const DWARFLocationTable & getLocationTable()
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.
LLVM Value Representation.
StringRef AttributeString(unsigned Attribute)
DWARFDie getFirstChild() const
Get the first child of this DIE object.
unsigned ParentRecurseDepth
const char * getSubroutineName(DINameKind Kind) const
If a DIE represents a subprogram (or inlined subroutine), returns its mangled name (or short name,...
Container for dump options that control which debug information will be dumped.
std::function< void(Error)> RecoverableErrorHandler