1 //===-- SymbolVendor.mm -----------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Symbol/SymbolVendor.h"
14 // Other libraries and framework includes
16 #include "lldb/Core/Module.h"
17 #include "lldb/Core/PluginManager.h"
18 #include "lldb/Core/Stream.h"
19 #include "lldb/Symbol/CompileUnit.h"
20 #include "lldb/Symbol/ObjectFile.h"
21 #include "lldb/Symbol/SymbolFile.h"
24 using namespace lldb_private;
27 //----------------------------------------------------------------------
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 //----------------------------------------------------------------------
35 SymbolVendor::FindPlugin (const lldb::ModuleSP &module_sp, lldb_private::Stream *feedback_strm)
37 std::unique_ptr<SymbolVendor> instance_ap;
38 SymbolVendorCreateInstance create_callback;
40 for (size_t idx = 0; (create_callback = PluginManager::GetSymbolVendorCreateCallbackAtIndex(idx)) != nullptr; ++idx)
42 instance_ap.reset(create_callback(module_sp, feedback_strm));
44 if (instance_ap.get())
46 return instance_ap.release();
49 // The default implementation just tries to create debug information using the
50 // file representation for the module.
51 instance_ap.reset(new SymbolVendor(module_sp));
52 if (instance_ap.get())
54 ObjectFile *objfile = module_sp->GetObjectFile();
56 instance_ap->AddSymbolFileRepresentation(objfile->shared_from_this());
58 return instance_ap.release();
61 //----------------------------------------------------------------------
62 // SymbolVendor constructor
63 //----------------------------------------------------------------------
64 SymbolVendor::SymbolVendor(const lldb::ModuleSP &module_sp) :
65 ModuleChild (module_sp),
72 //----------------------------------------------------------------------
74 //----------------------------------------------------------------------
75 SymbolVendor::~SymbolVendor()
79 //----------------------------------------------------------------------
80 // Add a representation given an object file.
81 //----------------------------------------------------------------------
83 SymbolVendor::AddSymbolFileRepresentation(const ObjectFileSP &objfile_sp)
85 ModuleSP module_sp(GetModule());
88 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
91 m_objfile_sp = objfile_sp;
92 m_sym_file_ap.reset(SymbolFile::FindPlugin(objfile_sp.get()));
98 SymbolVendor::SetCompileUnitAtIndex (size_t idx, const CompUnitSP &cu_sp)
100 ModuleSP module_sp(GetModule());
103 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
104 const size_t num_compile_units = GetNumCompileUnits();
105 if (idx < num_compile_units)
107 // Fire off an assertion if this compile unit already exists for now.
108 // The partial parsing should take care of only setting the compile
109 // unit once, so if this assertion fails, we need to make sure that
110 // we don't have a race condition, or have a second parse of the same
112 assert(m_compile_units[idx].get() == nullptr);
113 m_compile_units[idx] = cu_sp;
118 // This should NOT happen, and if it does, we want to crash and know
120 assert (idx < num_compile_units);
127 SymbolVendor::GetNumCompileUnits()
129 ModuleSP module_sp(GetModule());
132 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
133 if (m_compile_units.empty())
135 if (m_sym_file_ap.get())
137 // Resize our array of compile unit shared pointers -- which will
138 // each remain NULL until someone asks for the actual compile unit
139 // information. When this happens, the symbol file will be asked
140 // to parse this compile unit information.
141 m_compile_units.resize(m_sym_file_ap->GetNumCompileUnits());
145 return m_compile_units.size();
149 SymbolVendor::ParseCompileUnitLanguage (const SymbolContext& sc)
151 ModuleSP module_sp(GetModule());
154 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
155 if (m_sym_file_ap.get())
156 return m_sym_file_ap->ParseCompileUnitLanguage(sc);
158 return eLanguageTypeUnknown;
163 SymbolVendor::ParseCompileUnitFunctions (const SymbolContext &sc)
165 ModuleSP module_sp(GetModule());
168 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
169 if (m_sym_file_ap.get())
170 return m_sym_file_ap->ParseCompileUnitFunctions(sc);
176 SymbolVendor::ParseCompileUnitLineTable (const SymbolContext &sc)
178 ModuleSP module_sp(GetModule());
181 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
182 if (m_sym_file_ap.get())
183 return m_sym_file_ap->ParseCompileUnitLineTable(sc);
189 SymbolVendor::ParseCompileUnitDebugMacros (const SymbolContext &sc)
191 ModuleSP module_sp(GetModule());
194 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
195 if (m_sym_file_ap.get())
196 return m_sym_file_ap->ParseCompileUnitDebugMacros(sc);
201 SymbolVendor::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files)
203 ModuleSP module_sp(GetModule());
206 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
207 if (m_sym_file_ap.get())
208 return m_sym_file_ap->ParseCompileUnitSupportFiles(sc, support_files);
214 SymbolVendor::ParseImportedModules (const SymbolContext &sc,
215 std::vector<ConstString> &imported_modules)
217 ModuleSP module_sp(GetModule());
220 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
221 if (m_sym_file_ap.get())
222 return m_sym_file_ap->ParseImportedModules(sc, imported_modules);
229 SymbolVendor::ParseFunctionBlocks (const SymbolContext &sc)
231 ModuleSP module_sp(GetModule());
234 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
235 if (m_sym_file_ap.get())
236 return m_sym_file_ap->ParseFunctionBlocks(sc);
242 SymbolVendor::ParseTypes (const SymbolContext &sc)
244 ModuleSP module_sp(GetModule());
247 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
248 if (m_sym_file_ap.get())
249 return m_sym_file_ap->ParseTypes(sc);
255 SymbolVendor::ParseVariablesForContext (const SymbolContext& sc)
257 ModuleSP module_sp(GetModule());
260 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
261 if (m_sym_file_ap.get())
262 return m_sym_file_ap->ParseVariablesForContext(sc);
268 SymbolVendor::ResolveTypeUID(lldb::user_id_t type_uid)
270 ModuleSP module_sp(GetModule());
273 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
274 if (m_sym_file_ap.get())
275 return m_sym_file_ap->ResolveTypeUID(type_uid);
282 SymbolVendor::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
284 ModuleSP module_sp(GetModule());
287 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
288 if (m_sym_file_ap.get())
289 return m_sym_file_ap->ResolveSymbolContext(so_addr, resolve_scope, sc);
295 SymbolVendor::ResolveSymbolContext (const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
297 ModuleSP module_sp(GetModule());
300 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
301 if (m_sym_file_ap.get())
302 return m_sym_file_ap->ResolveSymbolContext(file_spec, line, check_inlines, resolve_scope, sc_list);
308 SymbolVendor::FindGlobalVariables (const ConstString &name, const CompilerDeclContext *parent_decl_ctx, bool append, size_t max_matches, VariableList& variables)
310 ModuleSP module_sp(GetModule());
313 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
314 if (m_sym_file_ap.get())
315 return m_sym_file_ap->FindGlobalVariables(name, parent_decl_ctx, append, max_matches, variables);
321 SymbolVendor::FindGlobalVariables (const RegularExpression& regex, bool append, size_t max_matches, VariableList& variables)
323 ModuleSP module_sp(GetModule());
326 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
327 if (m_sym_file_ap.get())
328 return m_sym_file_ap->FindGlobalVariables(regex, append, max_matches, variables);
334 SymbolVendor::FindFunctions(const ConstString &name, const CompilerDeclContext *parent_decl_ctx, uint32_t name_type_mask, bool include_inlines, bool append, SymbolContextList& sc_list)
336 ModuleSP module_sp(GetModule());
339 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
340 if (m_sym_file_ap.get())
341 return m_sym_file_ap->FindFunctions(name, parent_decl_ctx, name_type_mask, include_inlines, append, sc_list);
347 SymbolVendor::FindFunctions(const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list)
349 ModuleSP module_sp(GetModule());
352 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
353 if (m_sym_file_ap.get())
354 return m_sym_file_ap->FindFunctions(regex, include_inlines, append, sc_list);
361 SymbolVendor::FindTypes (const SymbolContext& sc, const ConstString &name, const CompilerDeclContext *parent_decl_ctx, bool append, size_t max_matches, TypeMap& types)
363 ModuleSP module_sp(GetModule());
366 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
367 if (m_sym_file_ap.get())
368 return m_sym_file_ap->FindTypes(sc, name, parent_decl_ctx, append, max_matches, types);
376 SymbolVendor::FindTypes (const std::vector<CompilerContext> &context, bool append, TypeMap& types)
378 ModuleSP module_sp(GetModule());
381 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
382 if (m_sym_file_ap.get())
383 return m_sym_file_ap->FindTypes(context, append, types);
391 SymbolVendor::GetTypes (SymbolContextScope *sc_scope,
393 lldb_private::TypeList &type_list)
395 ModuleSP module_sp(GetModule());
398 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
399 if (m_sym_file_ap.get())
400 return m_sym_file_ap->GetTypes (sc_scope, type_mask, type_list);
406 SymbolVendor::FindNamespace(const SymbolContext& sc, const ConstString &name, const CompilerDeclContext *parent_decl_ctx)
408 CompilerDeclContext namespace_decl_ctx;
409 ModuleSP module_sp(GetModule());
412 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
413 if (m_sym_file_ap.get())
414 namespace_decl_ctx = m_sym_file_ap->FindNamespace (sc, name, parent_decl_ctx);
416 return namespace_decl_ctx;
420 SymbolVendor::Dump(Stream *s)
422 ModuleSP module_sp(GetModule());
425 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
427 bool show_context = false;
429 s->Printf("%p: ", static_cast<void*>(this));
431 s->PutCString("SymbolVendor");
432 if (m_sym_file_ap.get())
434 ObjectFile *objfile = m_sym_file_ap->GetObjectFile();
437 const FileSpec &objfile_file_spec = objfile->GetFileSpec();
438 if (objfile_file_spec)
441 objfile_file_spec.Dump(s);
448 m_type_list.Dump(s, show_context);
450 CompileUnitConstIter cu_pos, cu_end;
451 cu_end = m_compile_units.end();
452 for (cu_pos = m_compile_units.begin(); cu_pos != cu_end; ++cu_pos)
454 // We currently only dump the compile units that have been parsed
456 (*cu_pos)->Dump(s, show_context);
464 SymbolVendor::GetCompileUnitAtIndex(size_t idx)
467 ModuleSP module_sp(GetModule());
470 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
471 const size_t num_compile_units = GetNumCompileUnits();
472 if (idx < num_compile_units)
474 cu_sp = m_compile_units[idx];
475 if (cu_sp.get() == nullptr)
477 m_compile_units[idx] = m_sym_file_ap->ParseCompileUnitAtIndex(idx);
478 cu_sp = m_compile_units[idx];
486 SymbolVendor::GetMainFileSpec() const
488 if (m_sym_file_ap.get())
490 const ObjectFile *symfile_objfile = m_sym_file_ap->GetObjectFile();
492 return symfile_objfile->GetFileSpec();
499 SymbolVendor::GetSymtab ()
501 ModuleSP module_sp(GetModule());
504 ObjectFile *objfile = module_sp->GetObjectFile();
507 // Get symbol table from unified section list.
508 return objfile->GetSymtab ();
515 SymbolVendor::ClearSymtab()
517 ModuleSP module_sp(GetModule());
520 ObjectFile *objfile = module_sp->GetObjectFile();
523 // Clear symbol table from unified section list.
524 objfile->ClearSymtab ();
530 SymbolVendor::SectionFileAddressesChanged ()
532 ModuleSP module_sp(GetModule());
535 ObjectFile *module_objfile = module_sp->GetObjectFile ();
536 if (m_sym_file_ap.get())
538 ObjectFile *symfile_objfile = m_sym_file_ap->GetObjectFile ();
539 if (symfile_objfile != module_objfile)
540 symfile_objfile->SectionFileAddressesChanged ();
542 Symtab *symtab = GetSymtab ();
545 symtab->SectionFileAddressesChanged ();
550 //------------------------------------------------------------------
551 // PluginInterface protocol
552 //------------------------------------------------------------------
553 lldb_private::ConstString
554 SymbolVendor::GetPluginName()
556 static ConstString g_name("vendor-default");
561 SymbolVendor::GetPluginVersion()