blob: 7b49ab22feda88651a8fd4bb60b1897e47dd1351 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- SymbolVendor.mm -----------------------------------------*- 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#include "lldb/Symbol/SymbolVendor.h"
11
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
16#include "lldb/Core/Module.h"
17#include "lldb/Core/PluginManager.h"
Greg Clayton1f746072012-08-29 21:13:06 +000018#include "lldb/Core/Stream.h"
19#include "lldb/Symbol/CompileUnit.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020#include "lldb/Symbol/ObjectFile.h"
21#include "lldb/Symbol/SymbolFile.h"
22
23using namespace lldb;
24using namespace lldb_private;
25
26
27//----------------------------------------------------------------------
28// FindPlugin
29//
30// Platforms can register a callback to use when creating symbol
31// vendors to allow for complex debug information file setups, and to
32// also allow for finding separate debug information files.
33//----------------------------------------------------------------------
34SymbolVendor*
Greg Clayton136dff82012-12-14 02:15:00 +000035SymbolVendor::FindPlugin (const lldb::ModuleSP &module_sp, lldb_private::Stream *feedback_strm)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000036{
Greg Clayton7b0992d2013-04-18 22:45:39 +000037 std::unique_ptr<SymbolVendor> instance_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000038 //----------------------------------------------------------------------
39 // We currently only have one debug symbol parser...
40 //----------------------------------------------------------------------
41 SymbolVendorCreateInstance create_callback;
Greg Claytonc7bece562013-01-25 18:06:21 +000042 for (size_t idx = 0; (create_callback = PluginManager::GetSymbolVendorCreateCallbackAtIndex(idx)) != NULL; ++idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000043 {
Greg Clayton136dff82012-12-14 02:15:00 +000044 instance_ap.reset(create_callback(module_sp, feedback_strm));
Chris Lattner30fdc8d2010-06-08 16:52:24 +000045
46 if (instance_ap.get())
47 {
48 // TODO: make sure this symbol vendor is what we want. We
49 // currently are just returning the first one we find, but
50 // we may want to call this function only when we have our
51 // main executable module and then give all symbol vendor
52 // plug-ins a chance to compete for who wins.
53 return instance_ap.release();
54 }
55 }
56 // The default implementation just tries to create debug information using the
57 // file representation for the module.
Greg Claytone72dfb32012-02-24 01:59:29 +000058 instance_ap.reset(new SymbolVendor(module_sp));
Chris Lattner30fdc8d2010-06-08 16:52:24 +000059 if (instance_ap.get())
Greg Clayton762f7132011-09-18 18:59:15 +000060 {
Greg Claytone72dfb32012-02-24 01:59:29 +000061 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Clayton762f7132011-09-18 18:59:15 +000062 if (objfile)
Greg Claytone1cd1be2012-01-29 20:56:30 +000063 instance_ap->AddSymbolFileRepresentation(objfile->shared_from_this());
Greg Clayton762f7132011-09-18 18:59:15 +000064 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +000065 return instance_ap.release();
66}
67
68//----------------------------------------------------------------------
69// SymbolVendor constructor
70//----------------------------------------------------------------------
Greg Claytone72dfb32012-02-24 01:59:29 +000071SymbolVendor::SymbolVendor(const lldb::ModuleSP &module_sp) :
72 ModuleChild (module_sp),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000073 m_type_list(),
74 m_compile_units(),
75 m_sym_file_ap()
76{
Chris Lattner30fdc8d2010-06-08 16:52:24 +000077}
78
79//----------------------------------------------------------------------
80// Destructor
81//----------------------------------------------------------------------
82SymbolVendor::~SymbolVendor()
83{
84}
85
86//----------------------------------------------------------------------
87// Add a represantion given an object file.
88//----------------------------------------------------------------------
89void
Jim Ingham7d1c1152011-12-06 01:07:22 +000090SymbolVendor::AddSymbolFileRepresentation(const ObjectFileSP &objfile_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000091{
Greg Claytona1743492012-03-13 23:14:29 +000092 ModuleSP module_sp(GetModule());
93 if (module_sp)
Greg Clayton762f7132011-09-18 18:59:15 +000094 {
Greg Claytona1743492012-03-13 23:14:29 +000095 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
96 if (objfile_sp)
97 {
98 m_objfile_sp = objfile_sp;
99 m_sym_file_ap.reset(SymbolFile::FindPlugin(objfile_sp.get()));
100 }
Greg Clayton762f7132011-09-18 18:59:15 +0000101 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000102}
103
104bool
Greg Claytonc7bece562013-01-25 18:06:21 +0000105SymbolVendor::SetCompileUnitAtIndex (size_t idx, const CompUnitSP &cu_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000106{
Greg Claytona1743492012-03-13 23:14:29 +0000107 ModuleSP module_sp(GetModule());
108 if (module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000109 {
Greg Claytona1743492012-03-13 23:14:29 +0000110 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
Greg Claytonc7bece562013-01-25 18:06:21 +0000111 const size_t num_compile_units = GetNumCompileUnits();
Greg Claytona1743492012-03-13 23:14:29 +0000112 if (idx < num_compile_units)
113 {
114 // Fire off an assertion if this compile unit already exists for now.
115 // The partial parsing should take care of only setting the compile
116 // unit once, so if this assertion fails, we need to make sure that
117 // we don't have a race condition, or have a second parse of the same
118 // compile unit.
119 assert(m_compile_units[idx].get() == NULL);
Greg Clayton53eb1c22012-04-02 22:59:12 +0000120 m_compile_units[idx] = cu_sp;
Greg Claytona1743492012-03-13 23:14:29 +0000121 return true;
122 }
Greg Clayton53eb1c22012-04-02 22:59:12 +0000123 else
124 {
125 // This should NOT happen, and if it does, we want to crash and know
126 // about it
127 assert (idx < num_compile_units);
128 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000129 }
130 return false;
131}
132
Greg Claytonc7bece562013-01-25 18:06:21 +0000133size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000134SymbolVendor::GetNumCompileUnits()
135{
Greg Claytona1743492012-03-13 23:14:29 +0000136 ModuleSP module_sp(GetModule());
137 if (module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000138 {
Greg Claytona1743492012-03-13 23:14:29 +0000139 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
140 if (m_compile_units.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000141 {
Greg Claytona1743492012-03-13 23:14:29 +0000142 if (m_sym_file_ap.get())
143 {
144 // Resize our array of compile unit shared pointers -- which will
145 // each remain NULL until someone asks for the actual compile unit
146 // information. When this happens, the symbol file will be asked
147 // to parse this compile unit information.
148 m_compile_units.resize(m_sym_file_ap->GetNumCompileUnits());
149 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000150 }
151 }
152 return m_compile_units.size();
153}
154
Greg Clayton1f746072012-08-29 21:13:06 +0000155lldb::LanguageType
156SymbolVendor::ParseCompileUnitLanguage (const SymbolContext& sc)
157{
158 ModuleSP module_sp(GetModule());
159 if (module_sp)
160 {
161 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
162 if (m_sym_file_ap.get())
163 return m_sym_file_ap->ParseCompileUnitLanguage(sc);
164 }
165 return eLanguageTypeUnknown;
166}
167
168
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000169size_t
170SymbolVendor::ParseCompileUnitFunctions (const SymbolContext &sc)
171{
Greg Claytona1743492012-03-13 23:14:29 +0000172 ModuleSP module_sp(GetModule());
173 if (module_sp)
174 {
175 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
176 if (m_sym_file_ap.get())
177 return m_sym_file_ap->ParseCompileUnitFunctions(sc);
178 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000179 return 0;
180}
181
182bool
183SymbolVendor::ParseCompileUnitLineTable (const SymbolContext &sc)
184{
Greg Claytona1743492012-03-13 23:14:29 +0000185 ModuleSP module_sp(GetModule());
186 if (module_sp)
187 {
188 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
189 if (m_sym_file_ap.get())
190 return m_sym_file_ap->ParseCompileUnitLineTable(sc);
191 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000192 return false;
193}
194
195bool
196SymbolVendor::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files)
197{
Greg Claytona1743492012-03-13 23:14:29 +0000198 ModuleSP module_sp(GetModule());
199 if (module_sp)
200 {
201 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
202 if (m_sym_file_ap.get())
203 return m_sym_file_ap->ParseCompileUnitSupportFiles(sc, support_files);
204 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000205 return false;
206}
207
208size_t
209SymbolVendor::ParseFunctionBlocks (const SymbolContext &sc)
210{
Greg Claytona1743492012-03-13 23:14:29 +0000211 ModuleSP module_sp(GetModule());
212 if (module_sp)
213 {
214 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
215 if (m_sym_file_ap.get())
216 return m_sym_file_ap->ParseFunctionBlocks(sc);
217 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000218 return 0;
219}
220
221size_t
222SymbolVendor::ParseTypes (const SymbolContext &sc)
223{
Greg Claytona1743492012-03-13 23:14:29 +0000224 ModuleSP module_sp(GetModule());
225 if (module_sp)
226 {
227 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
228 if (m_sym_file_ap.get())
229 return m_sym_file_ap->ParseTypes(sc);
230 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000231 return 0;
232}
233
234size_t
235SymbolVendor::ParseVariablesForContext (const SymbolContext& sc)
236{
Greg Claytona1743492012-03-13 23:14:29 +0000237 ModuleSP module_sp(GetModule());
238 if (module_sp)
239 {
240 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
241 if (m_sym_file_ap.get())
242 return m_sym_file_ap->ParseVariablesForContext(sc);
243 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000244 return 0;
245}
246
247Type*
248SymbolVendor::ResolveTypeUID(lldb::user_id_t type_uid)
249{
Greg Claytona1743492012-03-13 23:14:29 +0000250 ModuleSP module_sp(GetModule());
251 if (module_sp)
252 {
253 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
254 if (m_sym_file_ap.get())
255 return m_sym_file_ap->ResolveTypeUID(type_uid);
256 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000257 return NULL;
258}
259
260
261uint32_t
262SymbolVendor::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
263{
Greg Claytona1743492012-03-13 23:14:29 +0000264 ModuleSP module_sp(GetModule());
265 if (module_sp)
266 {
267 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
268 if (m_sym_file_ap.get())
269 return m_sym_file_ap->ResolveSymbolContext(so_addr, resolve_scope, sc);
270 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000271 return 0;
272}
273
274uint32_t
275SymbolVendor::ResolveSymbolContext (const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
276{
Greg Claytona1743492012-03-13 23:14:29 +0000277 ModuleSP module_sp(GetModule());
278 if (module_sp)
279 {
280 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
281 if (m_sym_file_ap.get())
282 return m_sym_file_ap->ResolveSymbolContext(file_spec, line, check_inlines, resolve_scope, sc_list);
283 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000284 return 0;
285}
286
Greg Claytonc7bece562013-01-25 18:06:21 +0000287size_t
288SymbolVendor::FindGlobalVariables (const ConstString &name, const ClangNamespaceDecl *namespace_decl, bool append, size_t max_matches, VariableList& variables)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000289{
Greg Claytona1743492012-03-13 23:14:29 +0000290 ModuleSP module_sp(GetModule());
291 if (module_sp)
292 {
293 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
294 if (m_sym_file_ap.get())
295 return m_sym_file_ap->FindGlobalVariables(name, namespace_decl, append, max_matches, variables);
296 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000297 return 0;
298}
299
Greg Claytonc7bece562013-01-25 18:06:21 +0000300size_t
301SymbolVendor::FindGlobalVariables (const RegularExpression& regex, bool append, size_t max_matches, VariableList& variables)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000302{
Greg Claytona1743492012-03-13 23:14:29 +0000303 ModuleSP module_sp(GetModule());
304 if (module_sp)
305 {
306 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
307 if (m_sym_file_ap.get())
308 return m_sym_file_ap->FindGlobalVariables(regex, append, max_matches, variables);
309 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000310 return 0;
311}
312
Greg Claytonc7bece562013-01-25 18:06:21 +0000313size_t
Sean Callanan9df05fb2012-02-10 22:52:19 +0000314SymbolVendor::FindFunctions(const ConstString &name, const ClangNamespaceDecl *namespace_decl, uint32_t name_type_mask, bool include_inlines, bool append, SymbolContextList& sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000315{
Greg Claytona1743492012-03-13 23:14:29 +0000316 ModuleSP module_sp(GetModule());
317 if (module_sp)
318 {
319 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
320 if (m_sym_file_ap.get())
321 return m_sym_file_ap->FindFunctions(name, namespace_decl, name_type_mask, include_inlines, append, sc_list);
322 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000323 return 0;
324}
325
Greg Claytonc7bece562013-01-25 18:06:21 +0000326size_t
Sean Callanan9df05fb2012-02-10 22:52:19 +0000327SymbolVendor::FindFunctions(const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000328{
Greg Claytona1743492012-03-13 23:14:29 +0000329 ModuleSP module_sp(GetModule());
330 if (module_sp)
331 {
332 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
333 if (m_sym_file_ap.get())
334 return m_sym_file_ap->FindFunctions(regex, include_inlines, append, sc_list);
335 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000336 return 0;
337}
338
339
Greg Claytonc7bece562013-01-25 18:06:21 +0000340size_t
341SymbolVendor::FindTypes (const SymbolContext& sc, const ConstString &name, const ClangNamespaceDecl *namespace_decl, bool append, size_t max_matches, TypeList& types)
Greg Claytonb0b9fe62010-08-03 00:35:52 +0000342{
Greg Claytona1743492012-03-13 23:14:29 +0000343 ModuleSP module_sp(GetModule());
344 if (module_sp)
345 {
346 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
347 if (m_sym_file_ap.get())
348 return m_sym_file_ap->FindTypes(sc, name, namespace_decl, append, max_matches, types);
349 }
Greg Claytonb0b9fe62010-08-03 00:35:52 +0000350 if (!append)
351 types.Clear();
352 return 0;
353}
Greg Clayton526e5af2010-11-13 03:52:47 +0000354
Greg Claytonf02500c2013-06-18 22:51:05 +0000355size_t
356SymbolVendor::GetTypes (SymbolContextScope *sc_scope,
357 uint32_t type_mask,
358 lldb_private::TypeList &type_list)
359{
360 ModuleSP module_sp(GetModule());
361 if (module_sp)
362 {
363 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
364 if (m_sym_file_ap.get())
365 return m_sym_file_ap->GetTypes (sc_scope, type_mask, type_list);
366 }
367 return 0;
368}
369
Greg Clayton526e5af2010-11-13 03:52:47 +0000370ClangNamespaceDecl
Sean Callanan213fdb82011-10-13 01:49:10 +0000371SymbolVendor::FindNamespace(const SymbolContext& sc, const ConstString &name, const ClangNamespaceDecl *parent_namespace_decl)
Greg Clayton526e5af2010-11-13 03:52:47 +0000372{
Greg Clayton526e5af2010-11-13 03:52:47 +0000373 ClangNamespaceDecl namespace_decl;
Greg Claytona1743492012-03-13 23:14:29 +0000374 ModuleSP module_sp(GetModule());
375 if (module_sp)
376 {
377 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
378 if (m_sym_file_ap.get())
379 namespace_decl = m_sym_file_ap->FindNamespace (sc, name, parent_namespace_decl);
380 }
Greg Clayton526e5af2010-11-13 03:52:47 +0000381 return namespace_decl;
382}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000383
384void
385SymbolVendor::Dump(Stream *s)
386{
Greg Claytona1743492012-03-13 23:14:29 +0000387 ModuleSP module_sp(GetModule());
388 if (module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000389 {
Greg Claytona1743492012-03-13 23:14:29 +0000390 bool show_context = false;
391
392 s->Printf("%p: ", this);
393 s->Indent();
394 s->PutCString("SymbolVendor");
395 if (m_sym_file_ap.get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000396 {
Greg Claytona1743492012-03-13 23:14:29 +0000397 ObjectFile *objfile = m_sym_file_ap->GetObjectFile();
398 if (objfile)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000399 {
Greg Claytona1743492012-03-13 23:14:29 +0000400 const FileSpec &objfile_file_spec = objfile->GetFileSpec();
401 if (objfile_file_spec)
402 {
403 s->PutCString(" (");
404 objfile_file_spec.Dump(s);
405 s->PutChar(')');
406 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000407 }
408 }
Greg Claytona1743492012-03-13 23:14:29 +0000409 s->EOL();
410 s->IndentMore();
411 m_type_list.Dump(s, show_context);
412
413 CompileUnitConstIter cu_pos, cu_end;
414 cu_end = m_compile_units.end();
415 for (cu_pos = m_compile_units.begin(); cu_pos != cu_end; ++cu_pos)
416 {
417 // We currently only dump the compile units that have been parsed
418 if (cu_pos->get())
419 (*cu_pos)->Dump(s, show_context);
420 }
421
422 s->IndentLess();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000423 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000424}
425
426CompUnitSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000427SymbolVendor::GetCompileUnitAtIndex(size_t idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000428{
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000429 CompUnitSP cu_sp;
Greg Claytona1743492012-03-13 23:14:29 +0000430 ModuleSP module_sp(GetModule());
431 if (module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000432 {
Greg Claytonc7bece562013-01-25 18:06:21 +0000433 const size_t num_compile_units = GetNumCompileUnits();
Greg Claytona1743492012-03-13 23:14:29 +0000434 if (idx < num_compile_units)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000435 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000436 cu_sp = m_compile_units[idx];
Greg Claytona1743492012-03-13 23:14:29 +0000437 if (cu_sp.get() == NULL)
438 {
439 m_compile_units[idx] = m_sym_file_ap->ParseCompileUnitAtIndex(idx);
440 cu_sp = m_compile_units[idx];
441 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000442 }
443 }
444 return cu_sp;
445}
446
447
448//------------------------------------------------------------------
449// PluginInterface protocol
450//------------------------------------------------------------------
Greg Clayton57abc5d2013-05-10 21:47:16 +0000451lldb_private::ConstString
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000452SymbolVendor::GetPluginName()
453{
Greg Clayton57abc5d2013-05-10 21:47:16 +0000454 static ConstString g_name("vendor-default");
455 return g_name;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000456}
457
458uint32_t
459SymbolVendor::GetPluginVersion()
460{
461 return 1;
462}
463