blob: 47f264f9841a5948fc319958feeadaabb4c625bf [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
Greg Clayton1f746072012-08-29 21:13:06 +0000121lldb::LanguageType
Kate Stoneb9c1b512016-09-06 20:57:50 +0000122SymbolVendor::ParseCompileUnitLanguage(const SymbolContext &sc) {
123 ModuleSP module_sp(GetModule());
124 if (module_sp) {
125 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
126 if (m_sym_file_ap.get())
127 return m_sym_file_ap->ParseCompileUnitLanguage(sc);
128 }
129 return eLanguageTypeUnknown;
Greg Clayton1f746072012-08-29 21:13:06 +0000130}
131
Kate Stoneb9c1b512016-09-06 20:57:50 +0000132size_t SymbolVendor::ParseCompileUnitFunctions(const SymbolContext &sc) {
133 ModuleSP module_sp(GetModule());
134 if (module_sp) {
135 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
136 if (m_sym_file_ap.get())
137 return m_sym_file_ap->ParseCompileUnitFunctions(sc);
138 }
139 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000140}
141
Kate Stoneb9c1b512016-09-06 20:57:50 +0000142bool SymbolVendor::ParseCompileUnitLineTable(const SymbolContext &sc) {
143 ModuleSP module_sp(GetModule());
144 if (module_sp) {
145 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
146 if (m_sym_file_ap.get())
147 return m_sym_file_ap->ParseCompileUnitLineTable(sc);
148 }
149 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000150}
151
Kate Stoneb9c1b512016-09-06 20:57:50 +0000152bool SymbolVendor::ParseCompileUnitDebugMacros(const SymbolContext &sc) {
153 ModuleSP module_sp(GetModule());
154 if (module_sp) {
155 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
156 if (m_sym_file_ap.get())
157 return m_sym_file_ap->ParseCompileUnitDebugMacros(sc);
158 }
159 return false;
Siva Chandrad8335e92015-12-16 00:22:08 +0000160}
Kate Stoneb9c1b512016-09-06 20:57:50 +0000161bool SymbolVendor::ParseCompileUnitSupportFiles(const SymbolContext &sc,
162 FileSpecList &support_files) {
163 ModuleSP module_sp(GetModule());
164 if (module_sp) {
165 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
166 if (m_sym_file_ap.get())
167 return m_sym_file_ap->ParseCompileUnitSupportFiles(sc, support_files);
168 }
169 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000170}
171
Kate Stoneb9c1b512016-09-06 20:57:50 +0000172bool SymbolVendor::ParseCompileUnitIsOptimized(const SymbolContext &sc) {
173 ModuleSP module_sp(GetModule());
174 if (module_sp) {
175 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
176 if (m_sym_file_ap.get())
177 return m_sym_file_ap->ParseCompileUnitIsOptimized(sc);
178 }
179 return false;
Greg Claytonad2b63c2016-07-05 23:01:20 +0000180}
181
Kate Stoneb9c1b512016-09-06 20:57:50 +0000182bool SymbolVendor::ParseImportedModules(
183 const SymbolContext &sc, std::vector<ConstString> &imported_modules) {
184 ModuleSP module_sp(GetModule());
185 if (module_sp) {
186 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
187 if (m_sym_file_ap.get())
188 return m_sym_file_ap->ParseImportedModules(sc, imported_modules);
189 }
190 return false;
Sean Callananf0c5aeb2015-04-20 16:31:29 +0000191}
192
Kate Stoneb9c1b512016-09-06 20:57:50 +0000193size_t SymbolVendor::ParseFunctionBlocks(const SymbolContext &sc) {
194 ModuleSP module_sp(GetModule());
195 if (module_sp) {
196 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
197 if (m_sym_file_ap.get())
198 return m_sym_file_ap->ParseFunctionBlocks(sc);
199 }
200 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000201}
202
Zachary Turnerac0d41c2019-01-10 20:57:50 +0000203size_t SymbolVendor::ParseTypesForCompileUnit(CompileUnit &comp_unit) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000204 ModuleSP module_sp(GetModule());
205 if (module_sp) {
206 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
207 if (m_sym_file_ap.get())
Zachary Turnerac0d41c2019-01-10 20:57:50 +0000208 return m_sym_file_ap->ParseTypesForCompileUnit(comp_unit);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000209 }
210 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000211}
212
Kate Stoneb9c1b512016-09-06 20:57:50 +0000213size_t SymbolVendor::ParseVariablesForContext(const SymbolContext &sc) {
214 ModuleSP module_sp(GetModule());
215 if (module_sp) {
216 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
217 if (m_sym_file_ap.get())
218 return m_sym_file_ap->ParseVariablesForContext(sc);
219 }
220 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000221}
222
Kate Stoneb9c1b512016-09-06 20:57:50 +0000223Type *SymbolVendor::ResolveTypeUID(lldb::user_id_t type_uid) {
224 ModuleSP module_sp(GetModule());
225 if (module_sp) {
226 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
227 if (m_sym_file_ap.get())
228 return m_sym_file_ap->ResolveTypeUID(type_uid);
229 }
230 return nullptr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000231}
232
Kate Stoneb9c1b512016-09-06 20:57:50 +0000233uint32_t SymbolVendor::ResolveSymbolContext(const Address &so_addr,
Zachary Turner991e4452018-10-25 20:45:19 +0000234 SymbolContextItem resolve_scope,
Kate Stoneb9c1b512016-09-06 20:57:50 +0000235 SymbolContext &sc) {
236 ModuleSP module_sp(GetModule());
237 if (module_sp) {
238 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
239 if (m_sym_file_ap.get())
240 return m_sym_file_ap->ResolveSymbolContext(so_addr, resolve_scope, sc);
241 }
242 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000243}
244
Kate Stoneb9c1b512016-09-06 20:57:50 +0000245uint32_t SymbolVendor::ResolveSymbolContext(const FileSpec &file_spec,
246 uint32_t line, bool check_inlines,
Zachary Turner991e4452018-10-25 20:45:19 +0000247 SymbolContextItem resolve_scope,
Kate Stoneb9c1b512016-09-06 20:57:50 +0000248 SymbolContextList &sc_list) {
249 ModuleSP module_sp(GetModule());
250 if (module_sp) {
251 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
252 if (m_sym_file_ap.get())
253 return m_sym_file_ap->ResolveSymbolContext(file_spec, line, check_inlines,
254 resolve_scope, sc_list);
255 }
256 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000257}
258
Pavel Labath34cda142018-05-31 09:46:26 +0000259size_t
260SymbolVendor::FindGlobalVariables(const ConstString &name,
261 const CompilerDeclContext *parent_decl_ctx,
262 size_t max_matches, VariableList &variables) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000263 ModuleSP module_sp(GetModule());
264 if (module_sp) {
265 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
266 if (m_sym_file_ap.get())
Pavel Labath34cda142018-05-31 09:46:26 +0000267 return m_sym_file_ap->FindGlobalVariables(name, parent_decl_ctx,
Kate Stoneb9c1b512016-09-06 20:57:50 +0000268 max_matches, variables);
269 }
270 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000271}
272
Kate Stoneb9c1b512016-09-06 20:57:50 +0000273size_t SymbolVendor::FindGlobalVariables(const RegularExpression &regex,
Pavel Labath34cda142018-05-31 09:46:26 +0000274 size_t max_matches,
Kate Stoneb9c1b512016-09-06 20:57:50 +0000275 VariableList &variables) {
276 ModuleSP module_sp(GetModule());
277 if (module_sp) {
278 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
279 if (m_sym_file_ap.get())
Pavel Labath34cda142018-05-31 09:46:26 +0000280 return m_sym_file_ap->FindGlobalVariables(regex, max_matches, variables);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000281 }
282 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000283}
284
Kate Stoneb9c1b512016-09-06 20:57:50 +0000285size_t SymbolVendor::FindFunctions(const ConstString &name,
286 const CompilerDeclContext *parent_decl_ctx,
Zachary Turner117b1fa2018-10-25 20:45:40 +0000287 FunctionNameType name_type_mask,
Kate Stoneb9c1b512016-09-06 20:57:50 +0000288 bool include_inlines, bool append,
289 SymbolContextList &sc_list) {
290 ModuleSP module_sp(GetModule());
291 if (module_sp) {
292 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
293 if (m_sym_file_ap.get())
294 return m_sym_file_ap->FindFunctions(name, parent_decl_ctx, name_type_mask,
295 include_inlines, append, sc_list);
296 }
297 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000298}
299
Kate Stoneb9c1b512016-09-06 20:57:50 +0000300size_t SymbolVendor::FindFunctions(const RegularExpression &regex,
301 bool include_inlines, bool append,
302 SymbolContextList &sc_list) {
303 ModuleSP module_sp(GetModule());
304 if (module_sp) {
305 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
306 if (m_sym_file_ap.get())
307 return m_sym_file_ap->FindFunctions(regex, include_inlines, append,
308 sc_list);
309 }
310 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000311}
312
Kate Stoneb9c1b512016-09-06 20:57:50 +0000313size_t SymbolVendor::FindTypes(
314 const SymbolContext &sc, const ConstString &name,
315 const CompilerDeclContext *parent_decl_ctx, bool append, size_t max_matches,
316 llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
317 TypeMap &types) {
318 ModuleSP module_sp(GetModule());
319 if (module_sp) {
320 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
321 if (m_sym_file_ap.get())
322 return m_sym_file_ap->FindTypes(sc, name, parent_decl_ctx, append,
323 max_matches, searched_symbol_files,
324 types);
325 }
326 if (!append)
327 types.Clear();
328 return 0;
Greg Claytonb0b9fe62010-08-03 00:35:52 +0000329}
Greg Clayton526e5af2010-11-13 03:52:47 +0000330
Kate Stoneb9c1b512016-09-06 20:57:50 +0000331size_t SymbolVendor::FindTypes(const std::vector<CompilerContext> &context,
332 bool append, TypeMap &types) {
333 ModuleSP module_sp(GetModule());
334 if (module_sp) {
335 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
336 if (m_sym_file_ap.get())
337 return m_sym_file_ap->FindTypes(context, append, types);
338 }
339 if (!append)
340 types.Clear();
341 return 0;
Greg Claytone6b36cd2015-12-08 01:02:08 +0000342}
343
Zachary Turner117b1fa2018-10-25 20:45:40 +0000344size_t SymbolVendor::GetTypes(SymbolContextScope *sc_scope, TypeClass type_mask,
Kate Stoneb9c1b512016-09-06 20:57:50 +0000345 lldb_private::TypeList &type_list) {
346 ModuleSP module_sp(GetModule());
347 if (module_sp) {
348 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
349 if (m_sym_file_ap.get())
350 return m_sym_file_ap->GetTypes(sc_scope, type_mask, type_list);
351 }
352 return 0;
Greg Claytonf02500c2013-06-18 22:51:05 +0000353}
354
Greg Clayton99558cc42015-08-24 23:46:31 +0000355CompilerDeclContext
Kate Stoneb9c1b512016-09-06 20:57:50 +0000356SymbolVendor::FindNamespace(const SymbolContext &sc, const ConstString &name,
357 const CompilerDeclContext *parent_decl_ctx) {
358 CompilerDeclContext namespace_decl_ctx;
359 ModuleSP module_sp(GetModule());
360 if (module_sp) {
361 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
Ilia Ke912e3e2015-03-10 21:18:59 +0000362 if (m_sym_file_ap.get())
Kate Stoneb9c1b512016-09-06 20:57:50 +0000363 namespace_decl_ctx =
364 m_sym_file_ap->FindNamespace(sc, name, parent_decl_ctx);
365 }
366 return namespace_decl_ctx;
Ilia Ke912e3e2015-03-10 21:18:59 +0000367}
368
Kate Stoneb9c1b512016-09-06 20:57:50 +0000369void SymbolVendor::Dump(Stream *s) {
370 ModuleSP module_sp(GetModule());
371 if (module_sp) {
372 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
373
374 bool show_context = false;
375
376 s->Printf("%p: ", static_cast<void *>(this));
377 s->Indent();
378 s->PutCString("SymbolVendor");
379 if (m_sym_file_ap.get()) {
Pavel Labath1cf23e12019-01-11 11:17:51 +0000380 *s << " " << m_sym_file_ap->GetPluginName();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000381 ObjectFile *objfile = m_sym_file_ap->GetObjectFile();
382 if (objfile) {
383 const FileSpec &objfile_file_spec = objfile->GetFileSpec();
384 if (objfile_file_spec) {
385 s->PutCString(" (");
386 objfile_file_spec.Dump(s);
387 s->PutChar(')');
Michael Sartaina7499c92013-07-01 19:45:50 +0000388 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000389 }
Michael Sartaina7499c92013-07-01 19:45:50 +0000390 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000391 s->EOL();
Pavel Labath9337b412018-06-06 11:35:23 +0000392 if (m_sym_file_ap)
393 m_sym_file_ap->Dump(*s);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000394 s->IndentMore();
395 m_type_list.Dump(s, show_context);
396
397 CompileUnitConstIter cu_pos, cu_end;
398 cu_end = m_compile_units.end();
399 for (cu_pos = m_compile_units.begin(); cu_pos != cu_end; ++cu_pos) {
400 // We currently only dump the compile units that have been parsed
401 if (cu_pos->get())
402 (*cu_pos)->Dump(s, show_context);
403 }
404
Pavel Labath1cf23e12019-01-11 11:17:51 +0000405 if (Symtab *symtab = GetSymtab())
406 symtab->Dump(s, nullptr, eSortOrderNone);
407
Kate Stoneb9c1b512016-09-06 20:57:50 +0000408 s->IndentLess();
409 }
Michael Sartaina7499c92013-07-01 19:45:50 +0000410}
411
Kate Stoneb9c1b512016-09-06 20:57:50 +0000412CompUnitSP SymbolVendor::GetCompileUnitAtIndex(size_t idx) {
413 CompUnitSP cu_sp;
414 ModuleSP module_sp(GetModule());
415 if (module_sp) {
416 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
417 const size_t num_compile_units = GetNumCompileUnits();
418 if (idx < num_compile_units) {
419 cu_sp = m_compile_units[idx];
420 if (cu_sp.get() == nullptr) {
421 m_compile_units[idx] = m_sym_file_ap->ParseCompileUnitAtIndex(idx);
422 cu_sp = m_compile_units[idx];
423 }
Michael Sartaina7499c92013-07-01 19:45:50 +0000424 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000425 }
426 return cu_sp;
Michael Sartaina7499c92013-07-01 19:45:50 +0000427}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000428
Kate Stoneb9c1b512016-09-06 20:57:50 +0000429FileSpec SymbolVendor::GetMainFileSpec() const {
430 if (m_sym_file_ap.get()) {
431 const ObjectFile *symfile_objfile = m_sym_file_ap->GetObjectFile();
432 if (symfile_objfile)
433 return symfile_objfile->GetFileSpec();
434 }
435
436 return FileSpec();
437}
438
439Symtab *SymbolVendor::GetSymtab() {
440 ModuleSP module_sp(GetModule());
Aleksandr Urakov8cfb12b2018-11-30 06:56:37 +0000441 if (!module_sp)
442 return nullptr;
443
444 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
445
446 if (m_symtab)
447 return m_symtab;
448
449 ObjectFile *objfile = module_sp->GetObjectFile();
450 if (!objfile)
451 return nullptr;
452
453 m_symtab = objfile->GetSymtab();
454 if (m_symtab && m_sym_file_ap)
455 m_sym_file_ap->AddSymbols(*m_symtab);
456
457 return m_symtab;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000458}
459
460void SymbolVendor::ClearSymtab() {
461 ModuleSP module_sp(GetModule());
462 if (module_sp) {
463 ObjectFile *objfile = module_sp->GetObjectFile();
464 if (objfile) {
465 // Clear symbol table from unified section list.
466 objfile->ClearSymtab();
467 }
468 }
469}
470
471void SymbolVendor::SectionFileAddressesChanged() {
472 ModuleSP module_sp(GetModule());
473 if (module_sp) {
474 ObjectFile *module_objfile = module_sp->GetObjectFile();
475 if (m_sym_file_ap.get()) {
476 ObjectFile *symfile_objfile = m_sym_file_ap->GetObjectFile();
477 if (symfile_objfile != module_objfile)
478 symfile_objfile->SectionFileAddressesChanged();
479 }
480 Symtab *symtab = GetSymtab();
481 if (symtab) {
482 symtab->SectionFileAddressesChanged();
483 }
484 }
Jason Molenda05a09c62014-08-22 02:46:46 +0000485}
486
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000487//------------------------------------------------------------------
488// PluginInterface protocol
489//------------------------------------------------------------------
Kate Stoneb9c1b512016-09-06 20:57:50 +0000490lldb_private::ConstString SymbolVendor::GetPluginName() {
491 static ConstString g_name("vendor-default");
492 return g_name;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000493}
494
Kate Stoneb9c1b512016-09-06 20:57:50 +0000495uint32_t SymbolVendor::GetPluginVersion() { return 1; }