1 //===-- 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 20 using namespace lldb; 21 using namespace lldb_private; 22 23 // Shared pointers to modules track module lifetimes in 24 // targets and in the global module, but this collection 25 // will track all module objects that are still alive 26 typedef std::vector<Module *> ModuleCollection; 27 28 static ModuleCollection & 29 GetModuleCollection() 30 { 31 static ModuleCollection g_module_collection; 32 return g_module_collection; 33 } 34 35 Mutex & 36 Module::GetAllocationModuleCollectionMutex() 37 { 38 static Mutex g_module_collection_mutex(Mutex::eMutexTypeRecursive); 39 return g_module_collection_mutex; 40 } 41 42 size_t 43 Module::GetNumberAllocatedModules () 44 { 45 Mutex::Locker locker (GetAllocationModuleCollectionMutex()); 46 return GetModuleCollection().size(); 47 } 48 49 Module * 50 Module::GetAllocatedModuleAtIndex (size_t idx) 51 { 52 Mutex::Locker locker (GetAllocationModuleCollectionMutex()); 53 ModuleCollection &modules = GetModuleCollection(); 54 if (idx < modules.size()) 55 return modules[idx]; 56 return NULL; 57 } 58 59 60 61 62 Module::Module(const FileSpec& file_spec, const ArchSpec& arch, const ConstString *object_name, off_t object_offset) : 63 m_mutex (Mutex::eMutexTypeRecursive), 64 m_mod_time (file_spec.GetModificationTime()), 65 m_arch (arch), 66 m_uuid (), 67 m_file (file_spec), 68 m_platform_file(), 69 m_object_name (), 70 m_object_offset (object_offset), 71 m_objfile_ap (), 72 m_symfile_ap (), 73 m_ast (), 74 m_did_load_objfile (false), 75 m_did_load_symbol_vendor (false), 76 m_did_parse_uuid (false), 77 m_did_init_ast (false), 78 m_is_dynamic_loader_module (false) 79 { 80 // Scope for locker below... 81 { 82 Mutex::Locker locker (GetAllocationModuleCollectionMutex()); 83 GetModuleCollection().push_back(this); 84 } 85 86 if (object_name) 87 m_object_name = *object_name; 88 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); 89 if (log) 90 log->Printf ("%p Module::Module((%s) '%s/%s%s%s%s')", 91 this, 92 m_arch.GetArchitectureName(), 93 m_file.GetDirectory().AsCString(""), 94 m_file.GetFilename().AsCString(""), 95 m_object_name.IsEmpty() ? "" : "(", 96 m_object_name.IsEmpty() ? "" : m_object_name.AsCString(""), 97 m_object_name.IsEmpty() ? "" : ")"); 98 } 99 100 Module::~Module() 101 { 102 // Scope for locker below... 103 { 104 Mutex::Locker locker (GetAllocationModuleCollectionMutex()); 105 ModuleCollection &modules = GetModuleCollection(); 106 ModuleCollection::iterator end = modules.end(); 107 ModuleCollection::iterator pos = std::find(modules.begin(), end, this); 108 if (pos != end) 109 modules.erase(pos); 110 } 111 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); 112 if (log) 113 log->Printf ("%p Module::~Module((%s) '%s/%s%s%s%s')", 114 this, 115 m_arch.GetArchitectureName(), 116 m_file.GetDirectory().AsCString(""), 117 m_file.GetFilename().AsCString(""), 118 m_object_name.IsEmpty() ? "" : "(", 119 m_object_name.IsEmpty() ? "" : m_object_name.AsCString(""), 120 m_object_name.IsEmpty() ? "" : ")"); 121 // Release any auto pointers before we start tearing down our member 122 // variables since the object file and symbol files might need to make 123 // function calls back into this module object. The ordering is important 124 // here because symbol files can require the module object file. So we tear 125 // down the symbol file first, then the object file. 126 m_symfile_ap.reset(); 127 m_objfile_ap.reset(); 128 } 129 130 131 ModuleSP 132 Module::GetSP () const 133 { 134 return ModuleList::GetModuleSP (this); 135 } 136 137 const lldb_private::UUID& 138 Module::GetUUID() 139 { 140 Mutex::Locker locker (m_mutex); 141 if (m_did_parse_uuid == false) 142 { 143 ObjectFile * obj_file = GetObjectFile (); 144 145 if (obj_file != NULL) 146 { 147 obj_file->GetUUID(&m_uuid); 148 m_did_parse_uuid = true; 149 } 150 } 151 return m_uuid; 152 } 153 154 ClangASTContext & 155 Module::GetClangASTContext () 156 { 157 Mutex::Locker locker (m_mutex); 158 if (m_did_init_ast == false) 159 { 160 ObjectFile * objfile = GetObjectFile(); 161 ArchSpec object_arch; 162 if (objfile && objfile->GetArchitecture(object_arch)) 163 { 164 m_did_init_ast = true; 165 m_ast.SetArchitecture (object_arch); 166 } 167 } 168 return m_ast; 169 } 170 171 void 172 Module::ParseAllDebugSymbols() 173 { 174 Mutex::Locker locker (m_mutex); 175 uint32_t num_comp_units = GetNumCompileUnits(); 176 if (num_comp_units == 0) 177 return; 178 179 TargetSP null_target; 180 SymbolContext sc(null_target, GetSP()); 181 uint32_t cu_idx; 182 SymbolVendor *symbols = GetSymbolVendor (); 183 184 for (cu_idx = 0; cu_idx < num_comp_units; cu_idx++) 185 { 186 sc.comp_unit = symbols->GetCompileUnitAtIndex(cu_idx).get(); 187 if (sc.comp_unit) 188 { 189 sc.function = NULL; 190 symbols->ParseVariablesForContext(sc); 191 192 symbols->ParseCompileUnitFunctions(sc); 193 194 uint32_t func_idx; 195 for (func_idx = 0; (sc.function = sc.comp_unit->GetFunctionAtIndex(func_idx).get()) != NULL; ++func_idx) 196 { 197 symbols->ParseFunctionBlocks(sc); 198 199 // Parse the variables for this function and all its blocks 200 symbols->ParseVariablesForContext(sc); 201 } 202 203 204 // Parse all types for this compile unit 205 sc.function = NULL; 206 symbols->ParseTypes(sc); 207 } 208 } 209 } 210 211 void 212 Module::CalculateSymbolContext(SymbolContext* sc) 213 { 214 sc->module_sp = GetSP(); 215 } 216 217 Module * 218 Module::CalculateSymbolContextModule () 219 { 220 return this; 221 } 222 223 void 224 Module::DumpSymbolContext(Stream *s) 225 { 226 s->Printf(", Module{0x%8.8x}", this); 227 } 228 229 uint32_t 230 Module::GetNumCompileUnits() 231 { 232 Mutex::Locker locker (m_mutex); 233 Timer scoped_timer(__PRETTY_FUNCTION__, "Module::GetNumCompileUnits (module = %p)", this); 234 SymbolVendor *symbols = GetSymbolVendor (); 235 if (symbols) 236 return symbols->GetNumCompileUnits(); 237 return 0; 238 } 239 240 CompUnitSP 241 Module::GetCompileUnitAtIndex (uint32_t index) 242 { 243 Mutex::Locker locker (m_mutex); 244 uint32_t num_comp_units = GetNumCompileUnits (); 245 CompUnitSP cu_sp; 246 247 if (index < num_comp_units) 248 { 249 SymbolVendor *symbols = GetSymbolVendor (); 250 if (symbols) 251 cu_sp = symbols->GetCompileUnitAtIndex(index); 252 } 253 return cu_sp; 254 } 255 256 bool 257 Module::ResolveFileAddress (lldb::addr_t vm_addr, Address& so_addr) 258 { 259 Mutex::Locker locker (m_mutex); 260 Timer scoped_timer(__PRETTY_FUNCTION__, "Module::ResolveFileAddress (vm_addr = 0x%llx)", vm_addr); 261 ObjectFile* ofile = GetObjectFile(); 262 if (ofile) 263 return so_addr.ResolveAddressUsingFileSections(vm_addr, ofile->GetSectionList()); 264 return false; 265 } 266 267 uint32_t 268 Module::ResolveSymbolContextForAddress (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc) 269 { 270 Mutex::Locker locker (m_mutex); 271 uint32_t resolved_flags = 0; 272 273 // Clear the result symbol context in case we don't find anything 274 sc.Clear(); 275 276 // Get the section from the section/offset address. 277 const Section *section = so_addr.GetSection(); 278 279 // Make sure the section matches this module before we try and match anything 280 if (section && section->GetModule() == this) 281 { 282 // If the section offset based address resolved itself, then this 283 // is the right module. 284 sc.module_sp = GetSP(); 285 resolved_flags |= eSymbolContextModule; 286 287 // Resolve the compile unit, function, block, line table or line 288 // entry if requested. 289 if (resolve_scope & eSymbolContextCompUnit || 290 resolve_scope & eSymbolContextFunction || 291 resolve_scope & eSymbolContextBlock || 292 resolve_scope & eSymbolContextLineEntry ) 293 { 294 SymbolVendor *symbols = GetSymbolVendor (); 295 if (symbols) 296 resolved_flags |= symbols->ResolveSymbolContext (so_addr, resolve_scope, sc); 297 } 298 299 // Resolve the symbol if requested, but don't re-look it up if we've already found it. 300 if (resolve_scope & eSymbolContextSymbol && !(resolved_flags & eSymbolContextSymbol)) 301 { 302 ObjectFile* ofile = GetObjectFile(); 303 if (ofile) 304 { 305 Symtab *symtab = ofile->GetSymtab(); 306 if (symtab) 307 { 308 if (so_addr.IsSectionOffset()) 309 { 310 sc.symbol = symtab->FindSymbolContainingFileAddress(so_addr.GetFileAddress()); 311 if (sc.symbol) 312 resolved_flags |= eSymbolContextSymbol; 313 } 314 } 315 } 316 } 317 } 318 return resolved_flags; 319 } 320 321 uint32_t 322 Module::ResolveSymbolContextForFilePath 323 ( 324 const char *file_path, 325 uint32_t line, 326 bool check_inlines, 327 uint32_t resolve_scope, 328 SymbolContextList& sc_list 329 ) 330 { 331 FileSpec file_spec(file_path, false); 332 return ResolveSymbolContextsForFileSpec (file_spec, line, check_inlines, resolve_scope, sc_list); 333 } 334 335 uint32_t 336 Module::ResolveSymbolContextsForFileSpec (const FileSpec &file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list) 337 { 338 Mutex::Locker locker (m_mutex); 339 Timer scoped_timer(__PRETTY_FUNCTION__, 340 "Module::ResolveSymbolContextForFilePath (%s%s%s:%u, check_inlines = %s, resolve_scope = 0x%8.8x)", 341 file_spec.GetDirectory().AsCString(""), 342 file_spec.GetDirectory() ? "/" : "", 343 file_spec.GetFilename().AsCString(""), 344 line, 345 check_inlines ? "yes" : "no", 346 resolve_scope); 347 348 const uint32_t initial_count = sc_list.GetSize(); 349 350 SymbolVendor *symbols = GetSymbolVendor (); 351 if (symbols) 352 symbols->ResolveSymbolContext (file_spec, line, check_inlines, resolve_scope, sc_list); 353 354 return sc_list.GetSize() - initial_count; 355 } 356 357 358 uint32_t 359 Module::FindGlobalVariables(const ConstString &name, bool append, uint32_t max_matches, VariableList& variables) 360 { 361 SymbolVendor *symbols = GetSymbolVendor (); 362 if (symbols) 363 return symbols->FindGlobalVariables(name, append, max_matches, variables); 364 return 0; 365 } 366 uint32_t 367 Module::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables) 368 { 369 SymbolVendor *symbols = GetSymbolVendor (); 370 if (symbols) 371 return symbols->FindGlobalVariables(regex, append, max_matches, variables); 372 return 0; 373 } 374 375 uint32_t 376 Module::FindCompileUnits (const FileSpec &path, 377 bool append, 378 SymbolContextList &sc_list) 379 { 380 if (!append) 381 sc_list.Clear(); 382 383 const uint32_t start_size = sc_list.GetSize(); 384 const uint32_t num_compile_units = GetNumCompileUnits(); 385 SymbolContext sc; 386 sc.module_sp = GetSP(); 387 const bool compare_directory = path.GetDirectory(); 388 for (uint32_t i=0; i<num_compile_units; ++i) 389 { 390 sc.comp_unit = GetCompileUnitAtIndex(i).get(); 391 if (FileSpec::Equal (*sc.comp_unit, path, compare_directory)) 392 sc_list.Append(sc); 393 } 394 return sc_list.GetSize() - start_size; 395 } 396 397 uint32_t 398 Module::FindFunctions (const ConstString &name, 399 uint32_t name_type_mask, 400 bool include_symbols, 401 bool append, 402 SymbolContextList& sc_list) 403 { 404 if (!append) 405 sc_list.Clear(); 406 407 const uint32_t start_size = sc_list.GetSize(); 408 409 // Find all the functions (not symbols, but debug information functions... 410 SymbolVendor *symbols = GetSymbolVendor (); 411 if (symbols) 412 symbols->FindFunctions(name, name_type_mask, append, sc_list); 413 414 // Now check our symbol table for symbols that are code symbols if requested 415 if (include_symbols) 416 { 417 ObjectFile *objfile = GetObjectFile(); 418 if (objfile) 419 { 420 Symtab *symtab = objfile->GetSymtab(); 421 if (symtab) 422 { 423 std::vector<uint32_t> symbol_indexes; 424 symtab->FindAllSymbolsWithNameAndType (name, eSymbolTypeCode, Symtab::eDebugAny, Symtab::eVisibilityAny, symbol_indexes); 425 const uint32_t num_matches = symbol_indexes.size(); 426 if (num_matches) 427 { 428 const bool merge_symbol_into_function = true; 429 SymbolContext sc(this); 430 for (uint32_t i=0; i<num_matches; i++) 431 { 432 sc.symbol = symtab->SymbolAtIndex(symbol_indexes[i]); 433 sc_list.AppendIfUnique (sc, merge_symbol_into_function); 434 } 435 } 436 } 437 } 438 } 439 return sc_list.GetSize() - start_size; 440 } 441 442 uint32_t 443 Module::FindFunctions (const RegularExpression& regex, 444 bool include_symbols, 445 bool append, 446 SymbolContextList& sc_list) 447 { 448 if (!append) 449 sc_list.Clear(); 450 451 const uint32_t start_size = sc_list.GetSize(); 452 453 SymbolVendor *symbols = GetSymbolVendor (); 454 if (symbols) 455 symbols->FindFunctions(regex, append, sc_list); 456 // Now check our symbol table for symbols that are code symbols if requested 457 if (include_symbols) 458 { 459 ObjectFile *objfile = GetObjectFile(); 460 if (objfile) 461 { 462 Symtab *symtab = objfile->GetSymtab(); 463 if (symtab) 464 { 465 std::vector<uint32_t> symbol_indexes; 466 symtab->AppendSymbolIndexesMatchingRegExAndType (regex, eSymbolTypeCode, Symtab::eDebugAny, Symtab::eVisibilityAny, symbol_indexes); 467 const uint32_t num_matches = symbol_indexes.size(); 468 if (num_matches) 469 { 470 const bool merge_symbol_into_function = true; 471 SymbolContext sc(this); 472 for (uint32_t i=0; i<num_matches; i++) 473 { 474 sc.symbol = symtab->SymbolAtIndex(symbol_indexes[i]); 475 sc_list.AppendIfUnique (sc, merge_symbol_into_function); 476 } 477 } 478 } 479 } 480 } 481 return sc_list.GetSize() - start_size; 482 } 483 484 uint32_t 485 Module::FindTypes_Impl (const SymbolContext& sc, const ConstString &name, bool append, uint32_t max_matches, TypeList& types) 486 { 487 Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__); 488 if (sc.module_sp.get() == NULL || sc.module_sp.get() == this) 489 { 490 SymbolVendor *symbols = GetSymbolVendor (); 491 if (symbols) 492 return symbols->FindTypes(sc, name, append, max_matches, types); 493 } 494 return 0; 495 } 496 497 // depending on implementation details, type lookup might fail because of 498 // embedded spurious namespace:: prefixes. this call strips them, paying 499 // attention to the fact that a type might have namespace'd type names as 500 // arguments to templates, and those must not be stripped off 501 static const char* 502 StripTypeName(const char* name_cstr) 503 { 504 const char* skip_namespace = strstr(name_cstr, "::"); 505 const char* template_arg_char = strchr(name_cstr, '<'); 506 while (skip_namespace != NULL) 507 { 508 if (template_arg_char != NULL && 509 skip_namespace > template_arg_char) // but namespace'd template arguments are still good to go 510 break; 511 name_cstr = skip_namespace+2; 512 skip_namespace = strstr(name_cstr, "::"); 513 } 514 return name_cstr; 515 } 516 517 uint32_t 518 Module::FindTypes (const SymbolContext& sc, const ConstString &name, bool append, uint32_t max_matches, TypeList& types) 519 { 520 uint32_t retval = FindTypes_Impl(sc, name, append, max_matches, types); 521 522 if (retval == 0) 523 { 524 const char *stripped = StripTypeName(name.GetCString()); 525 return FindTypes_Impl(sc, ConstString(stripped), append, max_matches, types); 526 } 527 else 528 return retval; 529 530 } 531 532 //uint32_t 533 //Module::FindTypes(const SymbolContext& sc, const RegularExpression& regex, bool append, uint32_t max_matches, Type::Encoding encoding, const char *udt_name, TypeList& types) 534 //{ 535 // Timer scoped_timer(__PRETTY_FUNCTION__); 536 // SymbolVendor *symbols = GetSymbolVendor (); 537 // if (symbols) 538 // return symbols->FindTypes(sc, regex, append, max_matches, encoding, udt_name, types); 539 // return 0; 540 // 541 //} 542 543 SymbolVendor* 544 Module::GetSymbolVendor (bool can_create) 545 { 546 Mutex::Locker locker (m_mutex); 547 if (m_did_load_symbol_vendor == false && can_create) 548 { 549 ObjectFile *obj_file = GetObjectFile (); 550 if (obj_file != NULL) 551 { 552 Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__); 553 m_symfile_ap.reset(SymbolVendor::FindPlugin(this)); 554 m_did_load_symbol_vendor = true; 555 } 556 } 557 return m_symfile_ap.get(); 558 } 559 560 void 561 Module::SetFileSpecAndObjectName (const FileSpec &file, const ConstString &object_name) 562 { 563 // Container objects whose paths do not specify a file directly can call 564 // this function to correct the file and object names. 565 m_file = file; 566 m_mod_time = file.GetModificationTime(); 567 m_object_name = object_name; 568 } 569 570 const ArchSpec& 571 Module::GetArchitecture () const 572 { 573 return m_arch; 574 } 575 576 void 577 Module::GetDescription (Stream *s) 578 { 579 Mutex::Locker locker (m_mutex); 580 581 if (m_arch.IsValid()) 582 s->Printf("(%s) ", m_arch.GetArchitectureName()); 583 584 char path[PATH_MAX]; 585 if (m_file.GetPath(path, sizeof(path))) 586 s->PutCString(path); 587 588 const char *object_name = m_object_name.GetCString(); 589 if (object_name) 590 s->Printf("(%s)", object_name); 591 } 592 593 void 594 Module::Dump(Stream *s) 595 { 596 Mutex::Locker locker (m_mutex); 597 //s->Printf("%.*p: ", (int)sizeof(void*) * 2, this); 598 s->Indent(); 599 s->Printf("Module %s/%s%s%s%s\n", 600 m_file.GetDirectory().AsCString(), 601 m_file.GetFilename().AsCString(), 602 m_object_name ? "(" : "", 603 m_object_name ? m_object_name.GetCString() : "", 604 m_object_name ? ")" : ""); 605 606 s->IndentMore(); 607 ObjectFile *objfile = GetObjectFile (); 608 609 if (objfile) 610 objfile->Dump(s); 611 612 SymbolVendor *symbols = GetSymbolVendor (); 613 614 if (symbols) 615 symbols->Dump(s); 616 617 s->IndentLess(); 618 } 619 620 621 TypeList* 622 Module::GetTypeList () 623 { 624 SymbolVendor *symbols = GetSymbolVendor (); 625 if (symbols) 626 return &symbols->GetTypeList(); 627 return NULL; 628 } 629 630 const ConstString & 631 Module::GetObjectName() const 632 { 633 return m_object_name; 634 } 635 636 ObjectFile * 637 Module::GetObjectFile() 638 { 639 Mutex::Locker locker (m_mutex); 640 if (m_did_load_objfile == false) 641 { 642 m_did_load_objfile = true; 643 Timer scoped_timer(__PRETTY_FUNCTION__, 644 "Module::GetObjectFile () module = %s", GetFileSpec().GetFilename().AsCString("")); 645 m_objfile_ap.reset(ObjectFile::FindPlugin(this, &m_file, m_object_offset, m_file.GetByteSize())); 646 } 647 return m_objfile_ap.get(); 648 } 649 650 651 const Symbol * 652 Module::FindFirstSymbolWithNameAndType (const ConstString &name, SymbolType symbol_type) 653 { 654 Timer scoped_timer(__PRETTY_FUNCTION__, 655 "Module::FindFirstSymbolWithNameAndType (name = %s, type = %i)", 656 name.AsCString(), 657 symbol_type); 658 ObjectFile *objfile = GetObjectFile(); 659 if (objfile) 660 { 661 Symtab *symtab = objfile->GetSymtab(); 662 if (symtab) 663 return symtab->FindFirstSymbolWithNameAndType (name, symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny); 664 } 665 return NULL; 666 } 667 void 668 Module::SymbolIndicesToSymbolContextList (Symtab *symtab, std::vector<uint32_t> &symbol_indexes, SymbolContextList &sc_list) 669 { 670 // No need to protect this call using m_mutex all other method calls are 671 // already thread safe. 672 673 size_t num_indices = symbol_indexes.size(); 674 if (num_indices > 0) 675 { 676 SymbolContext sc; 677 CalculateSymbolContext (&sc); 678 for (size_t i = 0; i < num_indices; i++) 679 { 680 sc.symbol = symtab->SymbolAtIndex (symbol_indexes[i]); 681 if (sc.symbol) 682 sc_list.Append (sc); 683 } 684 } 685 } 686 687 size_t 688 Module::FindSymbolsWithNameAndType (const ConstString &name, SymbolType symbol_type, SymbolContextList &sc_list) 689 { 690 // No need to protect this call using m_mutex all other method calls are 691 // already thread safe. 692 693 694 Timer scoped_timer(__PRETTY_FUNCTION__, 695 "Module::FindSymbolsWithNameAndType (name = %s, type = %i)", 696 name.AsCString(), 697 symbol_type); 698 const size_t initial_size = sc_list.GetSize(); 699 ObjectFile *objfile = GetObjectFile (); 700 if (objfile) 701 { 702 Symtab *symtab = objfile->GetSymtab(); 703 if (symtab) 704 { 705 std::vector<uint32_t> symbol_indexes; 706 symtab->FindAllSymbolsWithNameAndType (name, symbol_type, symbol_indexes); 707 SymbolIndicesToSymbolContextList (symtab, symbol_indexes, sc_list); 708 } 709 } 710 return sc_list.GetSize() - initial_size; 711 } 712 713 size_t 714 Module::FindSymbolsMatchingRegExAndType (const RegularExpression ®ex, SymbolType symbol_type, SymbolContextList &sc_list) 715 { 716 // No need to protect this call using m_mutex all other method calls are 717 // already thread safe. 718 719 Timer scoped_timer(__PRETTY_FUNCTION__, 720 "Module::FindSymbolsMatchingRegExAndType (regex = %s, type = %i)", 721 regex.GetText(), 722 symbol_type); 723 const size_t initial_size = sc_list.GetSize(); 724 ObjectFile *objfile = GetObjectFile (); 725 if (objfile) 726 { 727 Symtab *symtab = objfile->GetSymtab(); 728 if (symtab) 729 { 730 std::vector<uint32_t> symbol_indexes; 731 symtab->FindAllSymbolsMatchingRexExAndType (regex, symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny, symbol_indexes); 732 SymbolIndicesToSymbolContextList (symtab, symbol_indexes, sc_list); 733 } 734 } 735 return sc_list.GetSize() - initial_size; 736 } 737 738 const TimeValue & 739 Module::GetModificationTime () const 740 { 741 return m_mod_time; 742 } 743 744 bool 745 Module::IsExecutable () 746 { 747 if (GetObjectFile() == NULL) 748 return false; 749 else 750 return GetObjectFile()->IsExecutable(); 751 } 752 753 bool 754 Module::IsLoadedInTarget (Target *target) 755 { 756 ObjectFile *obj_file = GetObjectFile(); 757 if (obj_file) 758 { 759 SectionList *sections = obj_file->GetSectionList(); 760 if (sections != NULL) 761 { 762 size_t num_sections = sections->GetSize(); 763 for (size_t sect_idx = 0; sect_idx < num_sections; sect_idx++) 764 { 765 SectionSP section_sp = sections->GetSectionAtIndex(sect_idx); 766 if (section_sp->GetLoadBaseAddress(target) != LLDB_INVALID_ADDRESS) 767 { 768 return true; 769 } 770 } 771 } 772 } 773 return false; 774 } 775 bool 776 Module::SetArchitecture (const ArchSpec &new_arch) 777 { 778 if (!m_arch.IsValid()) 779 { 780 m_arch = new_arch; 781 return true; 782 } 783 return m_arch == new_arch; 784 } 785 786