Module.cpp revision 1d3db0a71f507df5158eb160aaceefb6dd5f38c2
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/lldb-python.h" 11 12#include "lldb/Core/Error.h" 13#include "lldb/Core/Module.h" 14#include "lldb/Core/DataBuffer.h" 15#include "lldb/Core/DataBufferHeap.h" 16#include "lldb/Core/Log.h" 17#include "lldb/Core/ModuleList.h" 18#include "lldb/Core/ModuleSpec.h" 19#include "lldb/Core/RegularExpression.h" 20#include "lldb/Core/Section.h" 21#include "lldb/Core/StreamString.h" 22#include "lldb/Core/Timer.h" 23#include "lldb/Host/Host.h" 24#include "lldb/Host/Symbols.h" 25#include "lldb/Interpreter/CommandInterpreter.h" 26#include "lldb/Interpreter/ScriptInterpreter.h" 27#include "lldb/lldb-private-log.h" 28#include "lldb/Symbol/CompileUnit.h" 29#include "lldb/Symbol/ObjectFile.h" 30#include "lldb/Symbol/SymbolContext.h" 31#include "lldb/Symbol/SymbolVendor.h" 32#include "lldb/Target/CPPLanguageRuntime.h" 33#include "lldb/Target/ObjCLanguageRuntime.h" 34#include "lldb/Target/Process.h" 35#include "lldb/Target/Target.h" 36 37using namespace lldb; 38using namespace lldb_private; 39 40// Shared pointers to modules track module lifetimes in 41// targets and in the global module, but this collection 42// will track all module objects that are still alive 43typedef std::vector<Module *> ModuleCollection; 44 45static ModuleCollection & 46GetModuleCollection() 47{ 48 // This module collection needs to live past any module, so we could either make it a 49 // shared pointer in each module or just leak is. Since it is only an empty vector by 50 // the time all the modules have gone away, we just leak it for now. If we decide this 51 // is a big problem we can introduce a Finalize method that will tear everything down in 52 // a predictable order. 53 54 static ModuleCollection *g_module_collection = NULL; 55 if (g_module_collection == NULL) 56 g_module_collection = new ModuleCollection(); 57 58 return *g_module_collection; 59} 60 61Mutex * 62Module::GetAllocationModuleCollectionMutex() 63{ 64 // NOTE: The mutex below must be leaked since the global module list in 65 // the ModuleList class will get torn at some point, and we can't know 66 // if it will tear itself down before the "g_module_collection_mutex" below 67 // will. So we leak a Mutex object below to safeguard against that 68 69 static Mutex *g_module_collection_mutex = NULL; 70 if (g_module_collection_mutex == NULL) 71 g_module_collection_mutex = new Mutex (Mutex::eMutexTypeRecursive); // NOTE: known leak 72 return g_module_collection_mutex; 73} 74 75size_t 76Module::GetNumberAllocatedModules () 77{ 78 Mutex::Locker locker (GetAllocationModuleCollectionMutex()); 79 return GetModuleCollection().size(); 80} 81 82Module * 83Module::GetAllocatedModuleAtIndex (size_t idx) 84{ 85 Mutex::Locker locker (GetAllocationModuleCollectionMutex()); 86 ModuleCollection &modules = GetModuleCollection(); 87 if (idx < modules.size()) 88 return modules[idx]; 89 return NULL; 90} 91#if 0 92 93// These functions help us to determine if modules are still loaded, yet don't require that 94// you have a command interpreter and can easily be called from an external debugger. 95namespace lldb { 96 97 void 98 ClearModuleInfo (void) 99 { 100 const bool mandatory = true; 101 ModuleList::RemoveOrphanSharedModules(mandatory); 102 } 103 104 void 105 DumpModuleInfo (void) 106 { 107 Mutex::Locker locker (Module::GetAllocationModuleCollectionMutex()); 108 ModuleCollection &modules = GetModuleCollection(); 109 const size_t count = modules.size(); 110 printf ("%s: %" PRIu64 " modules:\n", __PRETTY_FUNCTION__, (uint64_t)count); 111 for (size_t i=0; i<count; ++i) 112 { 113 114 StreamString strm; 115 Module *module = modules[i]; 116 const bool in_shared_module_list = ModuleList::ModuleIsInCache (module); 117 module->GetDescription(&strm, eDescriptionLevelFull); 118 printf ("%p: shared = %i, ref_count = %3u, module = %s\n", 119 module, 120 in_shared_module_list, 121 (uint32_t)module->use_count(), 122 strm.GetString().c_str()); 123 } 124 } 125} 126 127#endif 128 129Module::Module (const ModuleSpec &module_spec) : 130 m_mutex (Mutex::eMutexTypeRecursive), 131 m_mod_time (module_spec.GetFileSpec().GetModificationTime()), 132 m_arch (module_spec.GetArchitecture()), 133 m_uuid (), 134 m_file (module_spec.GetFileSpec()), 135 m_platform_file(module_spec.GetPlatformFileSpec()), 136 m_symfile_spec (module_spec.GetSymbolFileSpec()), 137 m_object_name (module_spec.GetObjectName()), 138 m_object_offset (module_spec.GetObjectOffset()), 139 m_object_mod_time (module_spec.GetObjectModificationTime()), 140 m_objfile_sp (), 141 m_symfile_ap (), 142 m_ast (), 143 m_source_mappings (), 144 m_did_load_objfile (false), 145 m_did_load_symbol_vendor (false), 146 m_did_parse_uuid (false), 147 m_did_init_ast (false), 148 m_is_dynamic_loader_module (false), 149 m_file_has_changed (false), 150 m_first_file_changed_log (false) 151{ 152 // Scope for locker below... 153 { 154 Mutex::Locker locker (GetAllocationModuleCollectionMutex()); 155 GetModuleCollection().push_back(this); 156 } 157 158 Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_OBJECT|LIBLLDB_LOG_MODULES)); 159 if (log) 160 log->Printf ("%p Module::Module((%s) '%s%s%s%s')", 161 this, 162 m_arch.GetArchitectureName(), 163 m_file.GetPath().c_str(), 164 m_object_name.IsEmpty() ? "" : "(", 165 m_object_name.IsEmpty() ? "" : m_object_name.AsCString(""), 166 m_object_name.IsEmpty() ? "" : ")"); 167} 168 169Module::Module(const FileSpec& file_spec, 170 const ArchSpec& arch, 171 const ConstString *object_name, 172 off_t object_offset, 173 const TimeValue *object_mod_time_ptr) : 174 m_mutex (Mutex::eMutexTypeRecursive), 175 m_mod_time (file_spec.GetModificationTime()), 176 m_arch (arch), 177 m_uuid (), 178 m_file (file_spec), 179 m_platform_file(), 180 m_symfile_spec (), 181 m_object_name (), 182 m_object_offset (object_offset), 183 m_object_mod_time (), 184 m_objfile_sp (), 185 m_symfile_ap (), 186 m_ast (), 187 m_source_mappings (), 188 m_did_load_objfile (false), 189 m_did_load_symbol_vendor (false), 190 m_did_parse_uuid (false), 191 m_did_init_ast (false), 192 m_is_dynamic_loader_module (false), 193 m_file_has_changed (false), 194 m_first_file_changed_log (false) 195{ 196 // Scope for locker below... 197 { 198 Mutex::Locker locker (GetAllocationModuleCollectionMutex()); 199 GetModuleCollection().push_back(this); 200 } 201 202 if (object_name) 203 m_object_name = *object_name; 204 205 if (object_mod_time_ptr) 206 m_object_mod_time = *object_mod_time_ptr; 207 208 Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_OBJECT|LIBLLDB_LOG_MODULES)); 209 if (log) 210 log->Printf ("%p Module::Module((%s) '%s%s%s%s')", 211 this, 212 m_arch.GetArchitectureName(), 213 m_file.GetPath().c_str(), 214 m_object_name.IsEmpty() ? "" : "(", 215 m_object_name.IsEmpty() ? "" : m_object_name.AsCString(""), 216 m_object_name.IsEmpty() ? "" : ")"); 217} 218 219Module::~Module() 220{ 221 // Scope for locker below... 222 { 223 Mutex::Locker locker (GetAllocationModuleCollectionMutex()); 224 ModuleCollection &modules = GetModuleCollection(); 225 ModuleCollection::iterator end = modules.end(); 226 ModuleCollection::iterator pos = std::find(modules.begin(), end, this); 227 assert (pos != end); 228 modules.erase(pos); 229 } 230 Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_OBJECT|LIBLLDB_LOG_MODULES)); 231 if (log) 232 log->Printf ("%p Module::~Module((%s) '%s%s%s%s')", 233 this, 234 m_arch.GetArchitectureName(), 235 m_file.GetPath().c_str(), 236 m_object_name.IsEmpty() ? "" : "(", 237 m_object_name.IsEmpty() ? "" : m_object_name.AsCString(""), 238 m_object_name.IsEmpty() ? "" : ")"); 239 // Release any auto pointers before we start tearing down our member 240 // variables since the object file and symbol files might need to make 241 // function calls back into this module object. The ordering is important 242 // here because symbol files can require the module object file. So we tear 243 // down the symbol file first, then the object file. 244 m_symfile_ap.reset(); 245 m_objfile_sp.reset(); 246} 247 248ObjectFile * 249Module::GetMemoryObjectFile (const lldb::ProcessSP &process_sp, lldb::addr_t header_addr, Error &error) 250{ 251 if (m_objfile_sp) 252 { 253 error.SetErrorString ("object file already exists"); 254 } 255 else 256 { 257 Mutex::Locker locker (m_mutex); 258 if (process_sp) 259 { 260 m_did_load_objfile = true; 261 std::unique_ptr<DataBufferHeap> data_ap (new DataBufferHeap (512, 0)); 262 Error readmem_error; 263 const size_t bytes_read = process_sp->ReadMemory (header_addr, 264 data_ap->GetBytes(), 265 data_ap->GetByteSize(), 266 readmem_error); 267 if (bytes_read == 512) 268 { 269 DataBufferSP data_sp(data_ap.release()); 270 m_objfile_sp = ObjectFile::FindPlugin(shared_from_this(), process_sp, header_addr, data_sp); 271 if (m_objfile_sp) 272 { 273 StreamString s; 274 s.Printf("0x%16.16" PRIx64, header_addr); 275 m_object_name.SetCString (s.GetData()); 276 277 // Once we get the object file, update our module with the object file's 278 // architecture since it might differ in vendor/os if some parts were 279 // unknown. 280 m_objfile_sp->GetArchitecture (m_arch); 281 } 282 else 283 { 284 error.SetErrorString ("unable to find suitable object file plug-in"); 285 } 286 } 287 else 288 { 289 error.SetErrorStringWithFormat ("unable to read header from memory: %s", readmem_error.AsCString()); 290 } 291 } 292 else 293 { 294 error.SetErrorString ("invalid process"); 295 } 296 } 297 return m_objfile_sp.get(); 298} 299 300 301const lldb_private::UUID& 302Module::GetUUID() 303{ 304 Mutex::Locker locker (m_mutex); 305 if (m_did_parse_uuid == false) 306 { 307 ObjectFile * obj_file = GetObjectFile (); 308 309 if (obj_file != NULL) 310 { 311 obj_file->GetUUID(&m_uuid); 312 m_did_parse_uuid = true; 313 } 314 } 315 return m_uuid; 316} 317 318ClangASTContext & 319Module::GetClangASTContext () 320{ 321 Mutex::Locker locker (m_mutex); 322 if (m_did_init_ast == false) 323 { 324 ObjectFile * objfile = GetObjectFile(); 325 ArchSpec object_arch; 326 if (objfile && objfile->GetArchitecture(object_arch)) 327 { 328 m_did_init_ast = true; 329 330 // LLVM wants this to be set to iOS or MacOSX; if we're working on 331 // a bare-boards type image, change the triple for llvm's benefit. 332 if (object_arch.GetTriple().getVendor() == llvm::Triple::Apple 333 && object_arch.GetTriple().getOS() == llvm::Triple::UnknownOS) 334 { 335 if (object_arch.GetTriple().getArch() == llvm::Triple::arm || 336 object_arch.GetTriple().getArch() == llvm::Triple::thumb) 337 { 338 object_arch.GetTriple().setOS(llvm::Triple::IOS); 339 } 340 else 341 { 342 object_arch.GetTriple().setOS(llvm::Triple::MacOSX); 343 } 344 } 345 m_ast.SetArchitecture (object_arch); 346 } 347 } 348 return m_ast; 349} 350 351void 352Module::ParseAllDebugSymbols() 353{ 354 Mutex::Locker locker (m_mutex); 355 size_t num_comp_units = GetNumCompileUnits(); 356 if (num_comp_units == 0) 357 return; 358 359 SymbolContext sc; 360 sc.module_sp = shared_from_this(); 361 SymbolVendor *symbols = GetSymbolVendor (); 362 363 for (size_t cu_idx = 0; cu_idx < num_comp_units; cu_idx++) 364 { 365 sc.comp_unit = symbols->GetCompileUnitAtIndex(cu_idx).get(); 366 if (sc.comp_unit) 367 { 368 sc.function = NULL; 369 symbols->ParseVariablesForContext(sc); 370 371 symbols->ParseCompileUnitFunctions(sc); 372 373 for (size_t func_idx = 0; (sc.function = sc.comp_unit->GetFunctionAtIndex(func_idx).get()) != NULL; ++func_idx) 374 { 375 symbols->ParseFunctionBlocks(sc); 376 377 // Parse the variables for this function and all its blocks 378 symbols->ParseVariablesForContext(sc); 379 } 380 381 382 // Parse all types for this compile unit 383 sc.function = NULL; 384 symbols->ParseTypes(sc); 385 } 386 } 387} 388 389void 390Module::CalculateSymbolContext(SymbolContext* sc) 391{ 392 sc->module_sp = shared_from_this(); 393} 394 395ModuleSP 396Module::CalculateSymbolContextModule () 397{ 398 return shared_from_this(); 399} 400 401void 402Module::DumpSymbolContext(Stream *s) 403{ 404 s->Printf(", Module{%p}", this); 405} 406 407size_t 408Module::GetNumCompileUnits() 409{ 410 Mutex::Locker locker (m_mutex); 411 Timer scoped_timer(__PRETTY_FUNCTION__, "Module::GetNumCompileUnits (module = %p)", this); 412 SymbolVendor *symbols = GetSymbolVendor (); 413 if (symbols) 414 return symbols->GetNumCompileUnits(); 415 return 0; 416} 417 418CompUnitSP 419Module::GetCompileUnitAtIndex (size_t index) 420{ 421 Mutex::Locker locker (m_mutex); 422 size_t num_comp_units = GetNumCompileUnits (); 423 CompUnitSP cu_sp; 424 425 if (index < num_comp_units) 426 { 427 SymbolVendor *symbols = GetSymbolVendor (); 428 if (symbols) 429 cu_sp = symbols->GetCompileUnitAtIndex(index); 430 } 431 return cu_sp; 432} 433 434bool 435Module::ResolveFileAddress (lldb::addr_t vm_addr, Address& so_addr) 436{ 437 Mutex::Locker locker (m_mutex); 438 Timer scoped_timer(__PRETTY_FUNCTION__, "Module::ResolveFileAddress (vm_addr = 0x%" PRIx64 ")", vm_addr); 439 ObjectFile* ofile = GetObjectFile(); 440 if (ofile) 441 return so_addr.ResolveAddressUsingFileSections(vm_addr, ofile->GetSectionList()); 442 return false; 443} 444 445uint32_t 446Module::ResolveSymbolContextForAddress (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc) 447{ 448 Mutex::Locker locker (m_mutex); 449 uint32_t resolved_flags = 0; 450 451 // Clear the result symbol context in case we don't find anything, but don't clear the target 452 sc.Clear(false); 453 454 // Get the section from the section/offset address. 455 SectionSP section_sp (so_addr.GetSection()); 456 457 // Make sure the section matches this module before we try and match anything 458 if (section_sp && section_sp->GetModule().get() == this) 459 { 460 // If the section offset based address resolved itself, then this 461 // is the right module. 462 sc.module_sp = shared_from_this(); 463 resolved_flags |= eSymbolContextModule; 464 465 // Resolve the compile unit, function, block, line table or line 466 // entry if requested. 467 if (resolve_scope & eSymbolContextCompUnit || 468 resolve_scope & eSymbolContextFunction || 469 resolve_scope & eSymbolContextBlock || 470 resolve_scope & eSymbolContextLineEntry ) 471 { 472 SymbolVendor *symbols = GetSymbolVendor (); 473 if (symbols) 474 resolved_flags |= symbols->ResolveSymbolContext (so_addr, resolve_scope, sc); 475 } 476 477 // Resolve the symbol if requested, but don't re-look it up if we've already found it. 478 if (resolve_scope & eSymbolContextSymbol && !(resolved_flags & eSymbolContextSymbol)) 479 { 480 ObjectFile* ofile = GetObjectFile(); 481 if (ofile) 482 { 483 Symtab *symtab = ofile->GetSymtab(); 484 if (symtab) 485 { 486 if (so_addr.IsSectionOffset()) 487 { 488 sc.symbol = symtab->FindSymbolContainingFileAddress(so_addr.GetFileAddress()); 489 if (sc.symbol) 490 resolved_flags |= eSymbolContextSymbol; 491 } 492 } 493 } 494 } 495 } 496 return resolved_flags; 497} 498 499uint32_t 500Module::ResolveSymbolContextForFilePath 501( 502 const char *file_path, 503 uint32_t line, 504 bool check_inlines, 505 uint32_t resolve_scope, 506 SymbolContextList& sc_list 507) 508{ 509 FileSpec file_spec(file_path, false); 510 return ResolveSymbolContextsForFileSpec (file_spec, line, check_inlines, resolve_scope, sc_list); 511} 512 513uint32_t 514Module::ResolveSymbolContextsForFileSpec (const FileSpec &file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list) 515{ 516 Mutex::Locker locker (m_mutex); 517 Timer scoped_timer(__PRETTY_FUNCTION__, 518 "Module::ResolveSymbolContextForFilePath (%s:%u, check_inlines = %s, resolve_scope = 0x%8.8x)", 519 file_spec.GetPath().c_str(), 520 line, 521 check_inlines ? "yes" : "no", 522 resolve_scope); 523 524 const uint32_t initial_count = sc_list.GetSize(); 525 526 SymbolVendor *symbols = GetSymbolVendor (); 527 if (symbols) 528 symbols->ResolveSymbolContext (file_spec, line, check_inlines, resolve_scope, sc_list); 529 530 return sc_list.GetSize() - initial_count; 531} 532 533 534size_t 535Module::FindGlobalVariables (const ConstString &name, 536 const ClangNamespaceDecl *namespace_decl, 537 bool append, 538 size_t max_matches, 539 VariableList& variables) 540{ 541 SymbolVendor *symbols = GetSymbolVendor (); 542 if (symbols) 543 return symbols->FindGlobalVariables(name, namespace_decl, append, max_matches, variables); 544 return 0; 545} 546 547size_t 548Module::FindGlobalVariables (const RegularExpression& regex, 549 bool append, 550 size_t max_matches, 551 VariableList& variables) 552{ 553 SymbolVendor *symbols = GetSymbolVendor (); 554 if (symbols) 555 return symbols->FindGlobalVariables(regex, append, max_matches, variables); 556 return 0; 557} 558 559size_t 560Module::FindCompileUnits (const FileSpec &path, 561 bool append, 562 SymbolContextList &sc_list) 563{ 564 if (!append) 565 sc_list.Clear(); 566 567 const size_t start_size = sc_list.GetSize(); 568 const size_t num_compile_units = GetNumCompileUnits(); 569 SymbolContext sc; 570 sc.module_sp = shared_from_this(); 571 const bool compare_directory = path.GetDirectory(); 572 for (size_t i=0; i<num_compile_units; ++i) 573 { 574 sc.comp_unit = GetCompileUnitAtIndex(i).get(); 575 if (sc.comp_unit) 576 { 577 if (FileSpec::Equal (*sc.comp_unit, path, compare_directory)) 578 sc_list.Append(sc); 579 } 580 } 581 return sc_list.GetSize() - start_size; 582} 583 584size_t 585Module::FindFunctions (const ConstString &name, 586 const ClangNamespaceDecl *namespace_decl, 587 uint32_t name_type_mask, 588 bool include_symbols, 589 bool include_inlines, 590 bool append, 591 SymbolContextList& sc_list) 592{ 593 if (!append) 594 sc_list.Clear(); 595 596 const size_t old_size = sc_list.GetSize(); 597 598 // Find all the functions (not symbols, but debug information functions... 599 SymbolVendor *symbols = GetSymbolVendor (); 600 601 if (name_type_mask & eFunctionNameTypeAuto) 602 { 603 ConstString lookup_name; 604 uint32_t lookup_name_type_mask = 0; 605 bool match_name_after_lookup = false; 606 Module::PrepareForFunctionNameLookup (name, 607 name_type_mask, 608 lookup_name, 609 lookup_name_type_mask, 610 match_name_after_lookup); 611 612 if (symbols) 613 symbols->FindFunctions(lookup_name, 614 namespace_decl, 615 lookup_name_type_mask, 616 include_inlines, 617 append, 618 sc_list); 619 620 // Now check our symbol table for symbols that are code symbols if requested 621 if (include_symbols) 622 { 623 ObjectFile *objfile = GetObjectFile(); 624 if (objfile) 625 { 626 Symtab *symtab = objfile->GetSymtab(); 627 if (symtab) 628 symtab->FindFunctionSymbols(lookup_name, lookup_name_type_mask, sc_list); 629 } 630 } 631 632 if (match_name_after_lookup) 633 { 634 SymbolContext sc; 635 size_t i = old_size; 636 while (i<sc_list.GetSize()) 637 { 638 if (sc_list.GetContextAtIndex(i, sc)) 639 { 640 const char *func_name = sc.GetFunctionName().GetCString(); 641 if (func_name && strstr (func_name, name.GetCString()) == NULL) 642 { 643 // Remove the current context 644 sc_list.RemoveContextAtIndex(i); 645 // Don't increment i and continue in the loop 646 continue; 647 } 648 } 649 ++i; 650 } 651 } 652 653 } 654 else 655 { 656 if (symbols) 657 symbols->FindFunctions(name, namespace_decl, name_type_mask, include_inlines, append, sc_list); 658 659 // Now check our symbol table for symbols that are code symbols if requested 660 if (include_symbols) 661 { 662 ObjectFile *objfile = GetObjectFile(); 663 if (objfile) 664 { 665 Symtab *symtab = objfile->GetSymtab(); 666 if (symtab) 667 symtab->FindFunctionSymbols(name, name_type_mask, sc_list); 668 } 669 } 670 } 671 672 return sc_list.GetSize() - old_size; 673} 674 675size_t 676Module::FindFunctions (const RegularExpression& regex, 677 bool include_symbols, 678 bool include_inlines, 679 bool append, 680 SymbolContextList& sc_list) 681{ 682 if (!append) 683 sc_list.Clear(); 684 685 const size_t start_size = sc_list.GetSize(); 686 687 SymbolVendor *symbols = GetSymbolVendor (); 688 if (symbols) 689 symbols->FindFunctions(regex, include_inlines, append, sc_list); 690 // Now check our symbol table for symbols that are code symbols if requested 691 if (include_symbols) 692 { 693 ObjectFile *objfile = GetObjectFile(); 694 if (objfile) 695 { 696 Symtab *symtab = objfile->GetSymtab(); 697 if (symtab) 698 { 699 std::vector<uint32_t> symbol_indexes; 700 symtab->AppendSymbolIndexesMatchingRegExAndType (regex, eSymbolTypeAny, Symtab::eDebugAny, Symtab::eVisibilityAny, symbol_indexes); 701 const size_t num_matches = symbol_indexes.size(); 702 if (num_matches) 703 { 704 const bool merge_symbol_into_function = true; 705 SymbolContext sc(this); 706 for (size_t i=0; i<num_matches; i++) 707 { 708 sc.symbol = symtab->SymbolAtIndex(symbol_indexes[i]); 709 SymbolType sym_type = sc.symbol->GetType(); 710 if (sc.symbol && (sym_type == eSymbolTypeCode || 711 sym_type == eSymbolTypeResolver)) 712 sc_list.AppendIfUnique (sc, merge_symbol_into_function); 713 } 714 } 715 } 716 } 717 } 718 return sc_list.GetSize() - start_size; 719} 720 721size_t 722Module::FindTypes_Impl (const SymbolContext& sc, 723 const ConstString &name, 724 const ClangNamespaceDecl *namespace_decl, 725 bool append, 726 size_t max_matches, 727 TypeList& types) 728{ 729 Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__); 730 if (sc.module_sp.get() == NULL || sc.module_sp.get() == this) 731 { 732 SymbolVendor *symbols = GetSymbolVendor (); 733 if (symbols) 734 return symbols->FindTypes(sc, name, namespace_decl, append, max_matches, types); 735 } 736 return 0; 737} 738 739size_t 740Module::FindTypesInNamespace (const SymbolContext& sc, 741 const ConstString &type_name, 742 const ClangNamespaceDecl *namespace_decl, 743 size_t max_matches, 744 TypeList& type_list) 745{ 746 const bool append = true; 747 return FindTypes_Impl(sc, type_name, namespace_decl, append, max_matches, type_list); 748} 749 750lldb::TypeSP 751Module::FindFirstType (const SymbolContext& sc, 752 const ConstString &name, 753 bool exact_match) 754{ 755 TypeList type_list; 756 const size_t num_matches = FindTypes (sc, name, exact_match, 1, type_list); 757 if (num_matches) 758 return type_list.GetTypeAtIndex(0); 759 return TypeSP(); 760} 761 762 763size_t 764Module::FindTypes (const SymbolContext& sc, 765 const ConstString &name, 766 bool exact_match, 767 size_t max_matches, 768 TypeList& types) 769{ 770 size_t num_matches = 0; 771 const char *type_name_cstr = name.GetCString(); 772 std::string type_scope; 773 std::string type_basename; 774 const bool append = true; 775 TypeClass type_class = eTypeClassAny; 776 if (Type::GetTypeScopeAndBasename (type_name_cstr, type_scope, type_basename, type_class)) 777 { 778 // Check if "name" starts with "::" which means the qualified type starts 779 // from the root namespace and implies and exact match. The typenames we 780 // get back from clang do not start with "::" so we need to strip this off 781 // in order to get the qualfied names to match 782 783 if (type_scope.size() >= 2 && type_scope[0] == ':' && type_scope[1] == ':') 784 { 785 type_scope.erase(0,2); 786 exact_match = true; 787 } 788 ConstString type_basename_const_str (type_basename.c_str()); 789 if (FindTypes_Impl(sc, type_basename_const_str, NULL, append, max_matches, types)) 790 { 791 types.RemoveMismatchedTypes (type_scope, type_basename, type_class, exact_match); 792 num_matches = types.GetSize(); 793 } 794 } 795 else 796 { 797 // The type is not in a namespace/class scope, just search for it by basename 798 if (type_class != eTypeClassAny) 799 { 800 // The "type_name_cstr" will have been modified if we have a valid type class 801 // prefix (like "struct", "class", "union", "typedef" etc). 802 num_matches = FindTypes_Impl(sc, ConstString(type_name_cstr), NULL, append, max_matches, types); 803 types.RemoveMismatchedTypes (type_class); 804 num_matches = types.GetSize(); 805 } 806 else 807 { 808 num_matches = FindTypes_Impl(sc, name, NULL, append, max_matches, types); 809 } 810 } 811 812 return num_matches; 813 814} 815 816SymbolVendor* 817Module::GetSymbolVendor (bool can_create, lldb_private::Stream *feedback_strm) 818{ 819 Mutex::Locker locker (m_mutex); 820 if (m_did_load_symbol_vendor == false && can_create) 821 { 822 ObjectFile *obj_file = GetObjectFile (); 823 if (obj_file != NULL) 824 { 825 Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__); 826 m_symfile_ap.reset(SymbolVendor::FindPlugin(shared_from_this(), feedback_strm)); 827 m_did_load_symbol_vendor = true; 828 } 829 } 830 return m_symfile_ap.get(); 831} 832 833void 834Module::SetFileSpecAndObjectName (const FileSpec &file, const ConstString &object_name) 835{ 836 // Container objects whose paths do not specify a file directly can call 837 // this function to correct the file and object names. 838 m_file = file; 839 m_mod_time = file.GetModificationTime(); 840 m_object_name = object_name; 841} 842 843const ArchSpec& 844Module::GetArchitecture () const 845{ 846 return m_arch; 847} 848 849std::string 850Module::GetSpecificationDescription () const 851{ 852 std::string spec(GetFileSpec().GetPath()); 853 if (m_object_name) 854 { 855 spec += '('; 856 spec += m_object_name.GetCString(); 857 spec += ')'; 858 } 859 return spec; 860} 861 862void 863Module::GetDescription (Stream *s, lldb::DescriptionLevel level) 864{ 865 Mutex::Locker locker (m_mutex); 866 867 if (level >= eDescriptionLevelFull) 868 { 869 if (m_arch.IsValid()) 870 s->Printf("(%s) ", m_arch.GetArchitectureName()); 871 } 872 873 if (level == eDescriptionLevelBrief) 874 { 875 const char *filename = m_file.GetFilename().GetCString(); 876 if (filename) 877 s->PutCString (filename); 878 } 879 else 880 { 881 char path[PATH_MAX]; 882 if (m_file.GetPath(path, sizeof(path))) 883 s->PutCString(path); 884 } 885 886 const char *object_name = m_object_name.GetCString(); 887 if (object_name) 888 s->Printf("(%s)", object_name); 889} 890 891void 892Module::ReportError (const char *format, ...) 893{ 894 if (format && format[0]) 895 { 896 StreamString strm; 897 strm.PutCString("error: "); 898 GetDescription(&strm, lldb::eDescriptionLevelBrief); 899 strm.PutChar (' '); 900 va_list args; 901 va_start (args, format); 902 strm.PrintfVarArg(format, args); 903 va_end (args); 904 905 const int format_len = strlen(format); 906 if (format_len > 0) 907 { 908 const char last_char = format[format_len-1]; 909 if (last_char != '\n' || last_char != '\r') 910 strm.EOL(); 911 } 912 Host::SystemLog (Host::eSystemLogError, "%s", strm.GetString().c_str()); 913 914 } 915} 916 917bool 918Module::FileHasChanged () const 919{ 920 if (m_file_has_changed == false) 921 m_file_has_changed = (m_file.GetModificationTime() != m_mod_time); 922 return m_file_has_changed; 923} 924 925void 926Module::ReportErrorIfModifyDetected (const char *format, ...) 927{ 928 if (m_first_file_changed_log == false) 929 { 930 if (FileHasChanged ()) 931 { 932 m_first_file_changed_log = true; 933 if (format) 934 { 935 StreamString strm; 936 strm.PutCString("error: the object file "); 937 GetDescription(&strm, lldb::eDescriptionLevelFull); 938 strm.PutCString (" has been modified\n"); 939 940 va_list args; 941 va_start (args, format); 942 strm.PrintfVarArg(format, args); 943 va_end (args); 944 945 const int format_len = strlen(format); 946 if (format_len > 0) 947 { 948 const char last_char = format[format_len-1]; 949 if (last_char != '\n' || last_char != '\r') 950 strm.EOL(); 951 } 952 strm.PutCString("The debug session should be aborted as the original debug information has been overwritten.\n"); 953 Host::SystemLog (Host::eSystemLogError, "%s", strm.GetString().c_str()); 954 } 955 } 956 } 957} 958 959void 960Module::ReportWarning (const char *format, ...) 961{ 962 if (format && format[0]) 963 { 964 StreamString strm; 965 strm.PutCString("warning: "); 966 GetDescription(&strm, lldb::eDescriptionLevelFull); 967 strm.PutChar (' '); 968 969 va_list args; 970 va_start (args, format); 971 strm.PrintfVarArg(format, args); 972 va_end (args); 973 974 const int format_len = strlen(format); 975 if (format_len > 0) 976 { 977 const char last_char = format[format_len-1]; 978 if (last_char != '\n' || last_char != '\r') 979 strm.EOL(); 980 } 981 Host::SystemLog (Host::eSystemLogWarning, "%s", strm.GetString().c_str()); 982 } 983} 984 985void 986Module::LogMessage (Log *log, const char *format, ...) 987{ 988 if (log) 989 { 990 StreamString log_message; 991 GetDescription(&log_message, lldb::eDescriptionLevelFull); 992 log_message.PutCString (": "); 993 va_list args; 994 va_start (args, format); 995 log_message.PrintfVarArg (format, args); 996 va_end (args); 997 log->PutCString(log_message.GetString().c_str()); 998 } 999} 1000 1001void 1002Module::LogMessageVerboseBacktrace (Log *log, const char *format, ...) 1003{ 1004 if (log) 1005 { 1006 StreamString log_message; 1007 GetDescription(&log_message, lldb::eDescriptionLevelFull); 1008 log_message.PutCString (": "); 1009 va_list args; 1010 va_start (args, format); 1011 log_message.PrintfVarArg (format, args); 1012 va_end (args); 1013 if (log->GetVerbose()) 1014 Host::Backtrace (log_message, 1024); 1015 log->PutCString(log_message.GetString().c_str()); 1016 } 1017} 1018 1019void 1020Module::Dump(Stream *s) 1021{ 1022 Mutex::Locker locker (m_mutex); 1023 //s->Printf("%.*p: ", (int)sizeof(void*) * 2, this); 1024 s->Indent(); 1025 s->Printf("Module %s%s%s%s\n", 1026 m_file.GetPath().c_str(), 1027 m_object_name ? "(" : "", 1028 m_object_name ? m_object_name.GetCString() : "", 1029 m_object_name ? ")" : ""); 1030 1031 s->IndentMore(); 1032 ObjectFile *objfile = GetObjectFile (); 1033 1034 if (objfile) 1035 objfile->Dump(s); 1036 1037 SymbolVendor *symbols = GetSymbolVendor (); 1038 1039 if (symbols) 1040 symbols->Dump(s); 1041 1042 s->IndentLess(); 1043} 1044 1045 1046TypeList* 1047Module::GetTypeList () 1048{ 1049 SymbolVendor *symbols = GetSymbolVendor (); 1050 if (symbols) 1051 return &symbols->GetTypeList(); 1052 return NULL; 1053} 1054 1055const ConstString & 1056Module::GetObjectName() const 1057{ 1058 return m_object_name; 1059} 1060 1061ObjectFile * 1062Module::GetObjectFile() 1063{ 1064 Mutex::Locker locker (m_mutex); 1065 if (m_did_load_objfile == false) 1066 { 1067 m_did_load_objfile = true; 1068 Timer scoped_timer(__PRETTY_FUNCTION__, 1069 "Module::GetObjectFile () module = %s", GetFileSpec().GetFilename().AsCString("")); 1070 DataBufferSP data_sp; 1071 lldb::offset_t data_offset = 0; 1072 m_objfile_sp = ObjectFile::FindPlugin (shared_from_this(), 1073 &m_file, 1074 m_object_offset, 1075 m_file.GetByteSize(), 1076 data_sp, 1077 data_offset); 1078 if (m_objfile_sp) 1079 { 1080 // Once we get the object file, update our module with the object file's 1081 // architecture since it might differ in vendor/os if some parts were 1082 // unknown. 1083 m_objfile_sp->GetArchitecture (m_arch); 1084 } 1085 } 1086 return m_objfile_sp.get(); 1087} 1088 1089 1090const Symbol * 1091Module::FindFirstSymbolWithNameAndType (const ConstString &name, SymbolType symbol_type) 1092{ 1093 Timer scoped_timer(__PRETTY_FUNCTION__, 1094 "Module::FindFirstSymbolWithNameAndType (name = %s, type = %i)", 1095 name.AsCString(), 1096 symbol_type); 1097 ObjectFile *objfile = GetObjectFile(); 1098 if (objfile) 1099 { 1100 Symtab *symtab = objfile->GetSymtab(); 1101 if (symtab) 1102 return symtab->FindFirstSymbolWithNameAndType (name, symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny); 1103 } 1104 return NULL; 1105} 1106void 1107Module::SymbolIndicesToSymbolContextList (Symtab *symtab, std::vector<uint32_t> &symbol_indexes, SymbolContextList &sc_list) 1108{ 1109 // No need to protect this call using m_mutex all other method calls are 1110 // already thread safe. 1111 1112 size_t num_indices = symbol_indexes.size(); 1113 if (num_indices > 0) 1114 { 1115 SymbolContext sc; 1116 CalculateSymbolContext (&sc); 1117 for (size_t i = 0; i < num_indices; i++) 1118 { 1119 sc.symbol = symtab->SymbolAtIndex (symbol_indexes[i]); 1120 if (sc.symbol) 1121 sc_list.Append (sc); 1122 } 1123 } 1124} 1125 1126size_t 1127Module::FindFunctionSymbols (const ConstString &name, 1128 uint32_t name_type_mask, 1129 SymbolContextList& sc_list) 1130{ 1131 Timer scoped_timer(__PRETTY_FUNCTION__, 1132 "Module::FindSymbolsFunctions (name = %s, mask = 0x%8.8x)", 1133 name.AsCString(), 1134 name_type_mask); 1135 ObjectFile *objfile = GetObjectFile (); 1136 if (objfile) 1137 { 1138 Symtab *symtab = objfile->GetSymtab(); 1139 if (symtab) 1140 return symtab->FindFunctionSymbols (name, name_type_mask, sc_list); 1141 } 1142 return 0; 1143} 1144 1145size_t 1146Module::FindSymbolsWithNameAndType (const ConstString &name, SymbolType symbol_type, SymbolContextList &sc_list) 1147{ 1148 // No need to protect this call using m_mutex all other method calls are 1149 // already thread safe. 1150 1151 1152 Timer scoped_timer(__PRETTY_FUNCTION__, 1153 "Module::FindSymbolsWithNameAndType (name = %s, type = %i)", 1154 name.AsCString(), 1155 symbol_type); 1156 const size_t initial_size = sc_list.GetSize(); 1157 ObjectFile *objfile = GetObjectFile (); 1158 if (objfile) 1159 { 1160 Symtab *symtab = objfile->GetSymtab(); 1161 if (symtab) 1162 { 1163 std::vector<uint32_t> symbol_indexes; 1164 symtab->FindAllSymbolsWithNameAndType (name, symbol_type, symbol_indexes); 1165 SymbolIndicesToSymbolContextList (symtab, symbol_indexes, sc_list); 1166 } 1167 } 1168 return sc_list.GetSize() - initial_size; 1169} 1170 1171size_t 1172Module::FindSymbolsMatchingRegExAndType (const RegularExpression ®ex, SymbolType symbol_type, SymbolContextList &sc_list) 1173{ 1174 // No need to protect this call using m_mutex all other method calls are 1175 // already thread safe. 1176 1177 Timer scoped_timer(__PRETTY_FUNCTION__, 1178 "Module::FindSymbolsMatchingRegExAndType (regex = %s, type = %i)", 1179 regex.GetText(), 1180 symbol_type); 1181 const size_t initial_size = sc_list.GetSize(); 1182 ObjectFile *objfile = GetObjectFile (); 1183 if (objfile) 1184 { 1185 Symtab *symtab = objfile->GetSymtab(); 1186 if (symtab) 1187 { 1188 std::vector<uint32_t> symbol_indexes; 1189 symtab->FindAllSymbolsMatchingRexExAndType (regex, symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny, symbol_indexes); 1190 SymbolIndicesToSymbolContextList (symtab, symbol_indexes, sc_list); 1191 } 1192 } 1193 return sc_list.GetSize() - initial_size; 1194} 1195 1196void 1197Module::SetSymbolFileFileSpec (const FileSpec &file) 1198{ 1199 m_symfile_spec = file; 1200 m_symfile_ap.reset(); 1201 m_did_load_symbol_vendor = false; 1202} 1203 1204 1205bool 1206Module::IsExecutable () 1207{ 1208 if (GetObjectFile() == NULL) 1209 return false; 1210 else 1211 return GetObjectFile()->IsExecutable(); 1212} 1213 1214bool 1215Module::IsLoadedInTarget (Target *target) 1216{ 1217 ObjectFile *obj_file = GetObjectFile(); 1218 if (obj_file) 1219 { 1220 SectionList *sections = obj_file->GetSectionList(); 1221 if (sections != NULL) 1222 { 1223 size_t num_sections = sections->GetSize(); 1224 for (size_t sect_idx = 0; sect_idx < num_sections; sect_idx++) 1225 { 1226 SectionSP section_sp = sections->GetSectionAtIndex(sect_idx); 1227 if (section_sp->GetLoadBaseAddress(target) != LLDB_INVALID_ADDRESS) 1228 { 1229 return true; 1230 } 1231 } 1232 } 1233 } 1234 return false; 1235} 1236 1237bool 1238Module::LoadScriptingResourceInTarget (Target *target, Error& error) 1239{ 1240 if (!target) 1241 { 1242 error.SetErrorString("invalid destination Target"); 1243 return false; 1244 } 1245 1246 bool shoud_load = target->TargetProperties::GetLoadScriptFromSymbolFile(); 1247 1248 Debugger &debugger = target->GetDebugger(); 1249 const ScriptLanguage script_language = debugger.GetScriptLanguage(); 1250 if (script_language != eScriptLanguageNone) 1251 { 1252 1253 PlatformSP platform_sp(target->GetPlatform()); 1254 1255 if (!platform_sp) 1256 { 1257 error.SetErrorString("invalid Platform"); 1258 return false; 1259 } 1260 1261 FileSpecList file_specs = platform_sp->LocateExecutableScriptingResources (target, 1262 *this); 1263 1264 1265 const uint32_t num_specs = file_specs.GetSize(); 1266 if (num_specs) 1267 { 1268 ScriptInterpreter *script_interpreter = debugger.GetCommandInterpreter().GetScriptInterpreter(); 1269 if (script_interpreter) 1270 { 1271 for (uint32_t i=0; i<num_specs; ++i) 1272 { 1273 FileSpec scripting_fspec (file_specs.GetFileSpecAtIndex(i)); 1274 if (scripting_fspec && scripting_fspec.Exists()) 1275 { 1276 if (!shoud_load) 1277 { 1278 error.SetErrorString("Target doesn't allow loading scripting resource. Please set target.load-script-from-symbol-file and retry."); 1279 return false; 1280 } 1281 StreamString scripting_stream; 1282 scripting_fspec.Dump(&scripting_stream); 1283 const bool can_reload = false; 1284 const bool init_lldb_globals = false; 1285 bool did_load = script_interpreter->LoadScriptingModule(scripting_stream.GetData(), can_reload, init_lldb_globals, error); 1286 if (!did_load) 1287 return false; 1288 } 1289 } 1290 } 1291 else 1292 { 1293 error.SetErrorString("invalid ScriptInterpreter"); 1294 return false; 1295 } 1296 } 1297 } 1298 return true; 1299} 1300 1301bool 1302Module::SetArchitecture (const ArchSpec &new_arch) 1303{ 1304 if (!m_arch.IsValid()) 1305 { 1306 m_arch = new_arch; 1307 return true; 1308 } 1309 return m_arch.IsExactMatch(new_arch); 1310} 1311 1312bool 1313Module::SetLoadAddress (Target &target, lldb::addr_t offset, bool &changed) 1314{ 1315 size_t num_loaded_sections = 0; 1316 ObjectFile *objfile = GetObjectFile(); 1317 if (objfile) 1318 { 1319 SectionList *section_list = objfile->GetSectionList (); 1320 if (section_list) 1321 { 1322 const size_t num_sections = section_list->GetSize(); 1323 size_t sect_idx = 0; 1324 for (sect_idx = 0; sect_idx < num_sections; ++sect_idx) 1325 { 1326 // Iterate through the object file sections to find the 1327 // first section that starts of file offset zero and that 1328 // has bytes in the file... 1329 SectionSP section_sp (section_list->GetSectionAtIndex (sect_idx)); 1330 // Only load non-thread specific sections when given a slide 1331 if (section_sp && !section_sp->IsThreadSpecific()) 1332 { 1333 if (target.GetSectionLoadList().SetSectionLoadAddress (section_sp, section_sp->GetFileAddress() + offset)) 1334 ++num_loaded_sections; 1335 } 1336 } 1337 } 1338 } 1339 changed = num_loaded_sections > 0; 1340 return num_loaded_sections > 0; 1341} 1342 1343 1344bool 1345Module::MatchesModuleSpec (const ModuleSpec &module_ref) 1346{ 1347 const UUID &uuid = module_ref.GetUUID(); 1348 1349 if (uuid.IsValid()) 1350 { 1351 // If the UUID matches, then nothing more needs to match... 1352 if (uuid == GetUUID()) 1353 return true; 1354 else 1355 return false; 1356 } 1357 1358 const FileSpec &file_spec = module_ref.GetFileSpec(); 1359 if (file_spec) 1360 { 1361 if (!FileSpec::Equal (file_spec, m_file, file_spec.GetDirectory())) 1362 return false; 1363 } 1364 1365 const FileSpec &platform_file_spec = module_ref.GetPlatformFileSpec(); 1366 if (platform_file_spec) 1367 { 1368 if (!FileSpec::Equal (platform_file_spec, GetPlatformFileSpec (), platform_file_spec.GetDirectory())) 1369 return false; 1370 } 1371 1372 const ArchSpec &arch = module_ref.GetArchitecture(); 1373 if (arch.IsValid()) 1374 { 1375 if (!m_arch.IsCompatibleMatch(arch)) 1376 return false; 1377 } 1378 1379 const ConstString &object_name = module_ref.GetObjectName(); 1380 if (object_name) 1381 { 1382 if (object_name != GetObjectName()) 1383 return false; 1384 } 1385 return true; 1386} 1387 1388bool 1389Module::FindSourceFile (const FileSpec &orig_spec, FileSpec &new_spec) const 1390{ 1391 Mutex::Locker locker (m_mutex); 1392 return m_source_mappings.FindFile (orig_spec, new_spec); 1393} 1394 1395bool 1396Module::RemapSourceFile (const char *path, std::string &new_path) const 1397{ 1398 Mutex::Locker locker (m_mutex); 1399 return m_source_mappings.RemapPath(path, new_path); 1400} 1401 1402uint32_t 1403Module::GetVersion (uint32_t *versions, uint32_t num_versions) 1404{ 1405 ObjectFile *obj_file = GetObjectFile(); 1406 if (obj_file) 1407 return obj_file->GetVersion (versions, num_versions); 1408 1409 if (versions && num_versions) 1410 { 1411 for (uint32_t i=0; i<num_versions; ++i) 1412 versions[i] = UINT32_MAX; 1413 } 1414 return 0; 1415} 1416 1417void 1418Module::PrepareForFunctionNameLookup (const ConstString &name, 1419 uint32_t name_type_mask, 1420 ConstString &lookup_name, 1421 uint32_t &lookup_name_type_mask, 1422 bool &match_name_after_lookup) 1423{ 1424 const char *name_cstr = name.GetCString(); 1425 lookup_name_type_mask = eFunctionNameTypeNone; 1426 match_name_after_lookup = false; 1427 const char *base_name_start = NULL; 1428 const char *base_name_end = NULL; 1429 1430 if (name_type_mask & eFunctionNameTypeAuto) 1431 { 1432 if (CPPLanguageRuntime::IsCPPMangledName (name_cstr)) 1433 lookup_name_type_mask = eFunctionNameTypeFull; 1434 else if (ObjCLanguageRuntime::IsPossibleObjCMethodName (name_cstr)) 1435 lookup_name_type_mask = eFunctionNameTypeFull; 1436 else 1437 { 1438 if (ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr)) 1439 lookup_name_type_mask |= eFunctionNameTypeSelector; 1440 1441 if (CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end)) 1442 lookup_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase); 1443 } 1444 } 1445 else 1446 { 1447 lookup_name_type_mask = name_type_mask; 1448 if (lookup_name_type_mask & eFunctionNameTypeMethod || name_type_mask & eFunctionNameTypeBase) 1449 { 1450 // If they've asked for a CPP method or function name and it can't be that, we don't 1451 // even need to search for CPP methods or names. 1452 if (!CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end)) 1453 { 1454 lookup_name_type_mask &= ~(eFunctionNameTypeMethod | eFunctionNameTypeBase); 1455 if (lookup_name_type_mask == eFunctionNameTypeNone) 1456 return; 1457 } 1458 } 1459 1460 if (lookup_name_type_mask & eFunctionNameTypeSelector) 1461 { 1462 if (!ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr)) 1463 { 1464 lookup_name_type_mask &= ~(eFunctionNameTypeSelector); 1465 if (lookup_name_type_mask == eFunctionNameTypeNone) 1466 return; 1467 } 1468 } 1469 } 1470 1471 if (base_name_start && 1472 base_name_end && 1473 base_name_start != name_cstr && 1474 base_name_start < base_name_end) 1475 { 1476 // The name supplied was a partial C++ path like "a::count". In this case we want to do a 1477 // lookup on the basename "count" and then make sure any matching results contain "a::count" 1478 // so that it would match "b::a::count" and "a::count". This is why we set "match_name_after_lookup" 1479 // to true 1480 lookup_name.SetCStringWithLength(base_name_start, base_name_end - base_name_start); 1481 match_name_after_lookup = true; 1482 } 1483 else 1484 { 1485 // The name is already correct, just use the exact name as supplied, and we won't need 1486 // to check if any matches contain "name" 1487 lookup_name = name; 1488 match_name_after_lookup = false; 1489 } 1490}