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 struct DWARFDebugInfoEntryInlinedChain;
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 /// Extracts a debug info entry, which is a child of a given compile unit,
49 /// starting at a given offset. If DIE can't be extracted, returns false and
50 /// doesn't change OffsetPtr.
51 bool extractFast(const DWARFCompileUnit *CU, const uint8_t *FixedFormSizes,
54 /// Extract a debug info entry for a given compile unit from the
55 /// .debug_info and .debug_abbrev data starting at the given offset.
56 /// If compile unit can't be parsed, returns false and doesn't change
58 bool extract(const DWARFCompileUnit *CU, uint32_t *OffsetPtr);
60 uint32_t getTag() const { return AbbrevDecl ? AbbrevDecl->getTag() : 0; }
61 bool isNULL() const { return AbbrevDecl == 0; }
63 /// Returns true if DIE represents a subprogram (not inlined).
64 bool isSubprogramDIE() const;
65 /// Returns true if DIE represents a subprogram or an inlined
67 bool isSubroutineDIE() const;
69 uint32_t getOffset() const { return Offset; }
70 uint32_t getNumAttributes() const {
71 return !isNULL() ? AbbrevDecl->getNumAttributes() : 0;
73 bool hasChildren() const { return !isNULL() && AbbrevDecl->hasChildren(); }
75 // We know we are kept in a vector of contiguous entries, so we know
76 // our parent will be some index behind "this".
77 DWARFDebugInfoEntryMinimal *getParent() {
78 return ParentIdx > 0 ? this - ParentIdx : 0;
80 const DWARFDebugInfoEntryMinimal *getParent() const {
81 return ParentIdx > 0 ? this - ParentIdx : 0;
83 // We know we are kept in a vector of contiguous entries, so we know
84 // our sibling will be some index after "this".
85 DWARFDebugInfoEntryMinimal *getSibling() {
86 return SiblingIdx > 0 ? this + SiblingIdx : 0;
88 const DWARFDebugInfoEntryMinimal *getSibling() const {
89 return SiblingIdx > 0 ? this + SiblingIdx : 0;
91 // We know we are kept in a vector of contiguous entries, so we know
92 // we don't need to store our child pointer, if we have a child it will
93 // be the next entry in the list...
94 DWARFDebugInfoEntryMinimal *getFirstChild() {
95 return hasChildren() ? this + 1 : 0;
97 const DWARFDebugInfoEntryMinimal *getFirstChild() const {
98 return hasChildren() ? this + 1 : 0;
101 void setParent(DWARFDebugInfoEntryMinimal *parent) {
103 // We know we are kept in a vector of contiguous entries, so we know
104 // our parent will be some index behind "this".
105 ParentIdx = this - parent;
109 void setSibling(DWARFDebugInfoEntryMinimal *sibling) {
111 // We know we are kept in a vector of contiguous entries, so we know
112 // our sibling will be some index after "this".
113 SiblingIdx = sibling - this;
114 sibling->setParent(getParent());
119 const DWARFAbbreviationDeclaration *getAbbreviationDeclarationPtr() const {
123 uint32_t getAttributeValue(const DWARFCompileUnit *cu,
124 const uint16_t attr, DWARFFormValue &formValue,
125 uint32_t *end_attr_offset_ptr = 0) const;
127 const char* getAttributeValueAsString(const DWARFCompileUnit* cu,
129 const char *fail_value) const;
131 uint64_t getAttributeValueAsUnsigned(const DWARFCompileUnit *cu,
133 uint64_t fail_value) const;
135 uint64_t getAttributeValueAsReference(const DWARFCompileUnit *cu,
137 uint64_t fail_value) const;
139 int64_t getAttributeValueAsSigned(const DWARFCompileUnit* cu,
141 int64_t fail_value) const;
143 /// Retrieves DW_AT_low_pc and DW_AT_high_pc from CU.
144 /// Returns true if both attributes are present.
145 bool getLowAndHighPC(const DWARFCompileUnit *CU,
146 uint64_t &LowPC, uint64_t &HighPC) const;
148 void buildAddressRangeTable(const DWARFCompileUnit *CU,
149 DWARFDebugAranges *DebugAranges) const;
151 bool addressRangeContainsAddress(const DWARFCompileUnit *CU,
152 const uint64_t Address) const;
154 /// If a DIE represents a subprogram (or inlined subroutine),
155 /// returns its mangled name (or short name, if mangled is missing).
156 /// This name may be fetched from specification or abstract origin
157 /// for this subprogram. Returns null if no name is found.
158 const char* getSubroutineName(const DWARFCompileUnit *CU) const;
160 /// Retrieves values of DW_AT_call_file, DW_AT_call_line and
161 /// DW_AT_call_column from DIE (or zeroes if they are missing).
162 void getCallerFrame(const DWARFCompileUnit *CU, uint32_t &CallFile,
163 uint32_t &CallLine, uint32_t &CallColumn) const;
165 /// Get inlined chain for a given address, rooted at the current DIE.
166 /// Returns empty chain if address is not contained in address range
168 DWARFDebugInfoEntryInlinedChain
169 getInlinedChainForAddress(const DWARFCompileUnit *CU,
170 const uint64_t Address) const;
173 /// DWARFDebugInfoEntryInlinedChain - represents a chain of inlined_subroutine
174 /// DIEs, (possibly ending with subprogram DIE), all of which are contained
175 /// in some concrete inlined instance tree. Address range for each DIE
176 /// (except the last DIE) in this chain is contained in address
177 /// range for next DIE in the chain.
178 struct DWARFDebugInfoEntryInlinedChain {
179 DWARFDebugInfoEntryInlinedChain() : CU(0) {}
180 SmallVector<DWARFDebugInfoEntryMinimal, 4> DIEs;
181 const DWARFCompileUnit *CU;