blob: a9badc15a5d60149bb20d48ba544a4dc370e48e2 [file] [log] [blame]
Alexander Shaposhnikov696bd632016-11-26 05:23:44 +00001//===-- SymbolVendor.cpp ----------------------------------------*- C++ -*-===//
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002//
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
Chris Lattner30fdc8d2010-06-08 16:52:24 +000012#include "lldb/Core/Module.h"
13#include "lldb/Core/PluginManager.h"
Greg Clayton1f746072012-08-29 21:13:06 +000014#include "lldb/Symbol/CompileUnit.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000015#include "lldb/Symbol/ObjectFile.h"
16#include "lldb/Symbol/SymbolFile.h"
Zachary Turnerbf9a7732017-02-02 21:39:50 +000017#include "lldb/Utility/Stream.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000018
19using namespace lldb;
20using namespace lldb_private;
21
Chris Lattner30fdc8d2010-06-08 16:52:24 +000022//----------------------------------------------------------------------
23// FindPlugin
24//
Adrian Prantl05097242018-04-30 16:49:04 +000025// Platforms can register a callback to use when creating symbol vendors to
26// allow for complex debug information file setups, and to also allow for
27// finding separate debug information files.
Chris Lattner30fdc8d2010-06-08 16:52:24 +000028//----------------------------------------------------------------------
Kate Stoneb9c1b512016-09-06 20:57:50 +000029SymbolVendor *SymbolVendor::FindPlugin(const lldb::ModuleSP &module_sp,
30 lldb_private::Stream *feedback_strm) {
31 std::unique_ptr<SymbolVendor> instance_ap;
32 SymbolVendorCreateInstance create_callback;
Michael Sartaina7499c92013-07-01 19:45:50 +000033
Kate Stoneb9c1b512016-09-06 20:57:50 +000034 for (size_t idx = 0;
35 (create_callback = PluginManager::GetSymbolVendorCreateCallbackAtIndex(
36 idx)) != nullptr;
37 ++idx) {
38 instance_ap.reset(create_callback(module_sp, feedback_strm));
Chris Lattner30fdc8d2010-06-08 16:52:24 +000039
Kate Stoneb9c1b512016-09-06 20:57:50 +000040 if (instance_ap.get()) {
41 return instance_ap.release();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000042 }
Kate Stoneb9c1b512016-09-06 20:57:50 +000043 }
Adrian Prantl05097242018-04-30 16:49:04 +000044 // The default implementation just tries to create debug information using
45 // the file representation for the module.
Kate Stoneb9c1b512016-09-06 20:57:50 +000046 instance_ap.reset(new SymbolVendor(module_sp));
47 if (instance_ap.get()) {
48 ObjectFile *objfile = module_sp->GetObjectFile();
49 if (objfile)
50 instance_ap->AddSymbolFileRepresentation(objfile->shared_from_this());
51 }
52 return instance_ap.release();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000053}
54
55//----------------------------------------------------------------------
56// SymbolVendor constructor
57//----------------------------------------------------------------------
Kate Stoneb9c1b512016-09-06 20:57:50 +000058SymbolVendor::SymbolVendor(const lldb::ModuleSP &module_sp)
59 : ModuleChild(module_sp), m_type_list(), m_compile_units(),
Aleksandr Urakov8cfb12b2018-11-30 06:56:37 +000060 m_sym_file_ap(), m_symtab() {}
Chris Lattner30fdc8d2010-06-08 16:52:24 +000061
62//----------------------------------------------------------------------
63// Destructor
64//----------------------------------------------------------------------
Kate Stoneb9c1b512016-09-06 20:57:50 +000065SymbolVendor::~SymbolVendor() {}
Chris Lattner30fdc8d2010-06-08 16:52:24 +000066
67//----------------------------------------------------------------------
Bruce Mitchenere171da52015-07-22 00:16:02 +000068// Add a representation given an object file.
Chris Lattner30fdc8d2010-06-08 16:52:24 +000069//----------------------------------------------------------------------
Kate Stoneb9c1b512016-09-06 20:57:50 +000070void SymbolVendor::AddSymbolFileRepresentation(const ObjectFileSP &objfile_sp) {
71 ModuleSP module_sp(GetModule());
72 if (module_sp) {
73 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
74 if (objfile_sp) {
75 m_objfile_sp = objfile_sp;
76 m_sym_file_ap.reset(SymbolFile::FindPlugin(objfile_sp.get()));
Greg Clayton762f7132011-09-18 18:59:15 +000077 }
Kate Stoneb9c1b512016-09-06 20:57:50 +000078 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +000079}
80
Kate Stoneb9c1b512016-09-06 20:57:50 +000081bool SymbolVendor::SetCompileUnitAtIndex(size_t idx, const CompUnitSP &cu_sp) {
82 ModuleSP module_sp(GetModule());
83 if (module_sp) {
84 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
85 const size_t num_compile_units = GetNumCompileUnits();
86 if (idx < num_compile_units) {
Adrian Prantl05097242018-04-30 16:49:04 +000087 // Fire off an assertion if this compile unit already exists for now. The
88 // partial parsing should take care of only setting the compile unit
89 // once, so if this assertion fails, we need to make sure that we don't
90 // have a race condition, or have a second parse of the same compile
91 // unit.
Kate Stoneb9c1b512016-09-06 20:57:50 +000092 assert(m_compile_units[idx].get() == nullptr);
93 m_compile_units[idx] = cu_sp;
94 return true;
95 } else {
96 // This should NOT happen, and if it does, we want to crash and know
97 // about it
98 assert(idx < num_compile_units);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000099 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000100 }
101 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000102}
103
Kate Stoneb9c1b512016-09-06 20:57:50 +0000104size_t SymbolVendor::GetNumCompileUnits() {
105 ModuleSP module_sp(GetModule());
106 if (module_sp) {
107 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
108 if (m_compile_units.empty()) {
109 if (m_sym_file_ap.get()) {
Adrian Prantl05097242018-04-30 16:49:04 +0000110 // Resize our array of compile unit shared pointers -- which will each
111 // remain NULL until someone asks for the actual compile unit
112 // information. When this happens, the symbol file will be asked to
113 // parse this compile unit information.
Kate Stoneb9c1b512016-09-06 20:57:50 +0000114 m_compile_units.resize(m_sym_file_ap->GetNumCompileUnits());
115 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000116 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000117 }
118 return m_compile_units.size();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000119}
120
Zachary Turner863f8c12019-01-11 18:03:20 +0000121lldb::LanguageType SymbolVendor::ParseLanguage(CompileUnit &comp_unit) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000122 ModuleSP module_sp(GetModule());
123 if (module_sp) {
124 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
125 if (m_sym_file_ap.get())
Zachary Turner863f8c12019-01-11 18:03:20 +0000126 return m_sym_file_ap->ParseLanguage(comp_unit);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000127 }
128 return eLanguageTypeUnknown;
Greg Clayton1f746072012-08-29 21:13:06 +0000129}
130
Zachary Turner863f8c12019-01-11 18:03:20 +0000131size_t SymbolVendor::ParseFunctions(CompileUnit &comp_unit) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000132 ModuleSP module_sp(GetModule());
133 if (module_sp) {
134 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
135 if (m_sym_file_ap.get())
Zachary Turner863f8c12019-01-11 18:03:20 +0000136 return m_sym_file_ap->ParseFunctions(comp_unit);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000137 }
138 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000139}
140
Zachary Turner863f8c12019-01-11 18:03:20 +0000141bool SymbolVendor::ParseLineTable(CompileUnit &comp_unit) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000142 ModuleSP module_sp(GetModule());
143 if (module_sp) {
144 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
145 if (m_sym_file_ap.get())
Zachary Turner863f8c12019-01-11 18:03:20 +0000146 return m_sym_file_ap->ParseLineTable(comp_unit);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000147 }
148 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000149}
150
Zachary Turner863f8c12019-01-11 18:03:20 +0000151bool SymbolVendor::ParseDebugMacros(CompileUnit &comp_unit) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000152 ModuleSP module_sp(GetModule());
153 if (module_sp) {
154 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
155 if (m_sym_file_ap.get())
Zachary Turner863f8c12019-01-11 18:03:20 +0000156 return m_sym_file_ap->ParseDebugMacros(comp_unit);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000157 }
158 return false;
Siva Chandrad8335e92015-12-16 00:22:08 +0000159}
Zachary Turner863f8c12019-01-11 18:03:20 +0000160bool SymbolVendor::ParseSupportFiles(CompileUnit &comp_unit,
161 FileSpecList &support_files) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000162 ModuleSP module_sp(GetModule());
163 if (module_sp) {
164 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
165 if (m_sym_file_ap.get())
Zachary Turner863f8c12019-01-11 18:03:20 +0000166 return m_sym_file_ap->ParseSupportFiles(comp_unit, support_files);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000167 }
168 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000169}
170
Zachary Turner863f8c12019-01-11 18:03:20 +0000171bool SymbolVendor::ParseIsOptimized(CompileUnit &comp_unit) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000172 ModuleSP module_sp(GetModule());
173 if (module_sp) {
174 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
175 if (m_sym_file_ap.get())
Zachary Turner863f8c12019-01-11 18:03:20 +0000176 return m_sym_file_ap->ParseIsOptimized(comp_unit);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000177 }
178 return false;
Greg Claytonad2b63c2016-07-05 23:01:20 +0000179}
180
Kate Stoneb9c1b512016-09-06 20:57:50 +0000181bool SymbolVendor::ParseImportedModules(
182 const SymbolContext &sc, std::vector<ConstString> &imported_modules) {
183 ModuleSP module_sp(GetModule());
184 if (module_sp) {
185 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
186 if (m_sym_file_ap.get())
187 return m_sym_file_ap->ParseImportedModules(sc, imported_modules);
188 }
189 return false;
Sean Callananf0c5aeb2015-04-20 16:31:29 +0000190}
191
Zachary Turnerffc1b8f2019-01-14 22:40:41 +0000192size_t SymbolVendor::ParseBlocksRecursive(Function &func) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000193 ModuleSP module_sp(GetModule());
194 if (module_sp) {
195 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
196 if (m_sym_file_ap.get())
Zachary Turnerffc1b8f2019-01-14 22:40:41 +0000197 return m_sym_file_ap->ParseBlocksRecursive(func);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000198 }
199 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000200}
201
Zachary Turner863f8c12019-01-11 18:03:20 +0000202size_t SymbolVendor::ParseTypes(CompileUnit &comp_unit) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000203 ModuleSP module_sp(GetModule());
204 if (module_sp) {
205 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
206 if (m_sym_file_ap.get())
Zachary Turner863f8c12019-01-11 18:03:20 +0000207 return m_sym_file_ap->ParseTypes(comp_unit);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000208 }
209 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000210}
211
Kate Stoneb9c1b512016-09-06 20:57:50 +0000212size_t SymbolVendor::ParseVariablesForContext(const SymbolContext &sc) {
213 ModuleSP module_sp(GetModule());
214 if (module_sp) {
215 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
216 if (m_sym_file_ap.get())
217 return m_sym_file_ap->ParseVariablesForContext(sc);
218 }
219 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000220}
221
Kate Stoneb9c1b512016-09-06 20:57:50 +0000222Type *SymbolVendor::ResolveTypeUID(lldb::user_id_t type_uid) {
223 ModuleSP module_sp(GetModule());
224 if (module_sp) {
225 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
226 if (m_sym_file_ap.get())
227 return m_sym_file_ap->ResolveTypeUID(type_uid);
228 }
229 return nullptr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000230}
231
Kate Stoneb9c1b512016-09-06 20:57:50 +0000232uint32_t SymbolVendor::ResolveSymbolContext(const Address &so_addr,
Zachary Turner991e4452018-10-25 20:45:19 +0000233 SymbolContextItem resolve_scope,
Kate Stoneb9c1b512016-09-06 20:57:50 +0000234 SymbolContext &sc) {
235 ModuleSP module_sp(GetModule());
236 if (module_sp) {
237 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
238 if (m_sym_file_ap.get())
239 return m_sym_file_ap->ResolveSymbolContext(so_addr, resolve_scope, sc);
240 }
241 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000242}
243
Kate Stoneb9c1b512016-09-06 20:57:50 +0000244uint32_t SymbolVendor::ResolveSymbolContext(const FileSpec &file_spec,
245 uint32_t line, bool check_inlines,
Zachary Turner991e4452018-10-25 20:45:19 +0000246 SymbolContextItem resolve_scope,
Kate Stoneb9c1b512016-09-06 20:57:50 +0000247 SymbolContextList &sc_list) {
248 ModuleSP module_sp(GetModule());
249 if (module_sp) {
250 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
251 if (m_sym_file_ap.get())
252 return m_sym_file_ap->ResolveSymbolContext(file_spec, line, check_inlines,
253 resolve_scope, sc_list);
254 }
255 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000256}
257
Pavel Labath34cda142018-05-31 09:46:26 +0000258size_t
259SymbolVendor::FindGlobalVariables(const ConstString &name,
260 const CompilerDeclContext *parent_decl_ctx,
261 size_t max_matches, VariableList &variables) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000262 ModuleSP module_sp(GetModule());
263 if (module_sp) {
264 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
265 if (m_sym_file_ap.get())
Pavel Labath34cda142018-05-31 09:46:26 +0000266 return m_sym_file_ap->FindGlobalVariables(name, parent_decl_ctx,
Kate Stoneb9c1b512016-09-06 20:57:50 +0000267 max_matches, variables);
268 }
269 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000270}
271
Kate Stoneb9c1b512016-09-06 20:57:50 +0000272size_t SymbolVendor::FindGlobalVariables(const RegularExpression &regex,
Pavel Labath34cda142018-05-31 09:46:26 +0000273 size_t max_matches,
Kate Stoneb9c1b512016-09-06 20:57:50 +0000274 VariableList &variables) {
275 ModuleSP module_sp(GetModule());
276 if (module_sp) {
277 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
278 if (m_sym_file_ap.get())
Pavel Labath34cda142018-05-31 09:46:26 +0000279 return m_sym_file_ap->FindGlobalVariables(regex, max_matches, variables);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000280 }
281 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000282}
283
Kate Stoneb9c1b512016-09-06 20:57:50 +0000284size_t SymbolVendor::FindFunctions(const ConstString &name,
285 const CompilerDeclContext *parent_decl_ctx,
Zachary Turner117b1fa2018-10-25 20:45:40 +0000286 FunctionNameType name_type_mask,
Kate Stoneb9c1b512016-09-06 20:57:50 +0000287 bool include_inlines, bool append,
288 SymbolContextList &sc_list) {
289 ModuleSP module_sp(GetModule());
290 if (module_sp) {
291 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
292 if (m_sym_file_ap.get())
293 return m_sym_file_ap->FindFunctions(name, parent_decl_ctx, name_type_mask,
294 include_inlines, append, sc_list);
295 }
296 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000297}
298
Kate Stoneb9c1b512016-09-06 20:57:50 +0000299size_t SymbolVendor::FindFunctions(const RegularExpression &regex,
300 bool include_inlines, bool append,
301 SymbolContextList &sc_list) {
302 ModuleSP module_sp(GetModule());
303 if (module_sp) {
304 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
305 if (m_sym_file_ap.get())
306 return m_sym_file_ap->FindFunctions(regex, include_inlines, append,
307 sc_list);
308 }
309 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000310}
311
Kate Stoneb9c1b512016-09-06 20:57:50 +0000312size_t SymbolVendor::FindTypes(
Zachary Turner576495e2019-01-14 22:41:21 +0000313 const ConstString &name, const CompilerDeclContext *parent_decl_ctx,
314 bool append, size_t max_matches,
Kate Stoneb9c1b512016-09-06 20:57:50 +0000315 llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
316 TypeMap &types) {
317 ModuleSP module_sp(GetModule());
318 if (module_sp) {
319 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
320 if (m_sym_file_ap.get())
Zachary Turner576495e2019-01-14 22:41:21 +0000321 return m_sym_file_ap->FindTypes(name, parent_decl_ctx, append,
Kate Stoneb9c1b512016-09-06 20:57:50 +0000322 max_matches, searched_symbol_files,
323 types);
324 }
325 if (!append)
326 types.Clear();
327 return 0;
Greg Claytonb0b9fe62010-08-03 00:35:52 +0000328}
Greg Clayton526e5af2010-11-13 03:52:47 +0000329
Kate Stoneb9c1b512016-09-06 20:57:50 +0000330size_t SymbolVendor::FindTypes(const std::vector<CompilerContext> &context,
331 bool append, TypeMap &types) {
332 ModuleSP module_sp(GetModule());
333 if (module_sp) {
334 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
335 if (m_sym_file_ap.get())
336 return m_sym_file_ap->FindTypes(context, append, types);
337 }
338 if (!append)
339 types.Clear();
340 return 0;
Greg Claytone6b36cd2015-12-08 01:02:08 +0000341}
342
Zachary Turner117b1fa2018-10-25 20:45:40 +0000343size_t SymbolVendor::GetTypes(SymbolContextScope *sc_scope, TypeClass type_mask,
Kate Stoneb9c1b512016-09-06 20:57:50 +0000344 lldb_private::TypeList &type_list) {
345 ModuleSP module_sp(GetModule());
346 if (module_sp) {
347 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
348 if (m_sym_file_ap.get())
349 return m_sym_file_ap->GetTypes(sc_scope, type_mask, type_list);
350 }
351 return 0;
Greg Claytonf02500c2013-06-18 22:51:05 +0000352}
353
Greg Clayton99558cc42015-08-24 23:46:31 +0000354CompilerDeclContext
Zachary Turnerc0a246a2019-01-14 22:41:00 +0000355SymbolVendor::FindNamespace(const ConstString &name,
Kate Stoneb9c1b512016-09-06 20:57:50 +0000356 const CompilerDeclContext *parent_decl_ctx) {
357 CompilerDeclContext namespace_decl_ctx;
358 ModuleSP module_sp(GetModule());
359 if (module_sp) {
360 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
Ilia Ke912e3e2015-03-10 21:18:59 +0000361 if (m_sym_file_ap.get())
Zachary Turnerc0a246a2019-01-14 22:41:00 +0000362 namespace_decl_ctx = m_sym_file_ap->FindNamespace(name, parent_decl_ctx);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000363 }
364 return namespace_decl_ctx;
Ilia Ke912e3e2015-03-10 21:18:59 +0000365}
366
Kate Stoneb9c1b512016-09-06 20:57:50 +0000367void SymbolVendor::Dump(Stream *s) {
368 ModuleSP module_sp(GetModule());
369 if (module_sp) {
370 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
371
372 bool show_context = false;
373
374 s->Printf("%p: ", static_cast<void *>(this));
375 s->Indent();
376 s->PutCString("SymbolVendor");
377 if (m_sym_file_ap.get()) {
Pavel Labath1cf23e12019-01-11 11:17:51 +0000378 *s << " " << m_sym_file_ap->GetPluginName();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000379 ObjectFile *objfile = m_sym_file_ap->GetObjectFile();
380 if (objfile) {
381 const FileSpec &objfile_file_spec = objfile->GetFileSpec();
382 if (objfile_file_spec) {
383 s->PutCString(" (");
384 objfile_file_spec.Dump(s);
385 s->PutChar(')');
Michael Sartaina7499c92013-07-01 19:45:50 +0000386 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000387 }
Michael Sartaina7499c92013-07-01 19:45:50 +0000388 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000389 s->EOL();
Pavel Labath9337b412018-06-06 11:35:23 +0000390 if (m_sym_file_ap)
391 m_sym_file_ap->Dump(*s);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000392 s->IndentMore();
393 m_type_list.Dump(s, show_context);
394
395 CompileUnitConstIter cu_pos, cu_end;
396 cu_end = m_compile_units.end();
397 for (cu_pos = m_compile_units.begin(); cu_pos != cu_end; ++cu_pos) {
398 // We currently only dump the compile units that have been parsed
399 if (cu_pos->get())
400 (*cu_pos)->Dump(s, show_context);
401 }
402
Pavel Labath1cf23e12019-01-11 11:17:51 +0000403 if (Symtab *symtab = GetSymtab())
404 symtab->Dump(s, nullptr, eSortOrderNone);
405
Kate Stoneb9c1b512016-09-06 20:57:50 +0000406 s->IndentLess();
407 }
Michael Sartaina7499c92013-07-01 19:45:50 +0000408}
409
Kate Stoneb9c1b512016-09-06 20:57:50 +0000410CompUnitSP SymbolVendor::GetCompileUnitAtIndex(size_t idx) {
411 CompUnitSP cu_sp;
412 ModuleSP module_sp(GetModule());
413 if (module_sp) {
414 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
415 const size_t num_compile_units = GetNumCompileUnits();
416 if (idx < num_compile_units) {
417 cu_sp = m_compile_units[idx];
418 if (cu_sp.get() == nullptr) {
419 m_compile_units[idx] = m_sym_file_ap->ParseCompileUnitAtIndex(idx);
420 cu_sp = m_compile_units[idx];
421 }
Michael Sartaina7499c92013-07-01 19:45:50 +0000422 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000423 }
424 return cu_sp;
Michael Sartaina7499c92013-07-01 19:45:50 +0000425}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000426
Kate Stoneb9c1b512016-09-06 20:57:50 +0000427FileSpec SymbolVendor::GetMainFileSpec() const {
428 if (m_sym_file_ap.get()) {
429 const ObjectFile *symfile_objfile = m_sym_file_ap->GetObjectFile();
430 if (symfile_objfile)
431 return symfile_objfile->GetFileSpec();
432 }
433
434 return FileSpec();
435}
436
437Symtab *SymbolVendor::GetSymtab() {
438 ModuleSP module_sp(GetModule());
Aleksandr Urakov8cfb12b2018-11-30 06:56:37 +0000439 if (!module_sp)
440 return nullptr;
441
442 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
443
444 if (m_symtab)
445 return m_symtab;
446
447 ObjectFile *objfile = module_sp->GetObjectFile();
448 if (!objfile)
449 return nullptr;
450
451 m_symtab = objfile->GetSymtab();
452 if (m_symtab && m_sym_file_ap)
453 m_sym_file_ap->AddSymbols(*m_symtab);
454
455 return m_symtab;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000456}
457
458void SymbolVendor::ClearSymtab() {
459 ModuleSP module_sp(GetModule());
460 if (module_sp) {
461 ObjectFile *objfile = module_sp->GetObjectFile();
462 if (objfile) {
463 // Clear symbol table from unified section list.
464 objfile->ClearSymtab();
465 }
466 }
467}
468
469void SymbolVendor::SectionFileAddressesChanged() {
470 ModuleSP module_sp(GetModule());
471 if (module_sp) {
472 ObjectFile *module_objfile = module_sp->GetObjectFile();
473 if (m_sym_file_ap.get()) {
474 ObjectFile *symfile_objfile = m_sym_file_ap->GetObjectFile();
475 if (symfile_objfile != module_objfile)
476 symfile_objfile->SectionFileAddressesChanged();
477 }
478 Symtab *symtab = GetSymtab();
479 if (symtab) {
480 symtab->SectionFileAddressesChanged();
481 }
482 }
Jason Molenda05a09c62014-08-22 02:46:46 +0000483}
484
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000485//------------------------------------------------------------------
486// PluginInterface protocol
487//------------------------------------------------------------------
Kate Stoneb9c1b512016-09-06 20:57:50 +0000488lldb_private::ConstString SymbolVendor::GetPluginName() {
489 static ConstString g_name("vendor-default");
490 return g_name;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000491}
492
Kate Stoneb9c1b512016-09-06 20:57:50 +0000493uint32_t SymbolVendor::GetPluginVersion() { return 1; }