33 using namespace dwarf;
34 using namespace syntax;
40 assert(Shift < 64 &&
"undefined behavior");
41 uint64_t
Bit = 1ULL << Shift;
43 if (!PropName.empty())
46 OS <<
format(
"DW_APPLE_PROPERTY_0x%" PRIx64, Bit);
55 unsigned AddressSize,
unsigned Indent) {
59 for (
const auto &Range: Ranges) {
62 OS <<
format(
"[0x%0*" PRIx64
" - 0x%0*" PRIx64
")",
63 AddressSize*2, Range.LowPC,
64 AddressSize*2, Range.HighPC);
74 const char BaseIndent[] =
" ";
78 if (!attrString.empty())
83 if (!DumpOpts.
Brief) {
85 if (!formString.empty())
86 OS <<
" [" << formString <<
']';
88 OS <<
format(
" [DW_FORM_Unknown_%x]", Form);
102 if (Attr == DW_AT_decl_file || Attr == DW_AT_call_file) {
106 File =
'"' + File +
'"';
114 else if (Attr == DW_AT_decl_line || Attr == DW_AT_call_line)
122 if (Attr == DW_AT_specification || Attr == DW_AT_abstract_origin) {
124 OS <<
" \"" << Name <<
'\"';
125 }
else if (Attr == DW_AT_APPLE_property_attribute) {
128 }
else if (Attr == DW_AT_ranges) {
130 sizeof(BaseIndent)+Indent+4);
137 return getTag() == DW_TAG_subprogram;
142 return Tag == DW_TAG_subprogram ||
Tag == DW_TAG_inlined_subroutine;
149 auto AbbrevDecl = getAbbreviationDeclarationPtr();
151 return AbbrevDecl->getAttributeValue(
getOffset(), Attr, *U);
159 auto AbbrevDecl = getAbbreviationDeclarationPtr();
161 for (
auto Attr : Attrs) {
162 if (
auto Value = AbbrevDecl->getAttributeValue(
getOffset(), Attr, *U))
174 if (
auto Value = Die.find(Attrs))
176 if (
auto D = Die.getAttributeValueAsReferencedDie(DW_AT_abstract_origin))
178 if (
auto Value = Die.find(Attrs))
180 if (
auto D = Die.getAttributeValueAsReferencedDie(DW_AT_specification))
182 if (
auto Value = Die.find(Attrs))
191 auto SpecUnit = U->getUnitSection().getUnitForOffset(*SpecRef);
193 return SpecUnit->getDIEForOffset(*SpecRef);
204 if (
auto FormValue =
find(DW_AT_high_pc)) {
205 if (
auto Address = FormValue->getAsAddress()) {
209 if (
auto Offset = FormValue->getAsUnsignedConstant()) {
218 uint64_t &SectionIndex)
const {
219 auto F =
find(DW_AT_low_pc);
223 if (
auto HighPcAddr = getHighPC(*LowPcAddr)) {
225 HighPC = *HighPcAddr;
226 SectionIndex =
F->getSectionIndex();
237 uint64_t LowPC, HighPC, Index;
238 if (getLowAndHighPC(LowPC, HighPC, Index))
239 return {{LowPC, HighPC, Index}};
245 if (U->extractRangeList(*RangesOffset, RangeList))
255 if (isSubprogramDIE()) {
256 const auto &DIERanges = getAddressRanges();
257 Ranges.insert(Ranges.end(), DIERanges.begin(), DIERanges.end());
261 Child.collectChildrenAddressRanges(Ranges);
265 for (
const auto& R : getAddressRanges()) {
266 if (R.LowPC <= Address && Address < R.HighPC)
274 if (!isSubroutineDIE())
286 DW_AT_linkage_name}),
nullptr))
295 return toUnsigned(findRecursively(DW_AT_decl_line), 0);
300 uint32_t &CallDiscriminator)
const {
320 auto AbbrevDecl = getAbbreviationDeclarationPtr();
323 if (!tagString.empty())
330 OS <<
format(
" [%u] %c", abbrCode,
331 AbbrevDecl->hasChildren() ?
'*' :
' ');
335 for (
const auto &AttrSpec : AbbrevDecl->attributes()) {
336 if (AttrSpec.Form == DW_FORM_implicit_const) {
342 dumpAttribute(OS, *
this, &offset, AttrSpec.Attr, AttrSpec.Form,
347 if (RecurseDepth > 0 && child) {
349 child.
dump(OS, RecurseDepth-1, Indent+2, DumpOpts);
354 OS <<
"Abbreviation code not found in 'debug_abbrev' class for code: "
358 OS.
indent(Indent) <<
"NULL\n";
382 Die(D), AttrValue(0), Index(0) {
384 assert(AbbrDecl &&
"Must have abbreviation declaration");
387 Index = AbbrDecl->getNumAttributes();
391 updateForIndex(*AbbrDecl, 0);
395 void DWARFDie::attribute_iterator::updateForIndex(
400 if (Index < NumAttrs) {
403 AttrValue.Offset += AttrValue.ByteSize;
405 uint32_t ParseOffset = AttrValue.Offset;
406 auto U = Die.getDwarfUnit();
407 assert(U &&
"Die must have valid DWARF unit");
411 assert(b &&
"extractValue cannot fail on fully parsed DWARF");
412 AttrValue.ByteSize = ParseOffset - AttrValue.Offset;
414 assert(Index == NumAttrs &&
"Indexes should be [0, NumAttrs) only");
421 updateForIndex(*AbbrDecl, Index + 1);
iterator_range< typename GraphTraits< GraphType >::ChildIteratorType > children(const typename GraphTraits< GraphType >::NodeRef &G)
StringRef ApplePropertyString(unsigned)
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.
attribute_iterator & operator++()
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.
DINameKind
A DINameKind is passed to name search methods to specify a preference regarding the type of name reso...
size_t getNumAttributes() const
bool addressRangeContainsAddress(const uint64_t Address) const
Optional< uint64_t > toAddress(const Optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an address.
const char * getSubroutineName(DINameKind Kind) const
If a DIE represents a subprogram (or inlined subroutine), returns its mangled name (or short name...
DWARFDataExtractor getDebugInfoExtractor() const
uint32_t getOffset() const
Get the absolute offset into the debug info or types section.
const char * getCompilationDir()
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...
StringRef FormEncodingString(unsigned Encoding)
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)
bool getLowAndHighPC(uint64_t &LowPC, uint64_t &HighPC, uint64_t &SectionIndex) const
Retrieves DW_AT_low_pc and DW_AT_high_pc from CU.
static void dumpApplePropertyAttribute(raw_ostream &OS, uint64_t Val)
StringRef AttributeString(unsigned Attribute)
const T & getValue() const LLVM_LVALUE_FUNCTION
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
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.
Container for dump options that control which debug information will be dumped.
attribute_iterator()=delete
DWARFDie getSibling() const
Get the sibling of this DIE object.
Optional< uint64_t > toSectionOffset(const Optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an section offset.
DWARFUnit * getDwarfUnit() const
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
static void dumpRanges(raw_ostream &OS, const DWARFAddressRangesVector &Ranges, unsigned AddressSize, unsigned Indent)
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.
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...
DWARFAddressRangesVector getAbsoluteRanges(uint64_t BaseAddress) const
getAbsoluteRanges - Returns absolute address ranges defined by this range list.
static const unsigned End
Optional< DWARFFormValue > find(dwarf::Attribute Attr) const
Extract the specified attribute from this DIE.
dwarf::Attribute getAttrByIndex(uint32_t idx) const
unsigned getTag(StringRef TagString)
const DWARFAbbreviationDeclaration * getAbbreviationDeclarationPtr() const
Get the abbreviation declaration for this DIE.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
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...
Color
A "color", which is either even or odd.
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) -> decltype(std::begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
uint32_t Offset
The debug info/types offset for this attribute.
const char * getName(DINameKind Kind) const
Return the DIE name resolving DW_AT_sepcification or DW_AT_abstract_origin references if necessary...
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.
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).
StringRef TagString(unsigned Tag)
const DWARFAbbreviationDeclaration * getAbbreviationDeclarationPtr() const
iterator_range< attribute_iterator > attributes() const
Get an iterator range to all attributes in the current DIE only.
dwarf::Form getFormByIndex(uint32_t idx) const
INITIALIZE_PASS(HexagonGenMux,"hexagon-gen-mux","Hexagon generate mux instructions", false, false) void HexagonGenMux I isValid()
void dump(raw_ostream &OS, unsigned recurseDepth, unsigned indent=0, DIDumpOptions DumpOpts=DIDumpOptions()) const
Dump the DIE and all of its attributes to the supplied stream.
uint8_t getAddressByteSize() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
std::vector< DWARFAddressRange > DWARFAddressRangesVector
DWARFAddressRangesVector - represents a set of absolute address ranges.
LLVM Value Representation.
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.
Optional< uint64_t > toUnsigned(const Optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an unsigned constant.
An RAII object that temporarily switches an output stream to a specific color.