blob: 971d3e1659b93c65172f16fd9f087f55f7bca828 [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;
Greg Claytona8022fa2012-04-24 21:22:41 +000026class DWARFDeclContext;
Greg Clayton1f746072012-08-29 21:13:06 +000027class DebugMapModule;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000028
29class SymbolFileDWARFDebugMap : public lldb_private::SymbolFile
30{
31public:
Greg Clayton1f746072012-08-29 21:13:06 +000032
Chris Lattner30fdc8d2010-06-08 16:52:24 +000033 //------------------------------------------------------------------
34 // Static Functions
35 //------------------------------------------------------------------
36 static void
37 Initialize();
38
39 static void
40 Terminate();
41
42 static const char *
43 GetPluginNameStatic();
44
45 static const char *
46 GetPluginDescriptionStatic();
47
48 static lldb_private::SymbolFile *
49 CreateInstance (lldb_private::ObjectFile* obj_file);
50
51 //------------------------------------------------------------------
52 // Constructors and Destructors
53 //------------------------------------------------------------------
54 SymbolFileDWARFDebugMap (lldb_private::ObjectFile* ofile);
55 virtual ~ SymbolFileDWARFDebugMap ();
56
Sean Callananbfaf54d2011-12-03 04:38:43 +000057 virtual uint32_t CalculateAbilities ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000058
Greg Clayton6beaaa62011-01-17 03:46:26 +000059 virtual void InitializeObject();
60
Chris Lattner30fdc8d2010-06-08 16:52:24 +000061 //------------------------------------------------------------------
62 // Compile Unit function calls
63 //------------------------------------------------------------------
64 virtual uint32_t GetNumCompileUnits ();
65 virtual lldb::CompUnitSP ParseCompileUnitAtIndex (uint32_t index);
66
Greg Clayton1f746072012-08-29 21:13:06 +000067 virtual lldb::LanguageType ParseCompileUnitLanguage (const lldb_private::SymbolContext& sc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000068 virtual size_t ParseCompileUnitFunctions (const lldb_private::SymbolContext& sc);
69 virtual bool ParseCompileUnitLineTable (const lldb_private::SymbolContext& sc);
70 virtual bool ParseCompileUnitSupportFiles (const lldb_private::SymbolContext& sc, lldb_private::FileSpecList &support_files);
71 virtual size_t ParseFunctionBlocks (const lldb_private::SymbolContext& sc);
72 virtual size_t ParseTypes (const lldb_private::SymbolContext& sc);
73 virtual size_t ParseVariablesForContext (const lldb_private::SymbolContext& sc);
74
Greg Clayton1be10fc2010-09-29 01:12:09 +000075 virtual lldb_private::Type* ResolveTypeUID (lldb::user_id_t type_uid);
Greg Clayton81c22f62011-10-19 18:09:39 +000076 virtual clang::DeclContext* GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid);
77 virtual clang::DeclContext* GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid);
Greg Clayton1be10fc2010-09-29 01:12:09 +000078 virtual lldb::clang_type_t ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_Type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000079 virtual uint32_t ResolveSymbolContext (const lldb_private::Address& so_addr, uint32_t resolve_scope, lldb_private::SymbolContext& sc);
80 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 +000081 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 +000082 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 +000083 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);
84 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 +000085 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 +000086 virtual lldb_private::ClangNamespaceDecl
Greg Clayton96d7d742010-11-10 23:42:09 +000087 FindNamespace (const lldb_private::SymbolContext& sc,
Sean Callanan213fdb82011-10-13 01:49:10 +000088 const lldb_private::ConstString &name,
89 const lldb_private::ClangNamespaceDecl *parent_namespace_decl);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000090
Greg Clayton6beaaa62011-01-17 03:46:26 +000091
92 //------------------------------------------------------------------
93 // ClangASTContext callbacks for external source lookups.
94 //------------------------------------------------------------------
95 static void
96 CompleteTagDecl (void *baton, clang::TagDecl *);
97
98 static void
99 CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *);
Greg Claytoncaab74e2012-01-28 00:48:57 +0000100
101 static bool
102 LayoutRecordType (void *baton,
103 const clang::RecordDecl *record_decl,
104 uint64_t &size,
105 uint64_t &alignment,
106 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
107 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
108 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets);
109
Greg Clayton6beaaa62011-01-17 03:46:26 +0000110
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000111 //------------------------------------------------------------------
112 // PluginInterface protocol
113 //------------------------------------------------------------------
114 virtual const char *
115 GetPluginName();
116
117 virtual const char *
118 GetShortPluginName();
119
120 virtual uint32_t
121 GetPluginVersion();
122
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000123protected:
124 enum
125 {
126 kHaveInitializedOSOs = (1 << 0),
127 kNumFlags
128 };
129
Greg Clayton450e3f32010-10-12 02:24:53 +0000130 friend class SymbolFileDWARF;
Greg Clayton1f746072012-08-29 21:13:06 +0000131 friend class DebugMapModule;
Greg Clayton906ba472013-02-06 00:38:25 +0000132 struct OSOInfo
133 {
134 lldb::ModuleSP module_sp;
135 bool symbol_file_supported;
136
137 OSOInfo() :
138 module_sp (),
139 symbol_file_supported (true)
140 {
141 }
142 };
143
144 typedef STD_SHARED_PTR(OSOInfo) OSOInfoSP;
145
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000146 //------------------------------------------------------------------
147 // Class specific types
148 //------------------------------------------------------------------
149 struct CompileUnitInfo
150 {
151 lldb_private::FileSpec so_file;
Greg Clayton906ba472013-02-06 00:38:25 +0000152 lldb_private::ConstString oso_path;
153 OSOInfoSP oso_sp;
154 lldb::CompUnitSP compile_unit_sp;
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000155 uint32_t first_symbol_index;
156 uint32_t last_symbol_index;
Greg Clayton1f746072012-08-29 21:13:06 +0000157 uint32_t first_symbol_id;
158 uint32_t last_symbol_id;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000159
160 CompileUnitInfo() :
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000161 so_file (),
Greg Clayton906ba472013-02-06 00:38:25 +0000162 oso_path (),
163 oso_sp (),
164 compile_unit_sp (),
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000165 first_symbol_index (UINT32_MAX),
166 last_symbol_index (UINT32_MAX),
Greg Clayton1f746072012-08-29 21:13:06 +0000167 first_symbol_id (UINT32_MAX),
Greg Clayton906ba472013-02-06 00:38:25 +0000168 last_symbol_id (UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000169 {
170 }
171 };
172
173 //------------------------------------------------------------------
174 // Protected Member Functions
175 //------------------------------------------------------------------
176 void
177 InitOSO ();
178
Greg Clayton81c22f62011-10-19 18:09:39 +0000179 static uint32_t
180 GetOSOIndexFromUserID (lldb::user_id_t uid)
181 {
182 return (uint32_t)((uid >> 32ull) - 1ull);
183 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000184 bool
185 GetFileSpecForSO (uint32_t oso_idx, lldb_private::FileSpec &file_spec);
186
187 CompileUnitInfo *
188 GetCompUnitInfo (const lldb_private::SymbolContext& sc);
189
Greg Clayton906ba472013-02-06 00:38:25 +0000190 size_t
191 GetCompUnitInfosForModule (const lldb_private::Module *oso_module,
192 std::vector<CompileUnitInfo *>& cu_infos);
Greg Clayton1f746072012-08-29 21:13:06 +0000193
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000194 lldb_private::Module *
195 GetModuleByCompUnitInfo (CompileUnitInfo *comp_unit_info);
196
197 lldb_private::Module *
198 GetModuleByOSOIndex (uint32_t oso_idx);
199
200 lldb_private::ObjectFile *
201 GetObjectFileByCompUnitInfo (CompileUnitInfo *comp_unit_info);
202
203 lldb_private::ObjectFile *
204 GetObjectFileByOSOIndex (uint32_t oso_idx);
205
Greg Clayton81c22f62011-10-19 18:09:39 +0000206 uint32_t
207 GetCompUnitInfoIndex (const CompileUnitInfo *comp_unit_info);
208
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000209 SymbolFileDWARF *
210 GetSymbolFile (const lldb_private::SymbolContext& sc);
211
212 SymbolFileDWARF *
213 GetSymbolFileByCompUnitInfo (CompileUnitInfo *comp_unit_info);
214
215 SymbolFileDWARF *
216 GetSymbolFileByOSOIndex (uint32_t oso_idx);
217
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000218 CompileUnitInfo *
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000219 GetCompileUnitInfoForSymbolWithIndex (uint32_t symbol_idx, uint32_t *oso_idx_ptr);
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000220
221 CompileUnitInfo *
222 GetCompileUnitInfoForSymbolWithID (lldb::user_id_t symbol_id, uint32_t *oso_idx_ptr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000223
224 static int
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000225 SymbolContainsSymbolWithIndex (uint32_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info);
226
227 static int
228 SymbolContainsSymbolWithID (lldb::user_id_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000229
230 uint32_t
231 PrivateFindGlobalVariables (const lldb_private::ConstString &name,
Sean Callanan213fdb82011-10-13 01:49:10 +0000232 const lldb_private::ClangNamespaceDecl *namespace_decl,
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000233 const std::vector<uint32_t> &name_symbol_indexes,
234 uint32_t max_matches,
235 lldb_private::VariableList& variables);
236
Greg Clayton450e3f32010-10-12 02:24:53 +0000237
238 void
239 SetCompileUnit (SymbolFileDWARF *oso_dwarf, const lldb::CompUnitSP &cu_sp);
240
Greg Clayton1f746072012-08-29 21:13:06 +0000241 lldb::CompUnitSP
242 GetCompileUnit (SymbolFileDWARF *oso_dwarf);
243
Greg Clayton2ccf8cf2010-11-07 21:02:03 +0000244 lldb::TypeSP
Greg Claytona8022fa2012-04-24 21:22:41 +0000245 FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &die_decl_ctx);
Greg Clayton2ccf8cf2010-11-07 21:02:03 +0000246
Greg Claytonc7f03b62012-01-12 04:33:28 +0000247 bool
248 Supports_DW_AT_APPLE_objc_complete_type (SymbolFileDWARF *skip_dwarf_oso);
249
Greg Clayton901c5ca2011-12-03 04:40:03 +0000250 lldb::TypeSP
Greg Claytonc7f03b62012-01-12 04:33:28 +0000251 FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die,
252 const lldb_private::ConstString &type_name,
253 bool must_be_implementation);
Greg Clayton901c5ca2011-12-03 04:40:03 +0000254
255
Greg Claytone576ab22011-02-15 00:19:15 +0000256 UniqueDWARFASTTypeMap &
257 GetUniqueDWARFASTTypeMap ()
258 {
259 return m_unique_ast_type_map;
260 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000261 //------------------------------------------------------------------
262 // Member Variables
263 //------------------------------------------------------------------
264 std::bitset<kNumFlags> m_flags;
265 std::vector<CompileUnitInfo> m_compile_unit_infos;
266 std::vector<uint32_t> m_func_indexes; // Sorted by address
267 std::vector<uint32_t> m_glob_indexes;
Greg Clayton906ba472013-02-06 00:38:25 +0000268 std::map<lldb_private::ConstString, OSOInfoSP> m_oso_map;
Greg Claytone576ab22011-02-15 00:19:15 +0000269 UniqueDWARFASTTypeMap m_unique_ast_type_map;
Greg Claytonc7f03b62012-01-12 04:33:28 +0000270 lldb_private::LazyBool m_supports_DW_AT_APPLE_objc_complete_type;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000271};
272
Greg Claytona76dd622011-09-12 04:20:38 +0000273#endif // #ifndef SymbolFileDWARF_SymbolFileDWARFDebugMap_h_