blob: 6d80d77d0442420adccc66003ab09a94ed4c2b24 [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 Callanan213fdb82011-10-13 01:49:10 +000079 virtual uint32_t FindFunctions (const lldb_private::ConstString &name, const lldb_private::ClangNamespaceDecl *namespace_decl, uint32_t name_type_mask, bool append, lldb_private::SymbolContextList& sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000080 virtual uint32_t FindFunctions (const lldb_private::RegularExpression& regex, 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;
144 lldb::SharedPtr<lldb_private::SectionList>::Type debug_map_sections_sp;
145
146 CompileUnitInfo() :
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000147 so_file (),
148 so_symbol (NULL),
149 oso_symbol (NULL),
150 last_symbol (NULL),
151 first_symbol_index (UINT32_MAX),
152 last_symbol_index (UINT32_MAX),
153 oso_module_sp (),
154 oso_compile_unit_sp (),
155 oso_symbol_vendor (NULL),
156 function_indexes (),
157 static_indexes (),
158 debug_map_sections_sp ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000159 {
160 }
161 };
162
163 //------------------------------------------------------------------
164 // Protected Member Functions
165 //------------------------------------------------------------------
166 void
167 InitOSO ();
168
Greg Clayton81c22f62011-10-19 18:09:39 +0000169 static uint32_t
170 GetOSOIndexFromUserID (lldb::user_id_t uid)
171 {
172 return (uint32_t)((uid >> 32ull) - 1ull);
173 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000174 bool
175 GetFileSpecForSO (uint32_t oso_idx, lldb_private::FileSpec &file_spec);
176
177 CompileUnitInfo *
178 GetCompUnitInfo (const lldb_private::SymbolContext& sc);
179
180 lldb_private::Module *
181 GetModuleByCompUnitInfo (CompileUnitInfo *comp_unit_info);
182
183 lldb_private::Module *
184 GetModuleByOSOIndex (uint32_t oso_idx);
185
186 lldb_private::ObjectFile *
187 GetObjectFileByCompUnitInfo (CompileUnitInfo *comp_unit_info);
188
189 lldb_private::ObjectFile *
190 GetObjectFileByOSOIndex (uint32_t oso_idx);
191
Greg Clayton81c22f62011-10-19 18:09:39 +0000192 uint32_t
193 GetCompUnitInfoIndex (const CompileUnitInfo *comp_unit_info);
194
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000195 SymbolFileDWARF *
196 GetSymbolFile (const lldb_private::SymbolContext& sc);
197
198 SymbolFileDWARF *
199 GetSymbolFileByCompUnitInfo (CompileUnitInfo *comp_unit_info);
200
201 SymbolFileDWARF *
202 GetSymbolFileByOSOIndex (uint32_t oso_idx);
203
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000204 CompileUnitInfo *
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000205 GetCompileUnitInfoForSymbolWithIndex (uint32_t symbol_idx, uint32_t *oso_idx_ptr);
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000206
207 CompileUnitInfo *
208 GetCompileUnitInfoForSymbolWithID (lldb::user_id_t symbol_id, uint32_t *oso_idx_ptr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000209
210 static int
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000211 SymbolContainsSymbolWithIndex (uint32_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info);
212
213 static int
214 SymbolContainsSymbolWithID (lldb::user_id_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000215
216 uint32_t
217 PrivateFindGlobalVariables (const lldb_private::ConstString &name,
Sean Callanan213fdb82011-10-13 01:49:10 +0000218 const lldb_private::ClangNamespaceDecl *namespace_decl,
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000219 const std::vector<uint32_t> &name_symbol_indexes,
220 uint32_t max_matches,
221 lldb_private::VariableList& variables);
222
Greg Clayton450e3f32010-10-12 02:24:53 +0000223
224 void
225 SetCompileUnit (SymbolFileDWARF *oso_dwarf, const lldb::CompUnitSP &cu_sp);
226
Greg Clayton2ccf8cf2010-11-07 21:02:03 +0000227 lldb::TypeSP
228 FindDefinitionTypeForDIE (DWARFCompileUnit* cu,
229 const DWARFDebugInfoEntry *die,
230 const lldb_private::ConstString &type_name);
231
Greg Claytonc7f03b62012-01-12 04:33:28 +0000232 bool
233 Supports_DW_AT_APPLE_objc_complete_type (SymbolFileDWARF *skip_dwarf_oso);
234
Greg Clayton901c5ca2011-12-03 04:40:03 +0000235 lldb::TypeSP
Greg Claytonc7f03b62012-01-12 04:33:28 +0000236 FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die,
237 const lldb_private::ConstString &type_name,
238 bool must_be_implementation);
Greg Clayton901c5ca2011-12-03 04:40:03 +0000239
240
Greg Claytone576ab22011-02-15 00:19:15 +0000241 UniqueDWARFASTTypeMap &
242 GetUniqueDWARFASTTypeMap ()
243 {
244 return m_unique_ast_type_map;
245 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000246 //------------------------------------------------------------------
247 // Member Variables
248 //------------------------------------------------------------------
249 std::bitset<kNumFlags> m_flags;
250 std::vector<CompileUnitInfo> m_compile_unit_infos;
251 std::vector<uint32_t> m_func_indexes; // Sorted by address
252 std::vector<uint32_t> m_glob_indexes;
Greg Claytone576ab22011-02-15 00:19:15 +0000253 UniqueDWARFASTTypeMap m_unique_ast_type_map;
Greg Claytonc7f03b62012-01-12 04:33:28 +0000254 lldb_private::LazyBool m_supports_DW_AT_APPLE_objc_complete_type;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000255};
256
Greg Claytona76dd622011-09-12 04:20:38 +0000257#endif // #ifndef SymbolFileDWARF_SymbolFileDWARFDebugMap_h_