blob: f3e72d74d19578b17f9246cc8c2d87a775dc4f12 [file] [log] [blame]
Greg Clayton6071e6f2015-08-26 22:57:51 +00001//===-- DWARFDIE.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 SymbolFileDWARF_DWARFDIE_h_
11#define SymbolFileDWARF_DWARFDIE_h_
12
13#include "lldb/lldb-types.h"
14#include "lldb/Core/dwarf.h"
15
Tamas Berghammereb882fc2015-09-09 10:20:48 +000016struct DIERef;
Greg Clayton261ac3f2015-08-28 01:01:03 +000017class DWARFASTParser;
Greg Clayton6071e6f2015-08-26 22:57:51 +000018class DWARFAttributes;
19class DWARFCompileUnit;
20class DWARFDebugInfoEntry;
21class DWARFDeclContext;
22class DWARFDIECollection;
23class SymbolFileDWARF;
24
25class DWARFDIE
26{
27public:
28 DWARFDIE () :
29 m_cu (nullptr),
30 m_die (nullptr)
31 {
32 }
33
34 DWARFDIE (DWARFCompileUnit *cu, DWARFDebugInfoEntry *die) :
35 m_cu (cu),
36 m_die (die)
37 {
38 }
39
40 DWARFDIE (const DWARFCompileUnit *cu, DWARFDebugInfoEntry *die) :
41 m_cu (const_cast<DWARFCompileUnit *>(cu)),
42 m_die (die)
43 {
44 }
45
46 DWARFDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) :
47 m_cu (cu),
48 m_die (const_cast<DWARFDebugInfoEntry *>(die))
49 {
50 }
51
52 DWARFDIE (const DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) :
53 m_cu (const_cast<DWARFCompileUnit *>(cu)),
54 m_die (const_cast<DWARFDebugInfoEntry *>(die))
55 {
56 }
57
58 //----------------------------------------------------------------------
59 // Tests
60 //----------------------------------------------------------------------
61 operator bool () const
62 {
63 return IsValid();
64 }
65
66 bool
67 IsValid() const
68 {
69 return m_cu && m_die;
70 }
71
72 bool
73 IsStructOrClass () const;
74
75 bool
76 HasChildren () const;
77
78 bool
79 Supports_DW_AT_APPLE_objc_complete_type () const;
80
81 //----------------------------------------------------------------------
82 // Accessors
83 //----------------------------------------------------------------------
84 SymbolFileDWARF *
85 GetDWARF () const;
86
87 DWARFCompileUnit *
88 GetCU() const
89 {
90 return m_cu;
91 }
92
93 DWARFDebugInfoEntry *
94 GetDIE() const
95 {
96 return m_die;
97 }
98
Tamas Berghammereb882fc2015-09-09 10:20:48 +000099 DIERef
100 GetDIERef() const;
101
Greg Clayton6071e6f2015-08-26 22:57:51 +0000102 lldb_private::TypeSystem *
103 GetTypeSystem () const;
104
Greg Clayton261ac3f2015-08-28 01:01:03 +0000105 DWARFASTParser *
106 GetDWARFParser () const;
107
Greg Clayton6071e6f2015-08-26 22:57:51 +0000108 void
109 Set (DWARFCompileUnit *cu, DWARFDebugInfoEntry *die)
110 {
111 if (cu && die)
112 {
113 m_cu = cu;
114 m_die = die;
115 }
116 else
117 {
118 Clear();
119 }
120 }
121
122 void
123 Clear ()
124 {
125 m_cu = nullptr;
126 m_die = nullptr;
127 }
128
129 //----------------------------------------------------------------------
130 // Accessing information about a DIE
131 //----------------------------------------------------------------------
132 dw_tag_t
133 Tag() const;
134
135 const char *
136 GetTagAsCString () const;
137
138 dw_offset_t
139 GetOffset () const;
140
141 dw_offset_t
142 GetCompileUnitRelativeOffset () const;
143
144 //----------------------------------------------------------------------
145 // Get the LLDB user ID for this DIE. This is often just the DIE offset,
146 // but it might have a SymbolFileDWARF::GetID() in the high 32 bits if
147 // we are doing Darwin DWARF in .o file, or DWARF stand alone debug
148 // info.
149 //----------------------------------------------------------------------
150 lldb::user_id_t
151 GetID() const;
152
153 const char *
154 GetName () const;
155
156 const char *
157 GetMangledName () const;
158
159 const char *
160 GetPubname () const;
161
162 const char *
163 GetQualifiedName (std::string &storage) const;
164
165 lldb::LanguageType
166 GetLanguage () const;
167
168 lldb::ModuleSP
169 GetModule () const;
170
171 lldb_private::CompileUnit *
172 GetLLDBCompileUnit () const;
173
174 lldb_private::Type *
175 ResolveType () const;
176
177 // Resolve a type by UID using this DIE's DWARF file
178 lldb_private::Type *
179 ResolveTypeUID (lldb::user_id_t uid) const;
180
181 //----------------------------------------------------------------------
182 // Functions for obtaining DIE relations and references
183 //----------------------------------------------------------------------
184
185 DWARFDIE
186 GetParent () const;
187
188 DWARFDIE
189 GetFirstChild () const;
190
191 DWARFDIE
192 GetSibling () const;
193
194 DWARFDIE
195 GetReferencedDIE (const dw_attr_t attr) const;
196
197 //----------------------------------------------------------------------
198 // Get a another DIE from the same DWARF file as this DIE. This will
199 // check the current DIE's compile unit first to see if "die_offset" is
200 // in the same compile unit, and fall back to checking the DWARF file.
201 //----------------------------------------------------------------------
202 DWARFDIE
203 GetDIE (dw_offset_t die_offset) const;
204
205 DWARFDIE
206 LookupDeepestBlock (lldb::addr_t file_addr) const;
207
208 DWARFDIE
209 GetParentDeclContextDIE () const;
210
211 //----------------------------------------------------------------------
212 // DeclContext related functions
213 //----------------------------------------------------------------------
214 void
215 GetDeclContextDIEs (DWARFDIECollection &decl_context_dies) const;
216
217 void
218 GetDWARFDeclContext (DWARFDeclContext &dwarf_decl_ctx) const;
219
220 //----------------------------------------------------------------------
221 // Getting attribute values from the DIE.
222 //
223 // GetAttributeValueAsXXX() functions should only be used if you are
224 // looking for one or two attributes on a DIE. If you are trying to
225 // parse all attributes, use GetAttributes (...) instead
226 //----------------------------------------------------------------------
227 const char *
228 GetAttributeValueAsString (const dw_attr_t attr, const char *fail_value) const;
229
230 uint64_t
231 GetAttributeValueAsUnsigned (const dw_attr_t attr, uint64_t fail_value) const;
232
233 int64_t
234 GetAttributeValueAsSigned (const dw_attr_t attr, int64_t fail_value) const;
235
236 uint64_t
237 GetAttributeValueAsReference (const dw_attr_t attr, uint64_t fail_value) const;
238
Tamas Berghammereb882fc2015-09-09 10:20:48 +0000239 uint64_t
240 GetAttributeValueAsAddress (const dw_attr_t attr, uint64_t fail_value) const;
241
Greg Clayton6071e6f2015-08-26 22:57:51 +0000242 size_t
243 GetAttributes (DWARFAttributes &attributes, uint32_t depth = 0) const;
244
245 bool
246 GetDIENamesAndRanges (const char * &name,
247 const char * &mangled,
248 DWARFRangeList& ranges,
249 int& decl_file,
250 int& decl_line,
251 int& decl_column,
252 int& call_file,
253 int& call_line,
254 int& call_column,
255 lldb_private::DWARFExpression *frame_base) const;
256
257 //----------------------------------------------------------------------
258 // Pretty printing
259 //----------------------------------------------------------------------
260
261 void
262 Dump (lldb_private::Stream *s, const uint32_t recurse_depth) const;
263
264protected:
265 DWARFCompileUnit *m_cu;
266 DWARFDebugInfoEntry *m_die;
267};
268
269bool operator == (const DWARFDIE &lhs, const DWARFDIE &rhs);
270bool operator != (const DWARFDIE &lhs, const DWARFDIE &rhs);
271
272#endif // SymbolFileDWARF_DWARFDIE_h_