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