blob: ecc6f67a6865ec2e623afd270a85a60789be109e [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;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000132 //------------------------------------------------------------------
133 // Class specific types
134 //------------------------------------------------------------------
135 struct CompileUnitInfo
136 {
137 lldb_private::FileSpec so_file;
Greg Clayton1f746072012-08-29 21:13:06 +0000138 lldb_private::FileSpec oso_file;
139 lldb_private::ConstString oso_object; // for archives this will be the .o file in the "oso_file"
140// lldb_private::Symbol *so_symbol;
141// lldb_private::Symbol *oso_symbol;
142// lldb_private::Symbol *last_symbol;
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000143 uint32_t first_symbol_index;
144 uint32_t last_symbol_index;
Greg Clayton1f746072012-08-29 21:13:06 +0000145 uint32_t first_symbol_id;
146 uint32_t last_symbol_id;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000147 lldb::ModuleSP oso_module_sp;
148 lldb::CompUnitSP oso_compile_unit_sp;
Greg Clayton1f746072012-08-29 21:13:06 +0000149// SymbolFileDWARF *oso_symfile;
Sean Callanan21f395f2012-03-24 00:43:18 +0000150 bool symbol_file_supported;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000151
152 CompileUnitInfo() :
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000153 so_file (),
Greg Clayton1f746072012-08-29 21:13:06 +0000154 oso_file (),
155 oso_object (),
156// so_symbol (NULL),
157// oso_symbol (NULL),
158// last_symbol (NULL),
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000159 first_symbol_index (UINT32_MAX),
160 last_symbol_index (UINT32_MAX),
Greg Clayton1f746072012-08-29 21:13:06 +0000161 first_symbol_id (UINT32_MAX),
162 last_symbol_id (UINT32_MAX),
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000163 oso_module_sp (),
164 oso_compile_unit_sp (),
Greg Clayton1f746072012-08-29 21:13:06 +0000165// oso_symfile (NULL),
Sean Callanan21f395f2012-03-24 00:43:18 +0000166 symbol_file_supported (true)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000167 {
168 }
169 };
170
171 //------------------------------------------------------------------
172 // Protected Member Functions
173 //------------------------------------------------------------------
174 void
175 InitOSO ();
176
Greg Clayton81c22f62011-10-19 18:09:39 +0000177 static uint32_t
178 GetOSOIndexFromUserID (lldb::user_id_t uid)
179 {
180 return (uint32_t)((uid >> 32ull) - 1ull);
181 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000182 bool
183 GetFileSpecForSO (uint32_t oso_idx, lldb_private::FileSpec &file_spec);
184
185 CompileUnitInfo *
186 GetCompUnitInfo (const lldb_private::SymbolContext& sc);
187
Greg Clayton1f746072012-08-29 21:13:06 +0000188 CompileUnitInfo *
189 GetCompUnitInfo (const lldb_private::Module *oso_module);
190
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000191 lldb_private::Module *
192 GetModuleByCompUnitInfo (CompileUnitInfo *comp_unit_info);
193
194 lldb_private::Module *
195 GetModuleByOSOIndex (uint32_t oso_idx);
196
197 lldb_private::ObjectFile *
198 GetObjectFileByCompUnitInfo (CompileUnitInfo *comp_unit_info);
199
200 lldb_private::ObjectFile *
201 GetObjectFileByOSOIndex (uint32_t oso_idx);
202
Greg Clayton81c22f62011-10-19 18:09:39 +0000203 uint32_t
204 GetCompUnitInfoIndex (const CompileUnitInfo *comp_unit_info);
205
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000206 SymbolFileDWARF *
207 GetSymbolFile (const lldb_private::SymbolContext& sc);
208
209 SymbolFileDWARF *
210 GetSymbolFileByCompUnitInfo (CompileUnitInfo *comp_unit_info);
211
212 SymbolFileDWARF *
213 GetSymbolFileByOSOIndex (uint32_t oso_idx);
214
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000215 CompileUnitInfo *
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000216 GetCompileUnitInfoForSymbolWithIndex (uint32_t symbol_idx, uint32_t *oso_idx_ptr);
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000217
218 CompileUnitInfo *
219 GetCompileUnitInfoForSymbolWithID (lldb::user_id_t symbol_id, uint32_t *oso_idx_ptr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000220
221 static int
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000222 SymbolContainsSymbolWithIndex (uint32_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info);
223
224 static int
225 SymbolContainsSymbolWithID (lldb::user_id_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000226
227 uint32_t
228 PrivateFindGlobalVariables (const lldb_private::ConstString &name,
Sean Callanan213fdb82011-10-13 01:49:10 +0000229 const lldb_private::ClangNamespaceDecl *namespace_decl,
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000230 const std::vector<uint32_t> &name_symbol_indexes,
231 uint32_t max_matches,
232 lldb_private::VariableList& variables);
233
Greg Clayton450e3f32010-10-12 02:24:53 +0000234
235 void
236 SetCompileUnit (SymbolFileDWARF *oso_dwarf, const lldb::CompUnitSP &cu_sp);
237
Greg Clayton1f746072012-08-29 21:13:06 +0000238 lldb::CompUnitSP
239 GetCompileUnit (SymbolFileDWARF *oso_dwarf);
240
Greg Clayton2ccf8cf2010-11-07 21:02:03 +0000241 lldb::TypeSP
Greg Claytona8022fa2012-04-24 21:22:41 +0000242 FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &die_decl_ctx);
Greg Clayton2ccf8cf2010-11-07 21:02:03 +0000243
Greg Claytonc7f03b62012-01-12 04:33:28 +0000244 bool
245 Supports_DW_AT_APPLE_objc_complete_type (SymbolFileDWARF *skip_dwarf_oso);
246
Greg Clayton901c5ca2011-12-03 04:40:03 +0000247 lldb::TypeSP
Greg Claytonc7f03b62012-01-12 04:33:28 +0000248 FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die,
249 const lldb_private::ConstString &type_name,
250 bool must_be_implementation);
Greg Clayton901c5ca2011-12-03 04:40:03 +0000251
252
Greg Claytone576ab22011-02-15 00:19:15 +0000253 UniqueDWARFASTTypeMap &
254 GetUniqueDWARFASTTypeMap ()
255 {
256 return m_unique_ast_type_map;
257 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000258 //------------------------------------------------------------------
259 // Member Variables
260 //------------------------------------------------------------------
261 std::bitset<kNumFlags> m_flags;
262 std::vector<CompileUnitInfo> m_compile_unit_infos;
263 std::vector<uint32_t> m_func_indexes; // Sorted by address
264 std::vector<uint32_t> m_glob_indexes;
Greg Claytone576ab22011-02-15 00:19:15 +0000265 UniqueDWARFASTTypeMap m_unique_ast_type_map;
Greg Claytonc7f03b62012-01-12 04:33:28 +0000266 lldb_private::LazyBool m_supports_DW_AT_APPLE_objc_complete_type;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000267};
268
Greg Claytona76dd622011-09-12 04:20:38 +0000269#endif // #ifndef SymbolFileDWARF_SymbolFileDWARFDebugMap_h_