blob: 4ac0f4c977214baa2157f8090eb9c09c6c566a7a [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- SymbolFileDWARFDebugMap.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
Greg Claytona76dd622011-09-12 04:20:38 +000010#ifndef SymbolFileDWARF_SymbolFileDWARFDebugMap_h_
11#define SymbolFileDWARF_SymbolFileDWARFDebugMap_h_
Chris Lattner30fdc8d2010-06-08 16:52:24 +000012
13
14#include <vector>
15#include <bitset>
Greg Claytoncaab74e2012-01-28 00:48:57 +000016
17#include "clang/AST/CharUnits.h"
18
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019#include "lldb/Symbol/SymbolFile.h"
20
Greg Claytone576ab22011-02-15 00:19:15 +000021#include "UniqueDWARFASTType.h"
22
Chris Lattner30fdc8d2010-06-08 16:52:24 +000023class SymbolFileDWARF;
Greg Clayton2ccf8cf2010-11-07 21:02:03 +000024class DWARFCompileUnit;
25class DWARFDebugInfoEntry;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000026
27class SymbolFileDWARFDebugMap : public lldb_private::SymbolFile
28{
29public:
30 //------------------------------------------------------------------
31 // Static Functions
32 //------------------------------------------------------------------
33 static void
34 Initialize();
35
36 static void
37 Terminate();
38
39 static const char *
40 GetPluginNameStatic();
41
42 static const char *
43 GetPluginDescriptionStatic();
44
45 static lldb_private::SymbolFile *
46 CreateInstance (lldb_private::ObjectFile* obj_file);
47
48 //------------------------------------------------------------------
49 // Constructors and Destructors
50 //------------------------------------------------------------------
51 SymbolFileDWARFDebugMap (lldb_private::ObjectFile* ofile);
52 virtual ~ SymbolFileDWARFDebugMap ();
53
Sean Callananbfaf54d2011-12-03 04:38:43 +000054 virtual uint32_t CalculateAbilities ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000055
Greg Clayton6beaaa62011-01-17 03:46:26 +000056 virtual void InitializeObject();
57
Chris Lattner30fdc8d2010-06-08 16:52:24 +000058 //------------------------------------------------------------------
59 // Compile Unit function calls
60 //------------------------------------------------------------------
61 virtual uint32_t GetNumCompileUnits ();
62 virtual lldb::CompUnitSP ParseCompileUnitAtIndex (uint32_t index);
63
64 virtual size_t ParseCompileUnitFunctions (const lldb_private::SymbolContext& sc);
65 virtual bool ParseCompileUnitLineTable (const lldb_private::SymbolContext& sc);
66 virtual bool ParseCompileUnitSupportFiles (const lldb_private::SymbolContext& sc, lldb_private::FileSpecList &support_files);
67 virtual size_t ParseFunctionBlocks (const lldb_private::SymbolContext& sc);
68 virtual size_t ParseTypes (const lldb_private::SymbolContext& sc);
69 virtual size_t ParseVariablesForContext (const lldb_private::SymbolContext& sc);
70
Greg Clayton1be10fc2010-09-29 01:12:09 +000071 virtual lldb_private::Type* ResolveTypeUID (lldb::user_id_t type_uid);
Greg Clayton81c22f62011-10-19 18:09:39 +000072 virtual clang::DeclContext* GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid);
73 virtual clang::DeclContext* GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid);
Greg Clayton1be10fc2010-09-29 01:12:09 +000074 virtual lldb::clang_type_t ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_Type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000075 virtual uint32_t ResolveSymbolContext (const lldb_private::Address& so_addr, uint32_t resolve_scope, lldb_private::SymbolContext& sc);
76 virtual uint32_t ResolveSymbolContext (const lldb_private::FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, lldb_private::SymbolContextList& sc_list);
Sean Callanan213fdb82011-10-13 01:49:10 +000077 virtual uint32_t FindGlobalVariables (const lldb_private::ConstString &name, const lldb_private::ClangNamespaceDecl *namespace_decl, bool append, uint32_t max_matches, lldb_private::VariableList& variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000078 virtual uint32_t FindGlobalVariables (const lldb_private::RegularExpression& regex, bool append, uint32_t max_matches, lldb_private::VariableList& variables);
Sean Callanan9df05fb2012-02-10 22:52:19 +000079 virtual uint32_t FindFunctions (const lldb_private::ConstString &name, const lldb_private::ClangNamespaceDecl *namespace_decl, uint32_t name_type_mask, bool include_inlines, bool append, lldb_private::SymbolContextList& sc_list);
80 virtual uint32_t FindFunctions (const lldb_private::RegularExpression& regex, bool include_inlines, bool append, lldb_private::SymbolContextList& sc_list);
Sean Callanan213fdb82011-10-13 01:49:10 +000081 virtual uint32_t FindTypes (const lldb_private::SymbolContext& sc, const lldb_private::ConstString &name, const lldb_private::ClangNamespaceDecl *namespace_decl, bool append, uint32_t max_matches, lldb_private::TypeList& types);
Greg Clayton526e5af2010-11-13 03:52:47 +000082 virtual lldb_private::ClangNamespaceDecl
Greg Clayton96d7d742010-11-10 23:42:09 +000083 FindNamespace (const lldb_private::SymbolContext& sc,
Sean Callanan213fdb82011-10-13 01:49:10 +000084 const lldb_private::ConstString &name,
85 const lldb_private::ClangNamespaceDecl *parent_namespace_decl);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000086
Greg Clayton6beaaa62011-01-17 03:46:26 +000087
88 //------------------------------------------------------------------
89 // ClangASTContext callbacks for external source lookups.
90 //------------------------------------------------------------------
91 static void
92 CompleteTagDecl (void *baton, clang::TagDecl *);
93
94 static void
95 CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *);
Greg Claytoncaab74e2012-01-28 00:48:57 +000096
97 static bool
98 LayoutRecordType (void *baton,
99 const clang::RecordDecl *record_decl,
100 uint64_t &size,
101 uint64_t &alignment,
102 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
103 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
104 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets);
105
Greg Clayton6beaaa62011-01-17 03:46:26 +0000106
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000107 //------------------------------------------------------------------
108 // PluginInterface protocol
109 //------------------------------------------------------------------
110 virtual const char *
111 GetPluginName();
112
113 virtual const char *
114 GetShortPluginName();
115
116 virtual uint32_t
117 GetPluginVersion();
118
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000119protected:
120 enum
121 {
122 kHaveInitializedOSOs = (1 << 0),
123 kNumFlags
124 };
125
Greg Clayton450e3f32010-10-12 02:24:53 +0000126 friend class SymbolFileDWARF;
127
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000128 //------------------------------------------------------------------
129 // Class specific types
130 //------------------------------------------------------------------
131 struct CompileUnitInfo
132 {
133 lldb_private::FileSpec so_file;
134 lldb_private::Symbol *so_symbol;
135 lldb_private::Symbol *oso_symbol;
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000136 lldb_private::Symbol *last_symbol;
137 uint32_t first_symbol_index;
138 uint32_t last_symbol_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000139 lldb::ModuleSP oso_module_sp;
140 lldb::CompUnitSP oso_compile_unit_sp;
141 lldb_private::SymbolVendor *oso_symbol_vendor;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000142 std::vector<uint32_t> function_indexes;
143 std::vector<uint32_t> static_indexes;
Greg Claytond64afba2012-03-14 03:07:05 +0000144 STD_SHARED_PTR(lldb_private::SectionList) debug_map_sections_sp;
Sean Callanan21f395f2012-03-24 00:43:18 +0000145 bool symbol_file_supported;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000146
147 CompileUnitInfo() :
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000148 so_file (),
149 so_symbol (NULL),
150 oso_symbol (NULL),
151 last_symbol (NULL),
152 first_symbol_index (UINT32_MAX),
153 last_symbol_index (UINT32_MAX),
154 oso_module_sp (),
155 oso_compile_unit_sp (),
156 oso_symbol_vendor (NULL),
157 function_indexes (),
158 static_indexes (),
Sean Callanan21f395f2012-03-24 00:43:18 +0000159 debug_map_sections_sp (),
160 symbol_file_supported (true)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000161 {
162 }
163 };
164
165 //------------------------------------------------------------------
166 // Protected Member Functions
167 //------------------------------------------------------------------
168 void
169 InitOSO ();
170
Greg Clayton81c22f62011-10-19 18:09:39 +0000171 static uint32_t
172 GetOSOIndexFromUserID (lldb::user_id_t uid)
173 {
174 return (uint32_t)((uid >> 32ull) - 1ull);
175 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000176 bool
177 GetFileSpecForSO (uint32_t oso_idx, lldb_private::FileSpec &file_spec);
178
179 CompileUnitInfo *
180 GetCompUnitInfo (const lldb_private::SymbolContext& sc);
181
182 lldb_private::Module *
183 GetModuleByCompUnitInfo (CompileUnitInfo *comp_unit_info);
184
185 lldb_private::Module *
186 GetModuleByOSOIndex (uint32_t oso_idx);
187
188 lldb_private::ObjectFile *
189 GetObjectFileByCompUnitInfo (CompileUnitInfo *comp_unit_info);
190
191 lldb_private::ObjectFile *
192 GetObjectFileByOSOIndex (uint32_t oso_idx);
193
Greg Clayton81c22f62011-10-19 18:09:39 +0000194 uint32_t
195 GetCompUnitInfoIndex (const CompileUnitInfo *comp_unit_info);
196
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000197 SymbolFileDWARF *
198 GetSymbolFile (const lldb_private::SymbolContext& sc);
199
200 SymbolFileDWARF *
201 GetSymbolFileByCompUnitInfo (CompileUnitInfo *comp_unit_info);
202
203 SymbolFileDWARF *
204 GetSymbolFileByOSOIndex (uint32_t oso_idx);
205
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000206 CompileUnitInfo *
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000207 GetCompileUnitInfoForSymbolWithIndex (uint32_t symbol_idx, uint32_t *oso_idx_ptr);
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000208
209 CompileUnitInfo *
210 GetCompileUnitInfoForSymbolWithID (lldb::user_id_t symbol_id, uint32_t *oso_idx_ptr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000211
212 static int
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000213 SymbolContainsSymbolWithIndex (uint32_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info);
214
215 static int
216 SymbolContainsSymbolWithID (lldb::user_id_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000217
218 uint32_t
219 PrivateFindGlobalVariables (const lldb_private::ConstString &name,
Sean Callanan213fdb82011-10-13 01:49:10 +0000220 const lldb_private::ClangNamespaceDecl *namespace_decl,
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000221 const std::vector<uint32_t> &name_symbol_indexes,
222 uint32_t max_matches,
223 lldb_private::VariableList& variables);
224
Greg Clayton450e3f32010-10-12 02:24:53 +0000225
226 void
227 SetCompileUnit (SymbolFileDWARF *oso_dwarf, const lldb::CompUnitSP &cu_sp);
228
Greg Clayton2ccf8cf2010-11-07 21:02:03 +0000229 lldb::TypeSP
230 FindDefinitionTypeForDIE (DWARFCompileUnit* cu,
231 const DWARFDebugInfoEntry *die,
232 const lldb_private::ConstString &type_name);
233
Greg Claytonc7f03b62012-01-12 04:33:28 +0000234 bool
235 Supports_DW_AT_APPLE_objc_complete_type (SymbolFileDWARF *skip_dwarf_oso);
236
Greg Clayton901c5ca2011-12-03 04:40:03 +0000237 lldb::TypeSP
Greg Claytonc7f03b62012-01-12 04:33:28 +0000238 FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die,
239 const lldb_private::ConstString &type_name,
240 bool must_be_implementation);
Greg Clayton901c5ca2011-12-03 04:40:03 +0000241
242
Greg Claytone576ab22011-02-15 00:19:15 +0000243 UniqueDWARFASTTypeMap &
244 GetUniqueDWARFASTTypeMap ()
245 {
246 return m_unique_ast_type_map;
247 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000248 //------------------------------------------------------------------
249 // Member Variables
250 //------------------------------------------------------------------
251 std::bitset<kNumFlags> m_flags;
252 std::vector<CompileUnitInfo> m_compile_unit_infos;
253 std::vector<uint32_t> m_func_indexes; // Sorted by address
254 std::vector<uint32_t> m_glob_indexes;
Greg Claytone576ab22011-02-15 00:19:15 +0000255 UniqueDWARFASTTypeMap m_unique_ast_type_map;
Greg Claytonc7f03b62012-01-12 04:33:28 +0000256 lldb_private::LazyBool m_supports_DW_AT_APPLE_objc_complete_type;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000257};
258
Greg Claytona76dd622011-09-12 04:20:38 +0000259#endif // #ifndef SymbolFileDWARF_SymbolFileDWARFDebugMap_h_