blob: 735dde4a5daff335f79caf47e8378653be3049ac [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- Module.cpp ----------------------------------------------*- 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/Core/Module.h"
11#include "lldb/Core/Log.h"
12#include "lldb/Core/ModuleList.h"
13#include "lldb/Core/RegularExpression.h"
14#include "lldb/Core/Timer.h"
15#include "lldb/lldb-private-log.h"
16#include "lldb/Symbol/ObjectFile.h"
17#include "lldb/Symbol/SymbolContext.h"
18#include "lldb/Symbol/SymbolVendor.h"
19
20using namespace lldb;
21using namespace lldb_private;
22
23Module::Module(const FileSpec& file_spec, const ArchSpec& arch, const ConstString *object_name, off_t object_offset) :
24 m_mutex (Mutex::eMutexTypeRecursive),
25 m_mod_time (file_spec.GetModificationTime()),
26 m_arch (arch),
27 m_uuid (),
28 m_file (file_spec),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029 m_object_name (),
30 m_objfile_ap (),
Greg Claytone83e7312010-09-07 23:40:05 +000031 m_symfile_ap (),
Greg Clayton6beaaa62011-01-17 03:46:26 +000032 m_ast (),
Greg Claytone83e7312010-09-07 23:40:05 +000033 m_did_load_objfile (false),
34 m_did_load_symbol_vendor (false),
35 m_did_parse_uuid (false),
Greg Clayton6beaaa62011-01-17 03:46:26 +000036 m_did_init_ast (false),
Greg Claytone83e7312010-09-07 23:40:05 +000037 m_is_dynamic_loader_module (false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000038{
39 if (object_name)
40 m_object_name = *object_name;
Greg Clayton2d4edfb2010-11-06 01:53:30 +000041 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner30fdc8d2010-06-08 16:52:24 +000042 if (log)
43 log->Printf ("%p Module::Module((%s) '%s/%s%s%s%s')",
44 this,
Greg Clayton64195a22011-02-23 00:35:02 +000045 m_arch.GetArchitectureName(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000046 m_file.GetDirectory().AsCString(""),
47 m_file.GetFilename().AsCString(""),
48 m_object_name.IsEmpty() ? "" : "(",
49 m_object_name.IsEmpty() ? "" : m_object_name.AsCString(""),
50 m_object_name.IsEmpty() ? "" : ")");
Chris Lattner30fdc8d2010-06-08 16:52:24 +000051}
52
53Module::~Module()
54{
Greg Clayton2d4edfb2010-11-06 01:53:30 +000055 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner30fdc8d2010-06-08 16:52:24 +000056 if (log)
57 log->Printf ("%p Module::~Module((%s) '%s/%s%s%s%s')",
58 this,
Greg Clayton64195a22011-02-23 00:35:02 +000059 m_arch.GetArchitectureName(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000060 m_file.GetDirectory().AsCString(""),
61 m_file.GetFilename().AsCString(""),
62 m_object_name.IsEmpty() ? "" : "(",
63 m_object_name.IsEmpty() ? "" : m_object_name.AsCString(""),
64 m_object_name.IsEmpty() ? "" : ")");
Greg Clayton6beaaa62011-01-17 03:46:26 +000065 // Release any auto pointers before we start tearing down our member
66 // variables since the object file and symbol files might need to make
67 // function calls back into this module object. The ordering is important
68 // here because symbol files can require the module object file. So we tear
69 // down the symbol file first, then the object file.
70 m_symfile_ap.reset();
71 m_objfile_ap.reset();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000072}
73
74
75ModuleSP
76Module::GetSP ()
77{
78 return ModuleList::GetModuleSP (this);
79}
80
Greg Clayton60830262011-02-04 18:53:10 +000081const lldb_private::UUID&
Chris Lattner30fdc8d2010-06-08 16:52:24 +000082Module::GetUUID()
83{
84 Mutex::Locker locker (m_mutex);
Greg Claytone83e7312010-09-07 23:40:05 +000085 if (m_did_parse_uuid == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000086 {
87 ObjectFile * obj_file = GetObjectFile ();
88
89 if (obj_file != NULL)
90 {
91 obj_file->GetUUID(&m_uuid);
Greg Claytone83e7312010-09-07 23:40:05 +000092 m_did_parse_uuid = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000093 }
94 }
95 return m_uuid;
96}
97
Greg Clayton6beaaa62011-01-17 03:46:26 +000098ClangASTContext &
99Module::GetClangASTContext ()
100{
101 Mutex::Locker locker (m_mutex);
102 if (m_did_init_ast == false)
103 {
104 ObjectFile * objfile = GetObjectFile();
Greg Clayton514487e2011-02-15 21:59:32 +0000105 ArchSpec object_arch;
106 if (objfile && objfile->GetArchitecture(object_arch))
Greg Clayton6beaaa62011-01-17 03:46:26 +0000107 {
108 m_did_init_ast = true;
Greg Clayton514487e2011-02-15 21:59:32 +0000109 m_ast.SetArchitecture (object_arch);
Greg Clayton6beaaa62011-01-17 03:46:26 +0000110 }
111 }
112 return m_ast;
113}
114
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000115void
116Module::ParseAllDebugSymbols()
117{
118 Mutex::Locker locker (m_mutex);
119 uint32_t num_comp_units = GetNumCompileUnits();
120 if (num_comp_units == 0)
121 return;
122
123 TargetSP null_target;
124 SymbolContext sc(null_target, GetSP());
125 uint32_t cu_idx;
126 SymbolVendor *symbols = GetSymbolVendor ();
127
128 for (cu_idx = 0; cu_idx < num_comp_units; cu_idx++)
129 {
130 sc.comp_unit = symbols->GetCompileUnitAtIndex(cu_idx).get();
131 if (sc.comp_unit)
132 {
133 sc.function = NULL;
134 symbols->ParseVariablesForContext(sc);
135
136 symbols->ParseCompileUnitFunctions(sc);
137
138 uint32_t func_idx;
139 for (func_idx = 0; (sc.function = sc.comp_unit->GetFunctionAtIndex(func_idx).get()) != NULL; ++func_idx)
140 {
141 symbols->ParseFunctionBlocks(sc);
142
143 // Parse the variables for this function and all its blocks
144 symbols->ParseVariablesForContext(sc);
145 }
146
147
148 // Parse all types for this compile unit
149 sc.function = NULL;
150 symbols->ParseTypes(sc);
151 }
152 }
153}
154
155void
156Module::CalculateSymbolContext(SymbolContext* sc)
157{
158 sc->module_sp = GetSP();
159}
160
161void
162Module::DumpSymbolContext(Stream *s)
163{
164 s->Printf(", Module{0x%8.8x}", this);
165}
166
167uint32_t
168Module::GetNumCompileUnits()
169{
170 Mutex::Locker locker (m_mutex);
171 Timer scoped_timer(__PRETTY_FUNCTION__, "Module::GetNumCompileUnits (module = %p)", this);
172 SymbolVendor *symbols = GetSymbolVendor ();
173 if (symbols)
174 return symbols->GetNumCompileUnits();
175 return 0;
176}
177
178CompUnitSP
179Module::GetCompileUnitAtIndex (uint32_t index)
180{
181 Mutex::Locker locker (m_mutex);
182 uint32_t num_comp_units = GetNumCompileUnits ();
183 CompUnitSP cu_sp;
184
185 if (index < num_comp_units)
186 {
187 SymbolVendor *symbols = GetSymbolVendor ();
188 if (symbols)
189 cu_sp = symbols->GetCompileUnitAtIndex(index);
190 }
191 return cu_sp;
192}
193
194//CompUnitSP
195//Module::FindCompUnit(lldb::user_id_t uid)
196//{
197// CompUnitSP cu_sp;
198// SymbolVendor *symbols = GetSymbolVendor ();
199// if (symbols)
200// cu_sp = symbols->FindCompUnit(uid);
201// return cu_sp;
202//}
203
204bool
205Module::ResolveFileAddress (lldb::addr_t vm_addr, Address& so_addr)
206{
207 Mutex::Locker locker (m_mutex);
208 Timer scoped_timer(__PRETTY_FUNCTION__, "Module::ResolveFileAddress (vm_addr = 0x%llx)", vm_addr);
209 ObjectFile* ofile = GetObjectFile();
210 if (ofile)
211 return so_addr.ResolveAddressUsingFileSections(vm_addr, ofile->GetSectionList());
212 return false;
213}
214
215uint32_t
216Module::ResolveSymbolContextForAddress (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
217{
218 Mutex::Locker locker (m_mutex);
219 uint32_t resolved_flags = 0;
220
221 // Clear the result symbol context in case we don't find anything
222 sc.Clear();
223
224 // Get the section from the section/offset address.
225 const Section *section = so_addr.GetSection();
226
227 // Make sure the section matches this module before we try and match anything
228 if (section && section->GetModule() == this)
229 {
230 // If the section offset based address resolved itself, then this
231 // is the right module.
232 sc.module_sp = GetSP();
233 resolved_flags |= eSymbolContextModule;
234
235 // Resolve the compile unit, function, block, line table or line
236 // entry if requested.
237 if (resolve_scope & eSymbolContextCompUnit ||
238 resolve_scope & eSymbolContextFunction ||
239 resolve_scope & eSymbolContextBlock ||
240 resolve_scope & eSymbolContextLineEntry )
241 {
242 SymbolVendor *symbols = GetSymbolVendor ();
243 if (symbols)
244 resolved_flags |= symbols->ResolveSymbolContext (so_addr, resolve_scope, sc);
245 }
246
Jim Ingham680e1772010-08-31 23:51:36 +0000247 // Resolve the symbol if requested, but don't re-look it up if we've already found it.
248 if (resolve_scope & eSymbolContextSymbol && !(resolved_flags & eSymbolContextSymbol))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000249 {
250 ObjectFile* ofile = GetObjectFile();
251 if (ofile)
252 {
253 Symtab *symtab = ofile->GetSymtab();
254 if (symtab)
255 {
256 if (so_addr.IsSectionOffset())
257 {
258 sc.symbol = symtab->FindSymbolContainingFileAddress(so_addr.GetFileAddress());
259 if (sc.symbol)
260 resolved_flags |= eSymbolContextSymbol;
261 }
262 }
263 }
264 }
265 }
266 return resolved_flags;
267}
268
269uint32_t
Greg Clayton274060b2010-10-20 20:54:39 +0000270Module::ResolveSymbolContextForFilePath
271(
272 const char *file_path,
273 uint32_t line,
274 bool check_inlines,
275 uint32_t resolve_scope,
276 SymbolContextList& sc_list
277)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000278{
Greg Clayton274060b2010-10-20 20:54:39 +0000279 FileSpec file_spec(file_path, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000280 return ResolveSymbolContextsForFileSpec (file_spec, line, check_inlines, resolve_scope, sc_list);
281}
282
283uint32_t
284Module::ResolveSymbolContextsForFileSpec (const FileSpec &file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
285{
286 Mutex::Locker locker (m_mutex);
287 Timer scoped_timer(__PRETTY_FUNCTION__,
288 "Module::ResolveSymbolContextForFilePath (%s%s%s:%u, check_inlines = %s, resolve_scope = 0x%8.8x)",
289 file_spec.GetDirectory().AsCString(""),
290 file_spec.GetDirectory() ? "/" : "",
291 file_spec.GetFilename().AsCString(""),
292 line,
293 check_inlines ? "yes" : "no",
294 resolve_scope);
295
296 const uint32_t initial_count = sc_list.GetSize();
297
298 SymbolVendor *symbols = GetSymbolVendor ();
299 if (symbols)
300 symbols->ResolveSymbolContext (file_spec, line, check_inlines, resolve_scope, sc_list);
301
302 return sc_list.GetSize() - initial_count;
303}
304
305
306uint32_t
307Module::FindGlobalVariables(const ConstString &name, bool append, uint32_t max_matches, VariableList& variables)
308{
309 SymbolVendor *symbols = GetSymbolVendor ();
310 if (symbols)
311 return symbols->FindGlobalVariables(name, append, max_matches, variables);
312 return 0;
313}
314uint32_t
315Module::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
316{
317 SymbolVendor *symbols = GetSymbolVendor ();
318 if (symbols)
319 return symbols->FindGlobalVariables(regex, append, max_matches, variables);
320 return 0;
321}
322
323uint32_t
Greg Clayton931180e2011-01-27 06:44:37 +0000324Module::FindFunctions (const ConstString &name,
325 uint32_t name_type_mask,
326 bool include_symbols,
327 bool append,
328 SymbolContextList& sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000329{
Greg Clayton931180e2011-01-27 06:44:37 +0000330 if (!append)
331 sc_list.Clear();
332
333 const uint32_t start_size = sc_list.GetSize();
334
335 // Find all the functions (not symbols, but debug information functions...
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000336 SymbolVendor *symbols = GetSymbolVendor ();
337 if (symbols)
Greg Clayton931180e2011-01-27 06:44:37 +0000338 symbols->FindFunctions(name, name_type_mask, append, sc_list);
339
340 // Now check our symbol table for symbols that are code symbols if requested
341 if (include_symbols)
342 {
343 ObjectFile *objfile = GetObjectFile();
344 if (objfile)
345 {
346 Symtab *symtab = objfile->GetSymtab();
347 if (symtab)
348 {
349 std::vector<uint32_t> symbol_indexes;
350 symtab->FindAllSymbolsWithNameAndType (name, eSymbolTypeCode, Symtab::eDebugAny, Symtab::eVisibilityAny, symbol_indexes);
351 const uint32_t num_matches = symbol_indexes.size();
352 if (num_matches)
353 {
Greg Clayton357132e2011-03-26 19:14:58 +0000354 const bool merge_symbol_into_function = true;
Greg Clayton931180e2011-01-27 06:44:37 +0000355 SymbolContext sc(this);
356 for (uint32_t i=0; i<num_matches; i++)
357 {
358 sc.symbol = symtab->SymbolAtIndex(symbol_indexes[i]);
Greg Clayton357132e2011-03-26 19:14:58 +0000359 sc_list.AppendIfUnique (sc, merge_symbol_into_function);
Greg Clayton931180e2011-01-27 06:44:37 +0000360 }
361 }
362 }
363 }
364 }
365 return sc_list.GetSize() - start_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000366}
367
368uint32_t
Greg Clayton931180e2011-01-27 06:44:37 +0000369Module::FindFunctions (const RegularExpression& regex,
370 bool include_symbols,
371 bool append,
372 SymbolContextList& sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000373{
Greg Clayton931180e2011-01-27 06:44:37 +0000374 if (!append)
375 sc_list.Clear();
376
377 const uint32_t start_size = sc_list.GetSize();
378
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000379 SymbolVendor *symbols = GetSymbolVendor ();
380 if (symbols)
381 return symbols->FindFunctions(regex, append, sc_list);
Greg Clayton931180e2011-01-27 06:44:37 +0000382 // Now check our symbol table for symbols that are code symbols if requested
383 if (include_symbols)
384 {
385 ObjectFile *objfile = GetObjectFile();
386 if (objfile)
387 {
388 Symtab *symtab = objfile->GetSymtab();
389 if (symtab)
390 {
391 std::vector<uint32_t> symbol_indexes;
392 symtab->AppendSymbolIndexesMatchingRegExAndType (regex, eSymbolTypeCode, Symtab::eDebugAny, Symtab::eVisibilityAny, symbol_indexes);
393 const uint32_t num_matches = symbol_indexes.size();
394 if (num_matches)
395 {
Greg Clayton357132e2011-03-26 19:14:58 +0000396 const bool merge_symbol_into_function = true;
Greg Clayton931180e2011-01-27 06:44:37 +0000397 SymbolContext sc(this);
398 for (uint32_t i=0; i<num_matches; i++)
399 {
400 sc.symbol = symtab->SymbolAtIndex(symbol_indexes[i]);
Greg Clayton357132e2011-03-26 19:14:58 +0000401 sc_list.AppendIfUnique (sc, merge_symbol_into_function);
Greg Clayton931180e2011-01-27 06:44:37 +0000402 }
403 }
404 }
405 }
406 }
407 return sc_list.GetSize() - start_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000408}
409
Greg Clayton3504eee2010-08-03 01:26:16 +0000410uint32_t
411Module::FindTypes (const SymbolContext& sc, const ConstString &name, bool append, uint32_t max_matches, TypeList& types)
412{
413 Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
414 if (sc.module_sp.get() == NULL || sc.module_sp.get() == this)
415 {
416 SymbolVendor *symbols = GetSymbolVendor ();
417 if (symbols)
418 return symbols->FindTypes(sc, name, append, max_matches, types);
419 }
420 return 0;
421}
422
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000423//uint32_t
424//Module::FindTypes(const SymbolContext& sc, const RegularExpression& regex, bool append, uint32_t max_matches, Type::Encoding encoding, const char *udt_name, TypeList& types)
425//{
426// Timer scoped_timer(__PRETTY_FUNCTION__);
427// SymbolVendor *symbols = GetSymbolVendor ();
428// if (symbols)
429// return symbols->FindTypes(sc, regex, append, max_matches, encoding, udt_name, types);
430// return 0;
431//
432//}
433
434SymbolVendor*
435Module::GetSymbolVendor (bool can_create)
436{
437 Mutex::Locker locker (m_mutex);
Greg Claytone83e7312010-09-07 23:40:05 +0000438 if (m_did_load_symbol_vendor == false && can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000439 {
440 ObjectFile *obj_file = GetObjectFile ();
441 if (obj_file != NULL)
442 {
443 Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
444 m_symfile_ap.reset(SymbolVendor::FindPlugin(this));
Greg Claytone83e7312010-09-07 23:40:05 +0000445 m_did_load_symbol_vendor = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000446 }
447 }
448 return m_symfile_ap.get();
449}
450
451const FileSpec &
452Module::GetFileSpec () const
453{
454 return m_file;
455}
456
457void
458Module::SetFileSpecAndObjectName (const FileSpec &file, const ConstString &object_name)
459{
460 // Container objects whose paths do not specify a file directly can call
461 // this function to correct the file and object names.
462 m_file = file;
463 m_mod_time = file.GetModificationTime();
464 m_object_name = object_name;
465}
466
467const ArchSpec&
468Module::GetArchitecture () const
469{
470 return m_arch;
471}
472
473void
Caroline Ticeceb6b132010-10-26 03:11:13 +0000474Module::GetDescription (Stream *s)
475{
476 Mutex::Locker locker (m_mutex);
477
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000478 if (m_arch.IsValid())
Greg Clayton64195a22011-02-23 00:35:02 +0000479 s->Printf("(%s) ", m_arch.GetArchitectureName());
Caroline Ticeceb6b132010-10-26 03:11:13 +0000480
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000481 char path[PATH_MAX];
482 if (m_file.GetPath(path, sizeof(path)))
483 s->PutCString(path);
484
485 const char *object_name = m_object_name.GetCString();
486 if (object_name)
487 s->Printf("(%s)", object_name);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000488}
489
490void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000491Module::Dump(Stream *s)
492{
493 Mutex::Locker locker (m_mutex);
Greg Clayton89411422010-10-08 00:21:05 +0000494 //s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000495 s->Indent();
496 s->Printf("Module %s/%s%s%s%s\n",
497 m_file.GetDirectory().AsCString(),
498 m_file.GetFilename().AsCString(),
499 m_object_name ? "(" : "",
500 m_object_name ? m_object_name.GetCString() : "",
501 m_object_name ? ")" : "");
502
503 s->IndentMore();
504 ObjectFile *objfile = GetObjectFile ();
505
506 if (objfile)
507 objfile->Dump(s);
508
509 SymbolVendor *symbols = GetSymbolVendor ();
510
511 if (symbols)
512 symbols->Dump(s);
513
514 s->IndentLess();
515}
516
517
518TypeList*
519Module::GetTypeList ()
520{
521 SymbolVendor *symbols = GetSymbolVendor ();
522 if (symbols)
523 return &symbols->GetTypeList();
524 return NULL;
525}
526
527const ConstString &
528Module::GetObjectName() const
529{
530 return m_object_name;
531}
532
533ObjectFile *
534Module::GetObjectFile()
535{
536 Mutex::Locker locker (m_mutex);
Greg Claytone83e7312010-09-07 23:40:05 +0000537 if (m_did_load_objfile == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000538 {
Greg Claytone83e7312010-09-07 23:40:05 +0000539 m_did_load_objfile = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000540 Timer scoped_timer(__PRETTY_FUNCTION__,
541 "Module::GetObjectFile () module = %s", GetFileSpec().GetFilename().AsCString(""));
542 m_objfile_ap.reset(ObjectFile::FindPlugin(this, &m_file, 0, m_file.GetByteSize()));
543 }
544 return m_objfile_ap.get();
545}
546
547
548const Symbol *
549Module::FindFirstSymbolWithNameAndType (const ConstString &name, SymbolType symbol_type)
550{
551 Timer scoped_timer(__PRETTY_FUNCTION__,
552 "Module::FindFirstSymbolWithNameAndType (name = %s, type = %i)",
553 name.AsCString(),
554 symbol_type);
555 ObjectFile *objfile = GetObjectFile();
556 if (objfile)
557 {
558 Symtab *symtab = objfile->GetSymtab();
559 if (symtab)
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000560 return symtab->FindFirstSymbolWithNameAndType (name, symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000561 }
562 return NULL;
563}
564void
565Module::SymbolIndicesToSymbolContextList (Symtab *symtab, std::vector<uint32_t> &symbol_indexes, SymbolContextList &sc_list)
566{
567 // No need to protect this call using m_mutex all other method calls are
568 // already thread safe.
569
570 size_t num_indices = symbol_indexes.size();
571 if (num_indices > 0)
572 {
573 SymbolContext sc;
574 CalculateSymbolContext (&sc);
575 for (size_t i = 0; i < num_indices; i++)
576 {
577 sc.symbol = symtab->SymbolAtIndex (symbol_indexes[i]);
578 if (sc.symbol)
579 sc_list.Append (sc);
580 }
581 }
582}
583
584size_t
585Module::FindSymbolsWithNameAndType (const ConstString &name, SymbolType symbol_type, SymbolContextList &sc_list)
586{
587 // No need to protect this call using m_mutex all other method calls are
588 // already thread safe.
589
590
591 Timer scoped_timer(__PRETTY_FUNCTION__,
592 "Module::FindSymbolsWithNameAndType (name = %s, type = %i)",
593 name.AsCString(),
594 symbol_type);
595 const size_t initial_size = sc_list.GetSize();
596 ObjectFile *objfile = GetObjectFile ();
597 if (objfile)
598 {
599 Symtab *symtab = objfile->GetSymtab();
600 if (symtab)
601 {
602 std::vector<uint32_t> symbol_indexes;
603 symtab->FindAllSymbolsWithNameAndType (name, symbol_type, symbol_indexes);
604 SymbolIndicesToSymbolContextList (symtab, symbol_indexes, sc_list);
605 }
606 }
607 return sc_list.GetSize() - initial_size;
608}
609
610size_t
611Module::FindSymbolsMatchingRegExAndType (const RegularExpression &regex, SymbolType symbol_type, SymbolContextList &sc_list)
612{
613 // No need to protect this call using m_mutex all other method calls are
614 // already thread safe.
615
616 Timer scoped_timer(__PRETTY_FUNCTION__,
617 "Module::FindSymbolsMatchingRegExAndType (regex = %s, type = %i)",
618 regex.GetText(),
619 symbol_type);
620 const size_t initial_size = sc_list.GetSize();
621 ObjectFile *objfile = GetObjectFile ();
622 if (objfile)
623 {
624 Symtab *symtab = objfile->GetSymtab();
625 if (symtab)
626 {
627 std::vector<uint32_t> symbol_indexes;
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000628 symtab->FindAllSymbolsMatchingRexExAndType (regex, symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny, symbol_indexes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000629 SymbolIndicesToSymbolContextList (symtab, symbol_indexes, sc_list);
630 }
631 }
632 return sc_list.GetSize() - initial_size;
633}
634
635const TimeValue &
636Module::GetModificationTime () const
637{
638 return m_mod_time;
639}
Jim Ingham5aee1622010-08-09 23:31:02 +0000640
641bool
642Module::IsExecutable ()
643{
644 if (GetObjectFile() == NULL)
645 return false;
646 else
647 return GetObjectFile()->IsExecutable();
648}
649
650bool
651Module::SetArchitecture (const ArchSpec &new_arch)
652{
Greg Clayton64195a22011-02-23 00:35:02 +0000653 if (!m_arch.IsValid())
Jim Ingham5aee1622010-08-09 23:31:02 +0000654 {
655 m_arch = new_arch;
656 return true;
Greg Clayton64195a22011-02-23 00:35:02 +0000657 }
658 return m_arch == new_arch;
Jim Ingham5aee1622010-08-09 23:31:02 +0000659}
660