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