1 //===-- DWARFDebugInfoEntry.h -----------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_DEBUGINFO_DWARFDEBUGINFOENTRY_H
11 #define LLVM_DEBUGINFO_DWARFDEBUGINFOENTRY_H
13 #include "DWARFAbbreviationDeclaration.h"
14 #include "llvm/ADT/SmallVector.h"
15 #include "llvm/Support/DataTypes.h"
19 class DWARFDebugAranges;
20 class DWARFCompileUnit;
23 class DWARFInlinedSubroutineChain;
25 /// DWARFDebugInfoEntryMinimal - A DIE with only the minimum required data.
26 class DWARFDebugInfoEntryMinimal {
27 /// Offset within the .debug_info of the start of this entry.
30 /// How many to subtract from "this" to get the parent.
31 /// If zero this die has no parent.
34 /// How many to add to "this" to get the sibling.
37 const DWARFAbbreviationDeclaration *AbbrevDecl;
39 DWARFDebugInfoEntryMinimal()
40 : Offset(0), ParentIdx(0), SiblingIdx(0), AbbrevDecl(0) {}
42 void dump(raw_ostream &OS, const DWARFCompileUnit *cu,
43 unsigned recurseDepth, unsigned indent = 0) const;
44 void dumpAttribute(raw_ostream &OS, const DWARFCompileUnit *cu,
45 uint32_t *offset_ptr, uint16_t attr, uint16_t form,
46 unsigned indent = 0) const;
48 bool extractFast(const DWARFCompileUnit *cu, const uint8_t *fixed_form_sizes,
49 uint32_t *offset_ptr);
51 /// Extract a debug info entry for a given compile unit from the
52 /// .debug_info and .debug_abbrev data starting at the given offset.
53 bool extract(const DWARFCompileUnit *cu, uint32_t *offset_ptr);
55 uint32_t getTag() const { return AbbrevDecl ? AbbrevDecl->getTag() : 0; }
56 bool isNULL() const { return AbbrevDecl == 0; }
58 /// Returns true if DIE represents a subprogram (not inlined).
59 bool isSubprogramDIE() const;
60 /// Returns true if DIE represents a subprogram or an inlined
62 bool isSubroutineDIE() const;
64 uint32_t getOffset() const { return Offset; }
65 uint32_t getNumAttributes() const {
66 return !isNULL() ? AbbrevDecl->getNumAttributes() : 0;
68 bool hasChildren() const { return !isNULL() && AbbrevDecl->hasChildren(); }
70 // We know we are kept in a vector of contiguous entries, so we know
71 // our parent will be some index behind "this".
72 DWARFDebugInfoEntryMinimal *getParent() {
73 return ParentIdx > 0 ? this - ParentIdx : 0;
75 const DWARFDebugInfoEntryMinimal *getParent() const {
76 return ParentIdx > 0 ? this - ParentIdx : 0;
78 // We know we are kept in a vector of contiguous entries, so we know
79 // our sibling will be some index after "this".
80 DWARFDebugInfoEntryMinimal *getSibling() {
81 return SiblingIdx > 0 ? this + SiblingIdx : 0;
83 const DWARFDebugInfoEntryMinimal *getSibling() const {
84 return SiblingIdx > 0 ? this + SiblingIdx : 0;
86 // We know we are kept in a vector of contiguous entries, so we know
87 // we don't need to store our child pointer, if we have a child it will
88 // be the next entry in the list...
89 DWARFDebugInfoEntryMinimal *getFirstChild() {
90 return hasChildren() ? this + 1 : 0;
92 const DWARFDebugInfoEntryMinimal *getFirstChild() const {
93 return hasChildren() ? this + 1 : 0;
96 void setParent(DWARFDebugInfoEntryMinimal *parent) {
98 // We know we are kept in a vector of contiguous entries, so we know
99 // our parent will be some index behind "this".
100 ParentIdx = this - parent;
104 void setSibling(DWARFDebugInfoEntryMinimal *sibling) {
106 // We know we are kept in a vector of contiguous entries, so we know
107 // our sibling will be some index after "this".
108 SiblingIdx = sibling - this;
109 sibling->setParent(getParent());
114 const DWARFAbbreviationDeclaration *getAbbreviationDeclarationPtr() const {
118 uint32_t getAttributeValue(const DWARFCompileUnit *cu,
119 const uint16_t attr, DWARFFormValue &formValue,
120 uint32_t *end_attr_offset_ptr = 0) const;
122 const char* getAttributeValueAsString(const DWARFCompileUnit* cu,
124 const char *fail_value) const;
126 uint64_t getAttributeValueAsUnsigned(const DWARFCompileUnit *cu,
128 uint64_t fail_value) const;
130 uint64_t getAttributeValueAsReference(const DWARFCompileUnit *cu,
132 uint64_t fail_value) const;
134 int64_t getAttributeValueAsSigned(const DWARFCompileUnit* cu,
136 int64_t fail_value) const;
138 /// Retrieves DW_AT_low_pc and DW_AT_high_pc from CU.
139 /// Returns true if both attributes are present.
140 bool getLowAndHighPC(const DWARFCompileUnit *CU,
141 uint64_t &LowPC, uint64_t &HighPC) const;
143 void buildAddressRangeTable(const DWARFCompileUnit *CU,
144 DWARFDebugAranges *DebugAranges) const;
146 bool addressRangeContainsAddress(const DWARFCompileUnit *CU,
147 const uint64_t Address) const;
149 /// If a DIE represents a subprogram (or inlined subroutine),
150 /// returns its mangled name (or short name, if mangled is missing).
151 /// This name may be fetched from specification or abstract origin
152 /// for this subprogram. Returns null if no name is found.
153 const char* getSubroutineName(const DWARFCompileUnit *CU) const;
155 /// Retrieves values of DW_AT_call_file, DW_AT_call_line and
156 /// DW_AT_call_column from DIE (or zeroes if they are missing).
157 void getCallerFrame(const DWARFCompileUnit *CU, uint32_t &CallFile,
158 uint32_t &CallLine, uint32_t &CallColumn) const;
160 /// InlinedChain - represents a chain of inlined_subroutine
161 /// DIEs, (possibly ending with subprogram DIE), all of which are contained
162 /// in some concrete inlined instance tree. Address range for each DIE
163 /// (except the last DIE) in this chain is contained in address
164 /// range for next DIE in the chain.
165 typedef SmallVector<DWARFDebugInfoEntryMinimal, 4> InlinedChain;
167 /// Get inlined chain for a given address, rooted at the current DIE.
168 /// Returns empty chain if address is not contained in address range
170 InlinedChain getInlinedChainForAddress(const DWARFCompileUnit *CU,
171 const uint64_t Address) const;