blob: 9003591cbe105760c7998a1acf5d275d0fc188a0 [file] [log] [blame]
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +00001//===-- DWARFDebugInfoEntry.h -----------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef LLVM_DEBUGINFO_DWARFDEBUGINFOENTRY_H
11#define LLVM_DEBUGINFO_DWARFDEBUGINFOENTRY_H
12
13#include "DWARFAbbreviationDeclaration.h"
Alexey Samsonov5eae90d2012-09-04 08:12:33 +000014#include "llvm/ADT/SmallVector.h"
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000015#include "llvm/Support/DataTypes.h"
16
17namespace llvm {
18
Benjamin Kramer10df8062011-09-14 20:52:27 +000019class DWARFDebugAranges;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000020class DWARFCompileUnit;
21class DWARFContext;
22class DWARFFormValue;
Alexey Samsonov5eae90d2012-09-04 08:12:33 +000023class DWARFInlinedSubroutineChain;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000024
25/// DWARFDebugInfoEntryMinimal - A DIE with only the minimum required data.
26class DWARFDebugInfoEntryMinimal {
27 /// Offset within the .debug_info of the start of this entry.
Benjamin Kramer80cc2592011-11-05 15:35:00 +000028 uint32_t Offset;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000029
30 /// How many to subtract from "this" to get the parent.
31 /// If zero this die has no parent.
32 uint32_t ParentIdx;
33
34 /// How many to add to "this" to get the sibling.
35 uint32_t SiblingIdx;
36
37 const DWARFAbbreviationDeclaration *AbbrevDecl;
38public:
Benjamin Kramer15ec0852011-09-14 00:15:32 +000039 DWARFDebugInfoEntryMinimal()
40 : Offset(0), ParentIdx(0), SiblingIdx(0), AbbrevDecl(0) {}
41
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000042 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;
47
Alexey Samsonovd6b89ef2013-04-08 14:37:16 +000048 /// 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,
52 uint32_t *OffsetPtr);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000053
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.
Alexey Samsonovd6b89ef2013-04-08 14:37:16 +000056 /// If compile unit can't be parsed, returns false and doesn't change
57 /// OffsetPtr.
58 bool extract(const DWARFCompileUnit *CU, uint32_t *OffsetPtr);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000059
60 uint32_t getTag() const { return AbbrevDecl ? AbbrevDecl->getTag() : 0; }
61 bool isNULL() const { return AbbrevDecl == 0; }
Alexey Samsonov5eae90d2012-09-04 08:12:33 +000062
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
66 /// subroutine.
67 bool isSubroutineDIE() const;
68
Benjamin Kramer80cc2592011-11-05 15:35:00 +000069 uint32_t getOffset() const { return Offset; }
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000070 uint32_t getNumAttributes() const {
71 return !isNULL() ? AbbrevDecl->getNumAttributes() : 0;
72 }
73 bool hasChildren() const { return !isNULL() && AbbrevDecl->hasChildren(); }
74
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;
79 }
80 const DWARFDebugInfoEntryMinimal *getParent() const {
81 return ParentIdx > 0 ? this - ParentIdx : 0;
82 }
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;
87 }
88 const DWARFDebugInfoEntryMinimal *getSibling() const {
89 return SiblingIdx > 0 ? this + SiblingIdx : 0;
90 }
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;
96 }
97 const DWARFDebugInfoEntryMinimal *getFirstChild() const {
98 return hasChildren() ? this + 1 : 0;
99 }
100
101 void setParent(DWARFDebugInfoEntryMinimal *parent) {
102 if (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;
Benjamin Kramer4aa3fea2011-09-13 21:47:32 +0000106 } else
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000107 ParentIdx = 0;
108 }
109 void setSibling(DWARFDebugInfoEntryMinimal *sibling) {
Benjamin Kramer4aa3fea2011-09-13 21:47:32 +0000110 if (sibling) {
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000111 // 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());
Benjamin Kramer4aa3fea2011-09-13 21:47:32 +0000115 } else
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000116 SiblingIdx = 0;
117 }
118
119 const DWARFAbbreviationDeclaration *getAbbreviationDeclarationPtr() const {
120 return AbbrevDecl;
121 }
122
123 uint32_t getAttributeValue(const DWARFCompileUnit *cu,
124 const uint16_t attr, DWARFFormValue &formValue,
125 uint32_t *end_attr_offset_ptr = 0) const;
126
127 const char* getAttributeValueAsString(const DWARFCompileUnit* cu,
128 const uint16_t attr,
129 const char *fail_value) const;
130
131 uint64_t getAttributeValueAsUnsigned(const DWARFCompileUnit *cu,
132 const uint16_t attr,
133 uint64_t fail_value) const;
134
135 uint64_t getAttributeValueAsReference(const DWARFCompileUnit *cu,
136 const uint16_t attr,
137 uint64_t fail_value) const;
138
139 int64_t getAttributeValueAsSigned(const DWARFCompileUnit* cu,
140 const uint16_t attr,
141 int64_t fail_value) const;
Benjamin Kramer10df8062011-09-14 20:52:27 +0000142
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000143 /// 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;
Alexey Samsonov3e25c4a2012-07-02 05:54:45 +0000147
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000148 void buildAddressRangeTable(const DWARFCompileUnit *CU,
149 DWARFDebugAranges *DebugAranges) const;
Alexey Samsonov3e25c4a2012-07-02 05:54:45 +0000150
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000151 bool addressRangeContainsAddress(const DWARFCompileUnit *CU,
152 const uint64_t Address) const;
153
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;
159
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;
164
165 /// InlinedChain - represents a chain of inlined_subroutine
166 /// DIEs, (possibly ending with subprogram DIE), all of which are contained
167 /// in some concrete inlined instance tree. Address range for each DIE
168 /// (except the last DIE) in this chain is contained in address
169 /// range for next DIE in the chain.
170 typedef SmallVector<DWARFDebugInfoEntryMinimal, 4> InlinedChain;
171
172 /// Get inlined chain for a given address, rooted at the current DIE.
173 /// Returns empty chain if address is not contained in address range
174 /// of current DIE.
175 InlinedChain getInlinedChainForAddress(const DWARFCompileUnit *CU,
176 const uint64_t Address) const;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000177};
178
179}
180
181#endif