17 #include "llvm/Support/DataTypes.h"
24 using namespace dwarf;
25 using namespace syntax;
28 static void dumpApplePropertyAttribute(
raw_ostream &OS, uint64_t Val) {
32 assert(Shift < 64 &&
"undefined behavior");
33 uint64_t
Bit = 1ULL << Shift;
35 if (!PropName.empty())
38 OS <<
format(
"DW_APPLE_PROPERTY_0x%" PRIx64, Bit);
47 unsigned AddressSize,
unsigned Indent) {
51 for (
const auto &Range: Ranges) {
54 OS <<
format(
"[0x%0*" PRIx64
" - 0x%0*" PRIx64
")",
55 AddressSize*2, Range.first,
56 AddressSize*2, Range.second);
65 const char BaseIndent[] =
" ";
69 if (!attrString.empty())
75 if (!formString.empty())
76 OS <<
" [" << formString <<
']';
78 OS <<
format(
" [DW_FORM_Unknown_%x]", Form);
91 if (Attr == DW_AT_decl_file || Attr == DW_AT_call_file) {
95 File =
'"' + File +
'"';
103 else if (Attr == DW_AT_decl_line || Attr == DW_AT_call_line)
104 OS << *formValue.getAsUnsignedConstant();
111 if (Attr == DW_AT_specification || Attr == DW_AT_abstract_origin) {
113 OS <<
" \"" << Name <<
'\"';
114 }
else if (Attr == DW_AT_APPLE_property_attribute) {
116 dumpApplePropertyAttribute(OS, *OptVal);
117 }
else if (Attr == DW_AT_ranges) {
119 sizeof(BaseIndent)+Indent+4);
128 return getTag() == DW_TAG_subprogram;
133 return Tag == DW_TAG_subprogram ||
Tag == DW_TAG_inlined_subroutine;
140 auto AbbrevDecl = getAbbreviationDeclarationPtr();
142 return AbbrevDecl->getAttributeValue(
getOffset(), Attr, *U);
147 const char *FailValue)
const {
148 auto FormValue = getAttributeValue(Attr);
157 if (
auto FormValue = getAttributeValue(Attr))
158 return FormValue->getAsAddress();
164 if (
auto FormValue = getAttributeValue(Attr))
165 return FormValue->getAsSignedConstant();
171 if (
auto FormValue = getAttributeValue(Attr))
172 return FormValue->getAsUnsignedConstant();
178 if (
auto FormValue = getAttributeValue(Attr))
179 return FormValue->getAsReference();
185 if (
auto FormValue = getAttributeValue(Attr))
186 return FormValue->getAsSectionOffset();
193 auto SpecRef = getAttributeValueAsReference(Attr);
204 auto Result = getAttributeValueAsSectionOffset(DW_AT_rnglists_base);
207 return getAttributeValueAsSectionOffset(DW_AT_GNU_ranges_base);
211 if (
auto FormValue = getAttributeValue(DW_AT_high_pc)) {
212 if (
auto Address = FormValue->getAsAddress()) {
216 if (
auto Offset = FormValue->getAsUnsignedConstant()) {
225 auto LowPcAddr = getAttributeValueAsAddress(DW_AT_low_pc);
228 if (
auto HighPcAddr = getHighPC(*LowPcAddr)) {
230 HighPC = *HighPcAddr;
241 uint64_t LowPC, HighPC;
242 if (getLowAndHighPC(LowPC, HighPC)) {
246 auto RangesOffset = getAttributeValueAsSectionOffset(DW_AT_ranges);
259 if (isSubprogramDIE()) {
260 const auto &DIERanges = getAddressRanges();
261 Ranges.insert(Ranges.end(), DIERanges.begin(), DIERanges.end());
264 for (
auto Child: children())
265 Child.collectChildrenAddressRanges(Ranges);
269 for (
const auto& R : getAddressRanges()) {
270 if (R.first <= Address && Address < R.second)
278 if (!isSubroutineDIE())
287 const char *
name =
nullptr;
290 if ((name = getAttributeValueAsString(DW_AT_MIPS_linkage_name,
nullptr)))
292 if ((name = getAttributeValueAsString(DW_AT_linkage_name,
nullptr)))
295 if ((name = getAttributeValueAsString(DW_AT_name,
nullptr)))
298 DWARFDie SpecDie = getAttributeValueAsReferencedDie(DW_AT_specification);
299 if (SpecDie && (name = SpecDie.
getName(Kind)))
302 DWARFDie AbsDie = getAttributeValueAsReferencedDie(DW_AT_abstract_origin);
303 if (AbsDie && (name = AbsDie.
getName(Kind)))
310 CallFile = getAttributeValueAsUnsignedConstant(DW_AT_call_file).getValueOr(0);
311 CallLine = getAttributeValueAsUnsignedConstant(DW_AT_call_line).getValueOr(0);
313 getAttributeValueAsUnsignedConstant(DW_AT_call_column).getValueOr(0);
317 unsigned Indent)
const {
329 auto AbbrevDecl = getAbbreviationDeclarationPtr();
332 if (!tagString.empty())
338 OS <<
format(
" [%u] %c\n", abbrCode,
339 AbbrevDecl->hasChildren() ?
'*' :
' ');
342 for (
const auto &AttrSpec : AbbrevDecl->attributes()) {
343 dumpAttribute(OS, *
this, &offset, AttrSpec.Attr, AttrSpec.Form,
348 if (RecurseDepth > 0 && child) {
350 child.
dump(OS, RecurseDepth-1, Indent+2);
355 OS <<
"Abbreviation code not found in 'debug_abbrev' class for code: "
359 OS.
indent(Indent) <<
"NULL\n";
void push_back(const T &Elt)
StringRef ApplePropertyString(unsigned)
Optional< int64_t > getAttributeValueAsSignedConstant(dwarf::Attribute Attr) const
Extract the specified attribute from this DIE as a signed integer.
DWARFDie getAttributeValueAsReferencedDie(dwarf::Attribute Attr) const
Extract the specified attribute from this DIE as the referenced DIE.
DWARFAddressRangesVector getAddressRanges() const
Get the address ranges for this DIE.
Optional< uint64_t > getHighPC(uint64_t LowPC) const
Get the DW_AT_high_pc attribute value as an address.
uint64_t getBaseAddress() const
std::vector< std::pair< uint64_t, uint64_t > > DWARFAddressRangesVector
DWARFAddressRangesVector - represents a set of absolute address ranges.
llvm::raw_ostream & get()
Optional< DWARFFormValue > getAttributeValue(dwarf::Attribute Attr) const
Extract the specified attribute from this DIE.
void getCallerFrame(uint32_t &CallFile, uint32_t &CallLine, uint32_t &CallColumn) const
Retrieves values of DW_AT_call_file, DW_AT_call_line and DW_AT_call_column from DIE (or zeroes if the...
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
void collectChildrenAddressRanges(DWARFAddressRangesVector &Ranges) const
Get all address ranges for any DW_TAG_subprogram DIEs in this DIE or any of its children.
bool getLowAndHighPC(uint64_t &LowPC, uint64_t &HighPC) const
Retrieves DW_AT_low_pc and DW_AT_high_pc from CU.
DINameKind
A DINameKind is passed to name search methods to specify a preference regarding the type of name reso...
bool addressRangeContainsAddress(const uint64_t Address) 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 > getAttributeValueAsAddress(dwarf::Attribute Attr) const
Extract the specified attribute from this DIE as an address.
StringRef FormEncodingString(unsigned Encoding)
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
static StringRef getName(Value *V)
DWARFDie getSibling(const DWARFDebugInfoEntry *Die)
const char * getAttributeValueAsString(dwarf::Attribute Attr, const char *FailValue) const
Extract the specified attribute from this DIE as a C string.
auto reverse(ContainerTy &&C, typename std::enable_if< has_rbegin< ContainerTy >::value >::type *=nullptr) -> decltype(make_range(C.rbegin(), C.rend()))
DWARFDie getParent(const DWARFDebugInfoEntry *Die)
StringRef AttributeString(unsigned Attribute)
const T & getValue() const LLVM_LVALUE_FUNCTION
static Error getOffset(const SymbolRef &Sym, SectionRef Sec, uint64_t &Result)
StringRef AttributeValueString(uint16_t Attr, unsigned Val)
Returns the symbolic string representing Val when used as a value for attribute Attr.
DWARFDie getParent() const
Get the parent of this DIE object.
format_object< Ts...> format(const char *Fmt, const Ts &...Vals)
These are helper functions used to produce formatted output.
Optional< uint64_t > getAttributeValueAsSectionOffset(dwarf::Attribute Attr) const
Extract the specified attribute from this DIE as absolute section offset.
DWARFDie getSibling() const
Get the sibling of this DIE object.
DWARFUnit * getDwarfUnit() const
virtual DWARFUnit * getUnitForOffset(uint32_t Offset) const =0
Returns the Unit that contains the given section offset in the same section this Unit originated from...
Utility class that carries the DWARF compile/type unit and the debug info entry in an object...
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...
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
DWARFAddressRangesVector getAbsoluteRanges(uint64_t BaseAddress) const
getAbsoluteRanges - Returns absolute address ranges defined by this range list.
A structured debug information entry.
void getInlinedChainForAddress(const uint64_t Address, SmallVectorImpl< DWARFDie > &InlinedChain) const
Get inlined chain for a given address, rooted at the current DIE.
const DWARFUnitSectionBase & getUnitSection() const
getUnitSection - Return the DWARFUnitSection containing this unit.
Optional< uint64_t > getAttributeValueAsUnsignedConstant(dwarf::Attribute Attr) const
Extract the specified attribute from this DIE as an unsigned integer.
const char * getCompilationDir()
unsigned getTag(StringRef TagString)
void dump(raw_ostream &OS, unsigned recurseDepth, unsigned indent=0) const
Dump the DIE and all of its attributes to the supplied stream.
DWARFDie getFirstChild() const
Get the first child of this DIE object.
Color
A "color", which is either even or odd.
bool extractRangeList(uint32_t RangeListOffset, DWARFDebugRangeList &RangeList) const
extractRangeList - extracts the range list referenced by this compile unit from .debug_ranges section...
INITIALIZE_PASS(HexagonGenMux,"hexagon-mux","Hexagon generate mux instructions", false, false) void HexagonGenMux I isValid()
const char * getName(DINameKind Kind) const
Return the DIE name resolving DW_AT_sepcification or DW_AT_abstract_origin references if necessary...
Optional< uint64_t > getAttributeValueAsReference(dwarf::Attribute Attr) const
Extract the specified attribute from this DIE as absolute DIE Offset.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Optional< uint64_t > getRangesBaseAttribute() const
Extract the range base attribute from this DIE as absolute section offset.
bool isSubroutineDIE() const
Returns true if DIE represents a subprogram or an inlined subroutine.
DWARFContext & getContext() const
bool isSubprogramDIE() const
Returns true if DIE represents a subprogram (not inlined).
DataExtractor getDebugInfoExtractor() const
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
StringRef TagString(unsigned Tag)
uint8_t getAddressByteSize() const
DWARFDie getDIEForOffset(uint32_t Offset)
Return the DIE object for a given offset inside the unit's DIE vector.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const DWARFDebugLine::LineTable * getLineTableForUnit(DWARFUnit *cu)
Get a pointer to a parsed line table corresponding to a compile unit.
This class implements an extremely fast bulk output stream that can only output to a stream...
StringRef - Represent a constant reference to a string, i.e.
An RAII object that temporarily switches an output stream to a specific color.