37using namespace object;
43 assert(Shift < 64 &&
"undefined behavior");
46 if (!PropName.empty())
49 OS <<
format(
"DW_APPLE_PROPERTY_0x%" PRIx64, Bit);
59 unsigned AddressSize,
unsigned Indent,
67 R.dump(
OS, AddressSize, DumpOpts, &Obj);
75 "bad FORM for location list");
79 if (FormValue.
getForm() == DW_FORM_loclistx) {
80 FormValue.
dump(
OS, DumpOpts);
82 if (
auto LoclistOffset = U->getLoclistOffset(
Offset))
87 U->getLocationTable().dumpLocationList(
96 "bad FORM for location expression");
106 return D.getAttributeValueAsReferencedDie(
F).resolveTypeUnitReference();
114 const char BaseIndent[] =
" ";
131 auto Color = HighlightColor::Enumerator;
132 if (Attr == DW_AT_decl_file || Attr == DW_AT_call_file) {
133 Color = HighlightColor::String;
134 if (
const auto *LT = U->getContext().getLineTableForUnit(U)) {
136 if (LT->getFileNameByIndex(
137 *Val, U->getCompilationDir(),
138 DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath,
140 File =
'"' + File +
'"';
150 else if (Attr == DW_AT_decl_line || Attr == DW_AT_call_line) {
154 FormValue.
dump(
OS, DumpOpts);
155 }
else if (Attr == DW_AT_low_pc &&
159 FormValue.
dump(
OS, DumpOpts);
165 }
else if (Attr == DW_AT_high_pc && !DumpOpts.
ShowForm && !DumpOpts.
Verbose &&
173 FormValue.
dump(
OS, DumpOpts);
185 FormValue.
dump(
OS, DumpOpts);
192 if (Attr == DW_AT_specification || Attr == DW_AT_abstract_origin) {
193 if (
const char *
Name =
195 DINameKind::LinkageName))
196 OS << Space <<
"\"" <<
Name <<
'\"';
197 }
else if (Attr == DW_AT_type || Attr == DW_AT_containing_type) {
199 if (
D && !
D.isNULL()) {
204 }
else if (Attr == DW_AT_APPLE_property_attribute) {
207 }
else if (Attr == DW_AT_ranges) {
211 if (FormValue.
getForm() == DW_FORM_rnglistx)
212 if (
auto RangeListOffset =
215 dwarf::DW_FORM_sec_offset, *RangeListOffset);
219 dumpRanges(Obj,
OS, RangesOrError.get(), U->getAddressByteSize(),
220 sizeof(BaseIndent) + Indent + 4, DumpOpts);
223 errc::invalid_argument,
"decoding address ranges: %s",
224 toString(RangesOrError.takeError()).c_str()));
231 std::string *OriginalFullName)
const {
235 if (
getTag() == DW_TAG_GNU_template_parameter_pack)
244 return Tag == DW_TAG_subprogram ||
Tag == DW_TAG_inlined_subroutine;
252 return AbbrevDecl->getAttributeValue(
getOffset(), Attr, *U);
256std::optional<DWARFFormValue>
262 for (
auto Attr : Attrs) {
263 if (
auto Value = AbbrevDecl->getAttributeValue(
getOffset(), Attr, *U))
270std::optional<DWARFFormValue>
282 while (!Worklist.
empty()) {
305 if (std::optional<DWARFFormValue>
F =
find(Attr))
313 if (
auto SpecRef = V.getAsRelativeReference()) {
315 Result = SpecRef->Unit->getDIEForOffset(SpecRef->Unit->getOffset() +
317 else if (
auto SpecUnit =
319 Result = SpecUnit->getDIEForOffset(SpecRef->Offset);
325 if (
auto Attr =
find(DW_AT_signature)) {
326 if (std::optional<uint64_t> Sig = Attr->getAsReferenceUVal()) {
329 return TU->getDIEForOffset(TU->getTypeOffset() + TU->getOffset());
345 if (LowPC == Tombstone)
347 if (
auto FormValue =
find(DW_AT_high_pc)) {
348 if (
auto Address = FormValue->getAsAddress()) {
352 if (
auto Offset = FormValue->getAsUnsignedConstant()) {
362 auto F =
find(DW_AT_low_pc);
366 if (
auto HighPcAddr =
getHighPC(LowPcAddr->Address)) {
367 LowPC = LowPcAddr->Address;
368 HighPC = *HighPcAddr;
369 SectionIndex = LowPcAddr->SectionIndex;
383 std::optional<DWARFFormValue>
Value =
find(DW_AT_ranges);
385 if (
Value->getForm() == DW_FORM_rnglistx)
394 if (!RangesOrError) {
399 for (
const auto &R : RangesOrError.get())
407 std::optional<DWARFFormValue> Location =
find(Attr);
412 if (std::optional<uint64_t> Off = Location->getAsSectionOffset()) {
415 if (Location->getForm() == DW_FORM_loclistx) {
420 "Loclist table not found");
465 dwarf::DW_AT_linkage_name}),
476 if (
auto OptString = FormValue->getAsFile(
Kind))
483 uint32_t &CallDiscriminator)
const {
491 if (
auto SizeAttr =
find(DW_AT_byte_size))
492 if (std::optional<uint64_t>
Size = SizeAttr->getAsUnsignedConstant())
496 case DW_TAG_pointer_type:
497 case DW_TAG_reference_type:
498 case DW_TAG_rvalue_reference_type:
500 case DW_TAG_ptr_to_member_type: {
502 if (
BaseType.getTag() == DW_TAG_subroutine_type)
503 return 2 * PointerSize;
506 case DW_TAG_const_type:
507 case DW_TAG_immutable_type:
508 case DW_TAG_volatile_type:
509 case DW_TAG_restrict_type:
510 case DW_TAG_typedef: {
512 return BaseType.getTypeSize(PointerSize);
515 case DW_TAG_array_type: {
519 std::optional<uint64_t> BaseSize =
BaseType.getTypeSize(PointerSize);
524 if (Child.
getTag() != DW_TAG_subrange_type)
527 if (
auto ElemCountAttr = Child.
find(DW_AT_count))
528 if (std::optional<uint64_t> ElemCount =
529 ElemCountAttr->getAsUnsignedConstant())
531 if (
auto UpperBoundAttr = Child.
find(DW_AT_upper_bound))
532 if (std::optional<int64_t> UpperBound =
533 UpperBoundAttr->getAsSignedConstant()) {
534 int64_t LowerBound = 0;
535 if (
auto LowerBoundAttr = Child.
find(DW_AT_lower_bound))
536 LowerBound = LowerBoundAttr->getAsSignedConstant().value_or(0);
537 Size *= *UpperBound - LowerBound + 1;
544 return BaseType.getTypeSize(PointerSize);
558 Die.
dump(
OS, Indent, DumpOpts);
589 AbbrevDecl->hasChildren() ?
'*' :
' ');
590 if (std::optional<uint32_t> ParentIdx = Die->
getParentIdx())
606 Child.
dump(
OS, Indent + 2, ChildDumpOpts);
611 OS <<
"Abbreviation code not found in 'debug_abbrev' class for code: "
660 assert(AbbrDecl &&
"Must have abbreviation declaration");
663 Index = AbbrDecl->getNumAttributes();
666 AttrValue.
Offset =
D.getOffset() + AbbrDecl->getCodeByteSize();
667 updateForIndex(*AbbrDecl, 0);
671void DWARFDie::attribute_iterator::updateForIndex(
676 if (
Index < NumAttrs) {
679 AttrValue.Offset += AttrValue.ByteSize;
680 uint64_t ParseOffset = AttrValue.Offset;
686 auto U = Die.getDwarfUnit();
687 assert(U &&
"Die must have valid DWARF unit");
691 AttrValue.ByteSize = ParseOffset - AttrValue.Offset;
693 assert(
Index == NumAttrs &&
"Indexes should be [0, NumAttrs) only");
700 updateForIndex(*AbbrDecl,
Index + 1);
707 case DW_AT_string_length:
708 case DW_AT_return_addr:
709 case DW_AT_data_member_location:
710 case DW_AT_frame_base:
711 case DW_AT_static_link:
713 case DW_AT_use_location:
714 case DW_AT_vtable_elem_location:
725 case DW_AT_byte_size:
726 case DW_AT_bit_offset:
728 case DW_AT_string_length:
729 case DW_AT_lower_bound:
730 case DW_AT_return_addr:
731 case DW_AT_bit_stride:
732 case DW_AT_upper_bound:
734 case DW_AT_data_member_location:
735 case DW_AT_frame_base:
737 case DW_AT_static_link:
738 case DW_AT_use_location:
739 case DW_AT_vtable_elem_location:
740 case DW_AT_allocated:
741 case DW_AT_associated:
742 case DW_AT_data_location:
743 case DW_AT_byte_stride:
745 case DW_AT_call_value:
746 case DW_AT_call_origin:
747 case DW_AT_call_target:
748 case DW_AT_call_target_clobbered:
749 case DW_AT_call_data_location:
750 case DW_AT_call_data_value:
752 case DW_AT_GNU_call_site_value:
753 case DW_AT_GNU_call_site_target:
767 std::string *OriginalFullName) {
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die, const DWARFAttribute &AttrValue, unsigned Indent, DIDumpOptions DumpOpts)
static void dumpLocationExpr(raw_ostream &OS, const DWARFFormValue &FormValue, DWARFUnit *U, unsigned Indent, DIDumpOptions DumpOpts)
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.
static DWARFDie resolveReferencedType(DWARFDie D, DWARFFormValue F)
static void dumpLocationList(raw_ostream &OS, const DWARFFormValue &FormValue, DWARFUnit *U, unsigned Indent, DIDumpOptions DumpOpts)
static void dumpApplePropertyAttribute(raw_ostream &OS, uint64_t Val)
static void dumpRanges(const DWARFObject &Obj, raw_ostream &OS, const DWARFAddressRangesVector &Ranges, unsigned AddressSize, unsigned Indent, const DIDumpOptions &DumpOpts)
This file contains constants used for implementing Dwarf debug support.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallSet class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
A structured debug information entry.
size_t getNumAttributes() const
bool getAttrIsImplicitConstByIndex(uint32_t idx) const
dwarf::Attribute getAttrByIndex(uint32_t idx) const
int64_t getAttrImplicitConstValueByIndex(uint32_t idx) const
dwarf::Form getFormByIndex(uint32_t idx) const
DWARFContext This data structure is the top level entity that deals with dwarf debug information pars...
bool isLittleEndian() const
DWARFTypeUnit * getTypeUnitForHash(uint16_t Version, uint64_t Hash, bool IsDWO)
const DWARFObject & getDWARFObj() const
std::optional< uint32_t > getParentIdx() const
Returns index of the parent die.
const DWARFAbbreviationDeclaration * getAbbreviationDeclarationPtr() const
attribute_iterator & operator++()
attribute_iterator()=delete
Utility class that carries the DWARF compile/type unit and the debug info entry in an object.
void getFullName(raw_string_ostream &, std::string *OriginalFullName=nullptr) const
DWARFDie resolveTypeUnitReference() const
std::optional< uint64_t > getLocBaseAttribute() const
uint64_t getOffset() const
Get the absolute offset into the debug info or types section.
const char * getShortName() const
Return the DIE short name resolving DW_AT_specification or DW_AT_abstract_origin references if necess...
Expected< DWARFAddressRangesVector > getAddressRanges() const
Get the address ranges for this DIE.
DWARFDie getAttributeValueAsReferencedDie(dwarf::Attribute Attr) const
Extract the specified attribute from this DIE as the referenced DIE.
DWARFDie getParent() const
Get the parent of this DIE object.
std::optional< DWARFFormValue > find(dwarf::Attribute Attr) const
Extract the specified attribute from this DIE.
DWARFUnit * getDwarfUnit() const
const char * getSubroutineName(DINameKind Kind) const
If a DIE represents a subprogram (or inlined subroutine), returns its mangled name (or short name,...
DWARFDie getSibling() const
Get the sibling of this DIE object.
bool isSubroutineDIE() const
Returns true if DIE represents a subprogram or an inlined subroutine.
bool getLowAndHighPC(uint64_t &LowPC, uint64_t &HighPC, uint64_t &SectionIndex) const
Retrieves DW_AT_low_pc and DW_AT_high_pc from CU.
LLVM_DUMP_METHOD void dump() const
Convenience zero-argument overload for debugging.
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...
bool isSubprogramDIE() const
Returns true if DIE represents a subprogram (not inlined).
bool addressRangeContainsAddress(const uint64_t Address) const
std::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...
std::optional< uint64_t > getHighPC(uint64_t LowPC) const
Get the DW_AT_high_pc attribute value as an address.
std::optional< uint64_t > getTypeSize(uint64_t PointerSize)
Gets the type size (in bytes) for this DIE.
const char * getName(DINameKind Kind) const
Return the DIE name resolving DW_AT_specification or DW_AT_abstract_origin references if necessary.
DWARFDie getLastChild() const
Get the last child of this DIE object.
DWARFDie getPreviousSibling() const
Get the previous sibling of this DIE object.
const DWARFAbbreviationDeclaration * getAbbreviationDeclarationPtr() const
Get the abbreviation declaration for this DIE.
std::string getDeclFile(DILineInfoSpecifier::FileLineInfoKind Kind) const
DWARFDie getFirstChild() const
Get the first child of this DIE object.
uint64_t getDeclLine() const
Returns the declaration line (start line) for a DIE, assuming it specifies a subprogram.
dwarf::Tag getTag() const
const char * getLinkageName() const
Return the DIE linkage name resolving DW_AT_specification or DW_AT_abstract_origin references if nece...
Expected< DWARFLocationExpressionsVector > getLocations(dwarf::Attribute Attr) const
std::optional< uint64_t > getRangesBaseAttribute() const
Extract the range base attribute from this DIE as absolute section offset.
bool isNULL() const
Returns true for a valid DIE that terminates a sibling chain.
iterator_range< attribute_iterator > attributes() const
Get an iterator range to all attributes in the current DIE only.
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 print(raw_ostream &OS, DIDumpOptions DumpOpts, DWARFUnit *U, bool IsEH=false) const
DWARFUnit * getUnitForOffset(uint64_t Offset) const
DWARFDie getPreviousSibling(const DWARFDebugInfoEntry *Die)
DWARFDie getFirstChild(const DWARFDebugInfoEntry *Die)
DWARFDataExtractor getDebugInfoExtractor() const
DWARFDie getSibling(const DWARFDebugInfoEntry *Die)
DWARFContext & getContext() const
uint8_t getAddressByteSize() const
DWARFDie getParent(const DWARFDebugInfoEntry *Die)
std::optional< uint64_t > getLoclistOffset(uint32_t Index)
uint16_t getVersion() const
Expected< DWARFLocationExpressionsVector > findLoclistFromOffset(uint64_t Offset)
Expected< DWARFAddressRangesVector > findRnglistFromOffset(uint64_t Offset)
Return a vector of address ranges resulting from a (possibly encoded) range list starting at a given ...
const DWARFUnitVector & getUnitVector() const
Return the DWARFUnitVector containing this unit.
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 getDIEAtIndex(unsigned Index)
Return the DIE object at the given index Index.
DWARFDie getLastChild(const DWARFDebugInfoEntry *Die)
Tagged union holding either a T or a Error.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
LLVM Value Representation.
An RAII object that temporarily switches an output stream to a specific color.
A range adaptor for a pair of iterators.
This class implements an extremely fast bulk output stream that can only output to a stream.
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
A raw_ostream that writes to an std::string.
StringRef AttributeString(unsigned Attribute)
StringRef FormEncodingString(unsigned Encoding)
StringRef ApplePropertyString(unsigned)
std::optional< const char * > toString(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract a string value from it.
std::optional< object::SectionedAddress > toSectionedAddress(const std::optional< DWARFFormValue > &V)
std::optional< uint64_t > toSectionOffset(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an section offset.
StringRef AttributeValueString(uint16_t Attr, unsigned Val)
Returns the symbolic string representing Val when used as a value for attribute Attr.
uint64_t computeTombstoneAddress(uint8_t AddressByteSize)
std::optional< uint64_t > toUnsigned(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an unsigned constant.
This is an optimization pass for GlobalISel generic memory operations.
auto formatv(const char *Fmt, Ts &&... Vals) -> formatv_object< decltype(std::make_tuple(detail::build_format_adapter(std::forward< Ts >(Vals))...))>
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
std::vector< DWARFAddressRange > DWARFAddressRangesVector
DWARFAddressRangesVector - represents a set of absolute address ranges.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
std::vector< DWARFLocationExpression > DWARFLocationExpressionsVector
Represents a set of absolute location expressions.
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
void dumpTypeQualifiedName(const DWARFDie &DIE, raw_ostream &OS)
DINameKind
A DINameKind is passed to name search methods to specify a preference regarding the type of name reso...
void dumpTypeUnqualifiedName(const DWARFDie &DIE, raw_ostream &OS, std::string *OriginalFullName=nullptr)
void consumeError(Error Err)
Consume a Error without doing anything.
Container for dump options that control which debug information will be dumped.
std::function< void(Error)> RecoverableErrorHandler
unsigned ChildRecurseDepth
unsigned ParentRecurseDepth
Encapsulates a DWARF attribute value and all of the data required to describe the attribute value.
uint64_t Offset
The debug info/types offset for this attribute.
static bool mayHaveLocationList(dwarf::Attribute Attr)
Identify DWARF attributes that may contain a pointer to a location list.
DWARFFormValue Value
The form and value for this attribute.
static bool mayHaveLocationExpr(dwarf::Attribute Attr)
Identifies DWARF attributes that may contain a reference to a DWARF expression.
dwarf::Attribute Attr
The attribute enumeration of this attribute.
Represents a single DWARF expression, whose value is location-dependent.
void appendQualifiedName(DWARFDie D)
void appendUnqualifiedName(DWARFDie D, std::string *OriginalFullName=nullptr)
Recursively append the DIE type name when applicable.