16 #include "llvm/Support/DataTypes.h"
22 using namespace dwarf;
23 using namespace syntax;
33 return (Unit && DIE.
extractFast(Unit, Offset)) ? Unit :
nullptr;
37 unsigned recurseDepth,
38 unsigned indent)
const {
40 uint32_t offset = Offset;
43 uint32_t abbrCode = debug_info_data.
getULEB128(&offset);
55 OS <<
format(
" [%u] %c\n", abbrCode,
56 AbbrevDecl->hasChildren() ?
'*' :
' ');
59 for (
const auto &AttrSpec : AbbrevDecl->attributes()) {
60 dumpAttribute(OS, u, &offset, AttrSpec.Attr, AttrSpec.Form, indent);
64 if (recurseDepth > 0 && child) {
66 child->
dump(OS, u, recurseDepth-1, indent+2);
71 OS <<
"Abbreviation code not found in 'debug_abbrev' class for code: "
75 OS.
indent(indent) <<
"NULL\n";
84 assert(Shift < 64 &&
"undefined behavior");
85 uint64_t
Bit = 1ULL << Shift;
89 OS <<
format(
"DW_APPLE_PROPERTY_0x%" PRIx64, Bit);
98 unsigned AddressSize,
unsigned Indent) {
102 for (
const auto &Range: Ranges) {
105 OS <<
format(
"[0x%0*" PRIx64
" - 0x%0*" PRIx64
")",
106 AddressSize*2, Range.first,
107 AddressSize*2, Range.second);
113 uint32_t *offset_ptr,
114 uint16_t attr, uint16_t form,
115 unsigned indent)
const {
116 const char BaseIndent[] =
" ";
127 OS <<
" [" << formString <<
']';
129 OS <<
format(
" [DW_FORM_Unknown_%x]", form);
138 const char *
Name =
nullptr;
144 if (
LT->getFileNameByIndex(
148 File =
'"' + File +
'"';
159 formValue.
dump(OS, u);
167 uint32_t RefOffset = Ref.
getValue();
171 OS <<
" \"" << Name <<
'\"';
178 sizeof(BaseIndent)+indent+4);
185 uint32_t *OffsetPtr) {
189 if (Offset >= UEndOffset || !DebugInfoData.
isValidOffset(Offset))
191 uint64_t AbbrCode = DebugInfoData.
getULEB128(OffsetPtr);
194 AbbrevDecl =
nullptr;
198 if (
nullptr == AbbrevDecl) {
205 assert(FixedFormSizes.
size() > 0);
208 for (
const auto &AttrSpec : AbbrevDecl->attributes()) {
209 uint16_t
Form = AttrSpec.Form;
211 uint8_t FixedFormSize =
212 (Form < FixedFormSizes.
size()) ? FixedFormSizes[Form] : 0;
214 *OffsetPtr += FixedFormSize;
225 return getTag() == DW_TAG_subprogram;
230 return Tag == DW_TAG_subprogram ||
231 Tag == DW_TAG_inlined_subroutine;
239 uint32_t AttrIdx = AbbrevDecl->findAttributeIndex(Attr);
250 for (uint32_t i = 0; i < AttrIdx; ++i) {
252 DebugInfoData, &DebugInfoOffset, U);
256 return FormValue.
extractValue(DebugInfoData, &DebugInfoOffset, U);
260 const DWARFUnit *U,
const uint16_t Attr,
const char *FailValue)
const {
262 if (!getAttributeValue(U, Attr, FormValue))
269 const DWARFUnit *U,
const uint16_t Attr, uint64_t FailValue)
const {
271 if (!getAttributeValue(U, Attr, FormValue))
278 const DWARFUnit *U,
const uint16_t Attr, uint64_t FailValue)
const {
280 if (!getAttributeValue(U, Attr, FormValue))
287 const DWARFUnit *U,
const uint16_t Attr, uint64_t FailValue)
const {
289 if (!getAttributeValue(U, Attr, FormValue))
296 const DWARFUnit *U,
const uint16_t Attr, uint64_t FailValue)
const {
298 if (!getAttributeValue(U, Attr, FormValue))
306 uint64_t FailValue)
const {
316 uint64_t &HighPC)
const {
317 LowPC = getAttributeValueAsAddress(U,
DW_AT_low_pc, -1ULL);
320 HighPC = getAttributeValueAsAddress(U,
DW_AT_high_pc, -1ULL);
321 if (HighPC == -1ULL) {
324 HighPC = getAttributeValueAsUnsignedConstant(U,
DW_AT_high_pc, -1ULL);
328 return (HighPC != -1ULL);
336 uint64_t LowPC, HighPC;
337 if (getLowAndHighPC(U, LowPC, HighPC)) {
341 uint32_t RangesOffset =
343 if (RangesOffset != -1U) {
355 if (isSubprogramDIE()) {
356 const auto &DIERanges = getAddressRanges(U);
357 Ranges.insert(Ranges.end(), DIERanges.begin(), DIERanges.end());
369 for (
const auto& R : getAddressRanges(U)) {
370 if (R.first <= Address && Address < R.second)
379 if (!isSubroutineDIE())
391 if (
const char *
name =
394 if (
const char *
name =
398 if (
const char *
name = getAttributeValueAsString(U,
DW_AT_name,
nullptr))
403 if (spec_ref != -1U) {
406 if (
const char *
name = spec_die.
getName(RefU, Kind))
411 uint32_t abs_origin_ref =
413 if (abs_origin_ref != -1U) {
417 if (
const char *
name = abs_origin_die.
getName(RefU, Kind))
427 uint32_t &CallColumn)
const {
443 if (
DIE->isSubroutineDIE()) {
444 InlinedChain.
DIEs.push_back(*
DIE);
458 std::reverse(InlinedChain.
DIEs.begin(), InlinedChain.
DIEs.end());
DWARFAddressRangesVector getAddressRanges(const DWARFUnit *U) const
static void dumpRanges(raw_ostream &OS, const DWARFAddressRangesVector &Ranges, unsigned AddressSize, unsigned Indent)
const char * getSubroutineName(const DWARFUnit *U, DINameKind Kind) const
If a DIE represents a subprogram (or inlined subroutine), returns its mangled name (or short name...
uint64_t getBaseAddress() const
uint64_t getAttributeValueAsAddress(const DWARFUnit *U, const uint16_t Attr, uint64_t FailValue) const
std::vector< std::pair< uint64_t, uint64_t > > DWARFAddressRangesVector
DWARFAddressRangesVector - represents a set of absolute address ranges.
llvm::raw_ostream & get()
static void dumpApplePropertyAttribute(raw_ostream &OS, uint64_t Val)
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
const char * getName(const DWARFUnit *U, DINameKind Kind) const
Return the DIE name resolving DW_AT_sepcification or DW_AT_abstract_origin references if necessary...
const char * AttributeString(unsigned Attribute)
DWARFDebugInfoEntryInlinedChain getInlinedChainForAddress(const DWARFUnit *U, const uint64_t Address) const
Get inlined chain for a given address, rooted at the current DIE.
bool extractRangeList(uint32_t RangeListOffset, DWARFDebugRangeList &RangeList) const
extractRangeList - extracts the range list referenced by this compile unit from .debug_ranges section...
uint32_t getNextUnitOffset() const
uint64_t getRangesBaseAttribute(const DWARFUnit *U, uint64_t FailValue) const
DINameKind
A DINameKind is passed to name search methods to specify a preference regarding the type of name reso...
static std::error_code getOffset(const SymbolRef &Sym, SectionRef Sec, uint64_t &Result)
const DWARFAbbreviationDeclarationSet * getAbbreviations() const
const char * getCompilationDir()
const char * TagString(unsigned Tag)
static StringRef getName(Value *V)
const char * getAttributeValueAsString(const DWARFUnit *U, const uint16_t Attr, const char *FailValue) const
void collectChildrenAddressRanges(const DWARFUnit *U, DWARFAddressRangesVector &Ranges) const
const T & getValue() const LLVM_LVALUE_FUNCTION
bool addressRangeContainsAddress(const DWARFUnit *U, const uint64_t Address) const
SmallVector< DWARFDebugInfoEntryMinimal, 4 > DIEs
size_t size() const
size - Get the array size.
uint64_t getAttributeValueAsReference(const DWARFUnit *U, const uint16_t Attr, uint64_t FailValue) const
uint16_t getVersion() const
format_object< Ts...> format(const char *Fmt, const Ts &...Vals)
These are helper functions used to produce formatted output.
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...
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...
DWARFDebugInfoEntryMinimal - A DIE with only the minimum required data.
void dump(raw_ostream &OS, DWARFUnit *u, unsigned recurseDepth, unsigned indent=0) const
DWARFAddressRangesVector getAbsoluteRanges(uint64_t BaseAddress) const
getAbsoluteRanges - Returns absolute address ranges defined by this range list.
DIE - A structured debug information entry.
const DWARFUnitSectionBase & getUnitSection() const
getUnitSection - Return the DWARFUnitSection containing this unit.
const DWARFDebugInfoEntryMinimal * getSibling() const
unsigned getTag(StringRef TagString)
Color
A "color", which is either even or odd.
uint64_t getAttributeValueAsUnsignedConstant(const DWARFUnit *U, const uint16_t Attr, uint64_t FailValue) const
uint64_t getAttributeValueAsSectionOffset(const DWARFUnit *U, const uint16_t Attr, uint64_t FailValue) const
void getCallerFrame(const DWARFUnit *U, 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...
DWARFContext & getContext() const
const char * AttributeValueString(uint16_t Attr, unsigned Val)
Returns the symbolic string representing Val when used as a value for attribute Attr.
DataExtractor getDebugInfoExtractor() const
const DWARFAbbreviationDeclaration * getAbbreviationDeclaration(uint32_t AbbrCode) const
const char * ApplePropertyString(unsigned)
static const DWARFUnit * findUnitAndExtractFast(DWARFDebugInfoEntryMinimal &DIE, const DWARFUnit *Unit, uint32_t *Offset)
const char * FormEncodingString(unsigned Encoding)
bool isSubroutineDIE() const
Returns true if DIE represents a subprogram or an inlined subroutine.
void dumpAttribute(raw_ostream &OS, DWARFUnit *u, uint32_t *offset_ptr, uint16_t attr, uint16_t form, unsigned indent=0) const
uint8_t getAddressByteSize() const
std::vector< uint8_t > Unit
bool getLowAndHighPC(const DWARFUnit *U, uint64_t &LowPC, uint64_t &HighPC) const
Retrieves DW_AT_low_pc and DW_AT_high_pc from CU.
const ARM::ArchExtKind Kind
const DWARFDebugLine::LineTable * getLineTableForUnit(DWARFUnit *cu)
Get a pointer to a parsed line table corresponding to a compile unit.
bool isSubprogramDIE() const
Returns true if DIE represents a subprogram (not inlined).
This class implements an extremely fast bulk output stream that can only output to a stream...
bool getAttributeValue(const DWARFUnit *U, const uint16_t Attr, DWARFFormValue &FormValue) const
bool extractFast(const DWARFUnit *U, uint32_t *OffsetPtr)
Extracts a debug info entry, which is a child of a given unit, starting at a given offset...
An RAII object that temporarily switches an output stream to a specific color.
DWARFDebugInfoEntryInlinedChain - represents a chain of inlined_subroutine DIEs, (possibly ending wit...