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)) != NULL; ++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 represention 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() == NULL);
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::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files)
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->ParseCompileUnitSupportFiles(sc, support_files);
202 SymbolVendor::ParseFunctionBlocks (const SymbolContext &sc)
204 ModuleSP module_sp(GetModule());
207 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
208 if (m_sym_file_ap.get())
209 return m_sym_file_ap->ParseFunctionBlocks(sc);
215 SymbolVendor::ParseTypes (const SymbolContext &sc)
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->ParseTypes(sc);
228 SymbolVendor::ParseVariablesForContext (const SymbolContext& sc)
230 ModuleSP module_sp(GetModule());
233 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
234 if (m_sym_file_ap.get())
235 return m_sym_file_ap->ParseVariablesForContext(sc);
241 SymbolVendor::ResolveTypeUID(lldb::user_id_t type_uid)
243 ModuleSP module_sp(GetModule());
246 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
247 if (m_sym_file_ap.get())
248 return m_sym_file_ap->ResolveTypeUID(type_uid);
255 SymbolVendor::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, 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->ResolveSymbolContext(so_addr, resolve_scope, sc);
268 SymbolVendor::ResolveSymbolContext (const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
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->ResolveSymbolContext(file_spec, line, check_inlines, resolve_scope, sc_list);
281 SymbolVendor::FindGlobalVariables (const ConstString &name, const ClangNamespaceDecl *namespace_decl, bool append, size_t max_matches, VariableList& variables)
283 ModuleSP module_sp(GetModule());
286 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
287 if (m_sym_file_ap.get())
288 return m_sym_file_ap->FindGlobalVariables(name, namespace_decl, append, max_matches, variables);
294 SymbolVendor::FindGlobalVariables (const RegularExpression& regex, bool append, size_t max_matches, VariableList& variables)
296 ModuleSP module_sp(GetModule());
299 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
300 if (m_sym_file_ap.get())
301 return m_sym_file_ap->FindGlobalVariables(regex, append, max_matches, variables);
307 SymbolVendor::FindFunctions(const ConstString &name, const ClangNamespaceDecl *namespace_decl, uint32_t name_type_mask, bool include_inlines, bool append, SymbolContextList& sc_list)
309 ModuleSP module_sp(GetModule());
312 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
313 if (m_sym_file_ap.get())
314 return m_sym_file_ap->FindFunctions(name, namespace_decl, name_type_mask, include_inlines, append, sc_list);
320 SymbolVendor::FindFunctions(const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list)
322 ModuleSP module_sp(GetModule());
325 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
326 if (m_sym_file_ap.get())
327 return m_sym_file_ap->FindFunctions(regex, include_inlines, append, sc_list);
334 SymbolVendor::FindTypes (const SymbolContext& sc, const ConstString &name, const ClangNamespaceDecl *namespace_decl, bool append, size_t max_matches, TypeList& types)
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->FindTypes(sc, name, namespace_decl, append, max_matches, types);
349 SymbolVendor::GetTypes (SymbolContextScope *sc_scope,
351 lldb_private::TypeList &type_list)
353 ModuleSP module_sp(GetModule());
356 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
357 if (m_sym_file_ap.get())
358 return m_sym_file_ap->GetTypes (sc_scope, type_mask, type_list);
364 SymbolVendor::FindNamespace(const SymbolContext& sc, const ConstString &name, const ClangNamespaceDecl *parent_namespace_decl)
366 ClangNamespaceDecl namespace_decl;
367 ModuleSP module_sp(GetModule());
370 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
371 if (m_sym_file_ap.get())
372 namespace_decl = m_sym_file_ap->FindNamespace (sc, name, parent_namespace_decl);
374 return namespace_decl;
378 SymbolVendor::Dump(Stream *s)
380 ModuleSP module_sp(GetModule());
383 bool show_context = false;
385 s->Printf("%p: ", this);
387 s->PutCString("SymbolVendor");
388 if (m_sym_file_ap.get())
390 ObjectFile *objfile = m_sym_file_ap->GetObjectFile();
393 const FileSpec &objfile_file_spec = objfile->GetFileSpec();
394 if (objfile_file_spec)
397 objfile_file_spec.Dump(s);
404 m_type_list.Dump(s, show_context);
406 CompileUnitConstIter cu_pos, cu_end;
407 cu_end = m_compile_units.end();
408 for (cu_pos = m_compile_units.begin(); cu_pos != cu_end; ++cu_pos)
410 // We currently only dump the compile units that have been parsed
412 (*cu_pos)->Dump(s, show_context);
420 SymbolVendor::GetCompileUnitAtIndex(size_t idx)
423 ModuleSP module_sp(GetModule());
426 const size_t num_compile_units = GetNumCompileUnits();
427 if (idx < num_compile_units)
429 cu_sp = m_compile_units[idx];
430 if (cu_sp.get() == NULL)
432 m_compile_units[idx] = m_sym_file_ap->ParseCompileUnitAtIndex(idx);
433 cu_sp = m_compile_units[idx];
441 SymbolVendor::GetSymtab ()
443 ModuleSP module_sp(GetModule());
446 ObjectFile *objfile = module_sp->GetObjectFile();
449 // Get symbol table from unified section list.
450 return objfile->GetSymtab ();
457 SymbolVendor::ClearSymtab()
459 ModuleSP module_sp(GetModule());
462 ObjectFile *objfile = module_sp->GetObjectFile();
465 // Clear symbol table from unified section list.
466 objfile->ClearSymtab ();
471 //------------------------------------------------------------------
472 // PluginInterface protocol
473 //------------------------------------------------------------------
474 lldb_private::ConstString
475 SymbolVendor::GetPluginName()
477 static ConstString g_name("vendor-default");
482 SymbolVendor::GetPluginVersion()