1 //===-- ModuleList.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/ModuleList.h" 11 12 // C Includes 13 // C++ Includes 14 // Other libraries and framework includes 15 // Project includes 16 #include "lldb/Core/Log.h" 17 #include "lldb/Core/Module.h" 18 #include "lldb/Host/Symbols.h" 19 #include "lldb/Symbol/ObjectFile.h" 20 #include "lldb/Symbol/VariableList.h" 21 22 using namespace lldb; 23 using namespace lldb_private; 24 25 //---------------------------------------------------------------------- 26 // ModuleList constructor 27 //---------------------------------------------------------------------- 28 ModuleList::ModuleList() : 29 m_modules(), 30 m_modules_mutex (Mutex::eMutexTypeRecursive) 31 { 32 } 33 34 //---------------------------------------------------------------------- 35 // Copy constructor 36 //---------------------------------------------------------------------- 37 ModuleList::ModuleList(const ModuleList& rhs) : 38 m_modules(rhs.m_modules) 39 { 40 } 41 42 //---------------------------------------------------------------------- 43 // Assignment operator 44 //---------------------------------------------------------------------- 45 const ModuleList& 46 ModuleList::operator= (const ModuleList& rhs) 47 { 48 if (this != &rhs) 49 { 50 Mutex::Locker locker(m_modules_mutex); 51 m_modules = rhs.m_modules; 52 } 53 return *this; 54 } 55 56 //---------------------------------------------------------------------- 57 // Destructor 58 //---------------------------------------------------------------------- 59 ModuleList::~ModuleList() 60 { 61 } 62 63 void 64 ModuleList::Append (ModuleSP &module_sp) 65 { 66 if (module_sp) 67 { 68 Mutex::Locker locker(m_modules_mutex); 69 m_modules.push_back(module_sp); 70 } 71 } 72 73 bool 74 ModuleList::AppendIfNeeded (ModuleSP &module_sp) 75 { 76 if (module_sp) 77 { 78 Mutex::Locker locker(m_modules_mutex); 79 collection::iterator pos, end = m_modules.end(); 80 for (pos = m_modules.begin(); pos != end; ++pos) 81 { 82 if (pos->get() == module_sp.get()) 83 return false; // Already in the list 84 } 85 // Only push module_sp on the list if it wasn't already in there. 86 m_modules.push_back(module_sp); 87 return true; 88 } 89 return false; 90 } 91 92 bool 93 ModuleList::Remove (ModuleSP &module_sp) 94 { 95 if (module_sp) 96 { 97 Mutex::Locker locker(m_modules_mutex); 98 collection::iterator pos, end = m_modules.end(); 99 for (pos = m_modules.begin(); pos != end; ++pos) 100 { 101 if (pos->get() == module_sp.get()) 102 { 103 m_modules.erase (pos); 104 return true; 105 } 106 } 107 } 108 return false; 109 } 110 111 size_t 112 ModuleList::Remove (ModuleList &module_list) 113 { 114 Mutex::Locker locker(m_modules_mutex); 115 size_t num_removed = 0; 116 collection::iterator pos, end = module_list.m_modules.end(); 117 for (pos = module_list.m_modules.begin(); pos != end; ++pos) 118 { 119 if (Remove (*pos)) 120 ++num_removed; 121 } 122 return num_removed; 123 } 124 125 126 127 void 128 ModuleList::Clear() 129 { 130 Mutex::Locker locker(m_modules_mutex); 131 m_modules.clear(); 132 } 133 134 Module* 135 ModuleList::GetModulePointerAtIndex (uint32_t idx) const 136 { 137 Mutex::Locker locker(m_modules_mutex); 138 if (idx < m_modules.size()) 139 return m_modules[idx].get(); 140 return NULL; 141 } 142 143 ModuleSP 144 ModuleList::GetModuleAtIndex(uint32_t idx) 145 { 146 Mutex::Locker locker(m_modules_mutex); 147 ModuleSP module_sp; 148 if (idx < m_modules.size()) 149 module_sp = m_modules[idx]; 150 return module_sp; 151 } 152 153 uint32_t 154 ModuleList::FindFunctions (const ConstString &name, 155 uint32_t name_type_mask, 156 bool include_symbols, 157 bool append, 158 SymbolContextList &sc_list) 159 { 160 if (!append) 161 sc_list.Clear(); 162 163 Mutex::Locker locker(m_modules_mutex); 164 collection::const_iterator pos, end = m_modules.end(); 165 for (pos = m_modules.begin(); pos != end; ++pos) 166 { 167 (*pos)->FindFunctions (name, name_type_mask, include_symbols, true, sc_list); 168 } 169 170 return sc_list.GetSize(); 171 } 172 173 uint32_t 174 ModuleList::FindCompileUnits (const FileSpec &path, 175 bool append, 176 SymbolContextList &sc_list) 177 { 178 if (!append) 179 sc_list.Clear(); 180 181 Mutex::Locker locker(m_modules_mutex); 182 collection::const_iterator pos, end = m_modules.end(); 183 for (pos = m_modules.begin(); pos != end; ++pos) 184 { 185 (*pos)->FindCompileUnits (path, true, sc_list); 186 } 187 188 return sc_list.GetSize(); 189 } 190 191 uint32_t 192 ModuleList::FindGlobalVariables (const ConstString &name, 193 bool append, 194 uint32_t max_matches, 195 VariableList& variable_list) 196 { 197 size_t initial_size = variable_list.GetSize(); 198 Mutex::Locker locker(m_modules_mutex); 199 collection::iterator pos, end = m_modules.end(); 200 for (pos = m_modules.begin(); pos != end; ++pos) 201 { 202 (*pos)->FindGlobalVariables (name, append, max_matches, variable_list); 203 } 204 return variable_list.GetSize() - initial_size; 205 } 206 207 208 uint32_t 209 ModuleList::FindGlobalVariables (const RegularExpression& regex, 210 bool append, 211 uint32_t max_matches, 212 VariableList& variable_list) 213 { 214 size_t initial_size = variable_list.GetSize(); 215 Mutex::Locker locker(m_modules_mutex); 216 collection::iterator pos, end = m_modules.end(); 217 for (pos = m_modules.begin(); pos != end; ++pos) 218 { 219 (*pos)->FindGlobalVariables (regex, append, max_matches, variable_list); 220 } 221 return variable_list.GetSize() - initial_size; 222 } 223 224 225 size_t 226 ModuleList::FindSymbolsWithNameAndType (const ConstString &name, 227 SymbolType symbol_type, 228 SymbolContextList &sc_list) 229 { 230 Mutex::Locker locker(m_modules_mutex); 231 sc_list.Clear(); 232 collection::iterator pos, end = m_modules.end(); 233 for (pos = m_modules.begin(); pos != end; ++pos) 234 (*pos)->FindSymbolsWithNameAndType (name, symbol_type, sc_list); 235 return sc_list.GetSize(); 236 } 237 238 class ModuleMatches 239 { 240 public: 241 //-------------------------------------------------------------- 242 /// Construct with the user ID to look for. 243 //-------------------------------------------------------------- 244 ModuleMatches (const FileSpec *file_spec_ptr, 245 const ArchSpec *arch_ptr, 246 const lldb_private::UUID *uuid_ptr, 247 const ConstString *object_name, 248 bool file_spec_is_platform) : 249 m_file_spec_ptr (file_spec_ptr), 250 m_arch_ptr (arch_ptr), 251 m_uuid_ptr (uuid_ptr), 252 m_object_name (object_name), 253 m_file_spec_compare_basename_only (false), 254 m_file_spec_is_platform (file_spec_is_platform) 255 { 256 if (file_spec_ptr) 257 m_file_spec_compare_basename_only = file_spec_ptr->GetDirectory(); 258 } 259 260 261 //-------------------------------------------------------------- 262 /// Unary predicate function object callback. 263 //-------------------------------------------------------------- 264 bool 265 operator () (const ModuleSP& module_sp) const 266 { 267 if (m_file_spec_ptr) 268 { 269 if (m_file_spec_is_platform) 270 { 271 if (!FileSpec::Equal (*m_file_spec_ptr, 272 module_sp->GetPlatformFileSpec(), 273 m_file_spec_compare_basename_only)) 274 return false; 275 276 } 277 else 278 { 279 if (!FileSpec::Equal (*m_file_spec_ptr, 280 module_sp->GetFileSpec(), 281 m_file_spec_compare_basename_only)) 282 return false; 283 } 284 } 285 286 if (m_arch_ptr && m_arch_ptr->IsValid()) 287 { 288 if (module_sp->GetArchitecture() != *m_arch_ptr) 289 return false; 290 } 291 292 if (m_uuid_ptr && m_uuid_ptr->IsValid()) 293 { 294 if (module_sp->GetUUID() != *m_uuid_ptr) 295 return false; 296 } 297 298 if (m_object_name) 299 { 300 if (module_sp->GetObjectName() != *m_object_name) 301 return false; 302 } 303 return true; 304 } 305 306 private: 307 //-------------------------------------------------------------- 308 // Member variables. 309 //-------------------------------------------------------------- 310 const FileSpec * m_file_spec_ptr; 311 const ArchSpec * m_arch_ptr; 312 const lldb_private::UUID * m_uuid_ptr; 313 const ConstString * m_object_name; 314 bool m_file_spec_compare_basename_only; 315 bool m_file_spec_is_platform; 316 }; 317 318 size_t 319 ModuleList::FindModules 320 ( 321 const FileSpec *file_spec_ptr, 322 const ArchSpec *arch_ptr, 323 const lldb_private::UUID *uuid_ptr, 324 const ConstString *object_name, 325 ModuleList& matching_module_list 326 ) const 327 { 328 size_t existing_matches = matching_module_list.GetSize(); 329 ModuleMatches matcher (file_spec_ptr, arch_ptr, uuid_ptr, object_name, false); 330 331 Mutex::Locker locker(m_modules_mutex); 332 collection::const_iterator end = m_modules.end(); 333 collection::const_iterator pos; 334 335 for (pos = std::find_if (m_modules.begin(), end, matcher); 336 pos != end; 337 pos = std::find_if (++pos, end, matcher)) 338 { 339 ModuleSP module_sp(*pos); 340 matching_module_list.Append(module_sp); 341 } 342 return matching_module_list.GetSize() - existing_matches; 343 } 344 345 ModuleSP 346 ModuleList::FindModule (const Module *module_ptr) 347 { 348 ModuleSP module_sp; 349 350 // Scope for "locker" 351 { 352 Mutex::Locker locker(m_modules_mutex); 353 collection::const_iterator pos, end = m_modules.end(); 354 355 for (pos = m_modules.begin(); pos != end; ++pos) 356 { 357 if ((*pos).get() == module_ptr) 358 { 359 module_sp = (*pos); 360 break; 361 } 362 } 363 } 364 return module_sp; 365 366 } 367 368 ModuleSP 369 ModuleList::FindModule (const UUID &uuid) 370 { 371 ModuleSP module_sp; 372 373 if (uuid.IsValid()) 374 { 375 Mutex::Locker locker(m_modules_mutex); 376 collection::const_iterator pos, end = m_modules.end(); 377 378 for (pos = m_modules.begin(); pos != end; ++pos) 379 { 380 if ((*pos)->GetUUID() == uuid) 381 { 382 module_sp = (*pos); 383 break; 384 } 385 } 386 } 387 return module_sp; 388 } 389 390 391 uint32_t 392 ModuleList::FindTypes (const SymbolContext& sc, const ConstString &name, bool append, uint32_t max_matches, TypeList& types) 393 { 394 Mutex::Locker locker(m_modules_mutex); 395 396 if (!append) 397 types.Clear(); 398 399 uint32_t total_matches = 0; 400 collection::const_iterator pos, end = m_modules.end(); 401 for (pos = m_modules.begin(); pos != end; ++pos) 402 { 403 if (sc.module_sp.get() == NULL || sc.module_sp.get() == (*pos).get()) 404 total_matches += (*pos)->FindTypes (sc, name, true, max_matches, types); 405 406 if (total_matches >= max_matches) 407 break; 408 } 409 return total_matches; 410 } 411 412 413 ModuleSP 414 ModuleList::FindFirstModuleForFileSpec (const FileSpec &file_spec, 415 const ArchSpec *arch_ptr, 416 const ConstString *object_name) 417 { 418 ModuleSP module_sp; 419 ModuleMatches matcher (&file_spec, 420 arch_ptr, 421 NULL, 422 object_name, 423 false); 424 425 // Scope for "locker" 426 { 427 Mutex::Locker locker(m_modules_mutex); 428 collection::const_iterator end = m_modules.end(); 429 collection::const_iterator pos = m_modules.begin(); 430 431 pos = std::find_if (pos, end, matcher); 432 if (pos != end) 433 module_sp = (*pos); 434 } 435 return module_sp; 436 437 } 438 439 ModuleSP 440 ModuleList::FindFirstModuleForPlatormFileSpec (const FileSpec &file_spec, 441 const ArchSpec *arch_ptr, 442 const ConstString *object_name) 443 { 444 ModuleSP module_sp; 445 ModuleMatches matcher (&file_spec, 446 arch_ptr, 447 NULL, 448 object_name, 449 true); 450 451 // Scope for "locker" 452 { 453 Mutex::Locker locker(m_modules_mutex); 454 collection::const_iterator end = m_modules.end(); 455 collection::const_iterator pos = m_modules.begin(); 456 457 pos = std::find_if (pos, end, matcher); 458 if (pos != end) 459 module_sp = (*pos); 460 } 461 return module_sp; 462 463 } 464 465 466 size_t 467 ModuleList::GetSize() const 468 { 469 size_t size = 0; 470 { 471 Mutex::Locker locker(m_modules_mutex); 472 size = m_modules.size(); 473 } 474 return size; 475 } 476 477 478 void 479 ModuleList::Dump(Stream *s) const 480 { 481 // s.Printf("%.*p: ", (int)sizeof(void*) * 2, this); 482 // s.Indent(); 483 // s << "ModuleList\n"; 484 485 Mutex::Locker locker(m_modules_mutex); 486 collection::const_iterator pos, end = m_modules.end(); 487 for (pos = m_modules.begin(); pos != end; ++pos) 488 { 489 (*pos)->Dump(s); 490 } 491 } 492 493 void 494 ModuleList::LogUUIDAndPaths (LogSP &log_sp, const char *prefix_cstr) 495 { 496 if (log_sp) 497 { 498 Mutex::Locker locker(m_modules_mutex); 499 char uuid_cstr[256]; 500 collection::const_iterator pos, begin = m_modules.begin(), end = m_modules.end(); 501 for (pos = begin; pos != end; ++pos) 502 { 503 Module *module = pos->get(); 504 module->GetUUID().GetAsCString (uuid_cstr, sizeof(uuid_cstr)); 505 const FileSpec &module_file_spec = module->GetFileSpec(); 506 log_sp->Printf ("%s[%u] %s (%s) \"%s/%s\"", 507 prefix_cstr ? prefix_cstr : "", 508 (uint32_t)std::distance (begin, pos), 509 uuid_cstr, 510 module->GetArchitecture().GetArchitectureName(), 511 module_file_spec.GetDirectory().GetCString(), 512 module_file_spec.GetFilename().GetCString()); 513 } 514 } 515 } 516 517 bool 518 ModuleList::ResolveFileAddress (lldb::addr_t vm_addr, Address& so_addr) 519 { 520 Mutex::Locker locker(m_modules_mutex); 521 collection::const_iterator pos, end = m_modules.end(); 522 for (pos = m_modules.begin(); pos != end; ++pos) 523 { 524 if ((*pos)->ResolveFileAddress (vm_addr, so_addr)) 525 return true; 526 } 527 528 return false; 529 } 530 531 uint32_t 532 ModuleList::ResolveSymbolContextForAddress (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc) 533 { 534 // The address is already section offset so it has a module 535 uint32_t resolved_flags = 0; 536 Module *module = so_addr.GetModule(); 537 if (module) 538 { 539 resolved_flags = module->ResolveSymbolContextForAddress (so_addr, 540 resolve_scope, 541 sc); 542 } 543 else 544 { 545 Mutex::Locker locker(m_modules_mutex); 546 collection::const_iterator pos, end = m_modules.end(); 547 for (pos = m_modules.begin(); pos != end; ++pos) 548 { 549 resolved_flags = (*pos)->ResolveSymbolContextForAddress (so_addr, 550 resolve_scope, 551 sc); 552 if (resolved_flags != 0) 553 break; 554 } 555 } 556 557 return resolved_flags; 558 } 559 560 uint32_t 561 ModuleList::ResolveSymbolContextForFilePath 562 ( 563 const char *file_path, 564 uint32_t line, 565 bool check_inlines, 566 uint32_t resolve_scope, 567 SymbolContextList& sc_list 568 ) 569 { 570 FileSpec file_spec(file_path, false); 571 return ResolveSymbolContextsForFileSpec (file_spec, line, check_inlines, resolve_scope, sc_list); 572 } 573 574 uint32_t 575 ModuleList::ResolveSymbolContextsForFileSpec (const FileSpec &file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list) 576 { 577 Mutex::Locker locker(m_modules_mutex); 578 collection::const_iterator pos, end = m_modules.end(); 579 for (pos = m_modules.begin(); pos != end; ++pos) 580 { 581 (*pos)->ResolveSymbolContextsForFileSpec (file_spec, line, check_inlines, resolve_scope, sc_list); 582 } 583 584 return sc_list.GetSize(); 585 } 586 587 uint32_t 588 ModuleList::GetIndexForModule (const Module *module) const 589 { 590 if (module) 591 { 592 Mutex::Locker locker(m_modules_mutex); 593 collection::const_iterator pos; 594 collection::const_iterator begin = m_modules.begin(); 595 collection::const_iterator end = m_modules.end(); 596 for (pos = begin; pos != end; ++pos) 597 { 598 if ((*pos).get() == module) 599 return std::distance (begin, pos); 600 } 601 } 602 return LLDB_INVALID_INDEX32; 603 } 604 605 static ModuleList & 606 GetSharedModuleList () 607 { 608 static ModuleList g_shared_module_list; 609 return g_shared_module_list; 610 } 611 612 const lldb::ModuleSP 613 ModuleList::GetModuleSP (const Module *module_ptr) 614 { 615 lldb::ModuleSP module_sp; 616 if (module_ptr) 617 { 618 ModuleList &shared_module_list = GetSharedModuleList (); 619 module_sp = shared_module_list.FindModule (module_ptr); 620 if (module_sp.get() == NULL) 621 { 622 char uuid_cstr[256]; 623 const_cast<Module *>(module_ptr)->GetUUID().GetAsCString (uuid_cstr, sizeof(uuid_cstr)); 624 const FileSpec &module_file_spec = module_ptr->GetFileSpec(); 625 fprintf (stderr, "warning: module not in shared module list: %s (%s) \"%s/%s\"\n", 626 uuid_cstr, 627 module_ptr->GetArchitecture().GetArchitectureName(), 628 module_file_spec.GetDirectory().GetCString(), 629 module_file_spec.GetFilename().GetCString()); 630 } 631 } 632 return module_sp; 633 } 634 635 size_t 636 ModuleList::FindSharedModules 637 ( 638 const FileSpec& in_file_spec, 639 const ArchSpec& arch, 640 const lldb_private::UUID *uuid_ptr, 641 const ConstString *object_name_ptr, 642 ModuleList &matching_module_list 643 ) 644 { 645 ModuleList &shared_module_list = GetSharedModuleList (); 646 return shared_module_list.FindModules (&in_file_spec, &arch, uuid_ptr, object_name_ptr, matching_module_list); 647 } 648 649 Error 650 ModuleList::GetSharedModule 651 ( 652 const FileSpec& in_file_spec, 653 const ArchSpec& arch, 654 const lldb_private::UUID *uuid_ptr, 655 const ConstString *object_name_ptr, 656 off_t object_offset, 657 ModuleSP &module_sp, 658 ModuleSP *old_module_sp_ptr, 659 bool *did_create_ptr, 660 bool always_create 661 ) 662 { 663 ModuleList &shared_module_list = GetSharedModuleList (); 664 Mutex::Locker locker(shared_module_list.m_modules_mutex); 665 char path[PATH_MAX]; 666 char uuid_cstr[64]; 667 668 Error error; 669 670 module_sp.reset(); 671 672 if (did_create_ptr) 673 *did_create_ptr = false; 674 if (old_module_sp_ptr) 675 old_module_sp_ptr->reset(); 676 677 678 // First just try and get the file where it purports to be (path in 679 // in_file_spec), then check and uuid. 680 681 if (in_file_spec) 682 { 683 // Make sure no one else can try and get or create a module while this 684 // function is actively working on it by doing an extra lock on the 685 // global mutex list. 686 if (always_create == false) 687 { 688 ModuleList matching_module_list; 689 const size_t num_matching_modules = shared_module_list.FindModules (&in_file_spec, &arch, NULL, object_name_ptr, matching_module_list); 690 if (num_matching_modules > 0) 691 { 692 for (uint32_t module_idx = 0; module_idx < num_matching_modules; ++module_idx) 693 { 694 module_sp = matching_module_list.GetModuleAtIndex(module_idx); 695 if (uuid_ptr && uuid_ptr->IsValid()) 696 { 697 // We found the module we were looking for. 698 if (module_sp->GetUUID() == *uuid_ptr) 699 return error; 700 } 701 else 702 { 703 // If we didn't have a UUID in mind when looking for the object file, 704 // then we should make sure the modification time hasn't changed! 705 TimeValue file_spec_mod_time(in_file_spec.GetModificationTime()); 706 if (file_spec_mod_time.IsValid()) 707 { 708 if (file_spec_mod_time == module_sp->GetModificationTime()) 709 return error; 710 } 711 } 712 if (old_module_sp_ptr && !old_module_sp_ptr->get()) 713 *old_module_sp_ptr = module_sp; 714 shared_module_list.Remove (module_sp); 715 module_sp.reset(); 716 } 717 } 718 } 719 720 if (module_sp) 721 return error; 722 else 723 { 724 module_sp.reset (new Module (in_file_spec, arch, object_name_ptr, object_offset)); 725 if (module_sp) 726 { 727 // If we get in here we got the correct arch, now we just need 728 // to verify the UUID if one was given 729 if (uuid_ptr && *uuid_ptr != module_sp->GetUUID()) 730 module_sp.reset(); 731 else 732 { 733 if (did_create_ptr) 734 *did_create_ptr = true; 735 736 shared_module_list.Append(module_sp); 737 return error; 738 } 739 } 740 } 741 } 742 743 // Either the file didn't exist where at the path, or no path was given, so 744 // we now have to use more extreme measures to try and find the appropriate 745 // module. 746 747 // Fixup the incoming path in case the path points to a valid file, yet 748 // the arch or UUID (if one was passed in) don't match. 749 FileSpec file_spec = Symbols::LocateExecutableObjectFile (&in_file_spec, arch.IsValid() ? &arch : NULL, uuid_ptr); 750 751 // Don't look for the file if it appears to be the same one we already 752 // checked for above... 753 if (file_spec != in_file_spec) 754 { 755 if (!file_spec.Exists()) 756 { 757 file_spec.GetPath(path, sizeof(path)); 758 if (file_spec.Exists()) 759 { 760 if (uuid_ptr && uuid_ptr->IsValid()) 761 uuid_ptr->GetAsCString(uuid_cstr, sizeof (uuid_cstr)); 762 else 763 uuid_cstr[0] = '\0'; 764 765 766 if (arch.IsValid()) 767 { 768 if (uuid_cstr[0]) 769 error.SetErrorStringWithFormat("'%s' does not contain the %s architecture and UUID %s.\n", path, arch.GetArchitectureName(), uuid_cstr[0]); 770 else 771 error.SetErrorStringWithFormat("'%s' does not contain the %s architecture.\n", path, arch.GetArchitectureName()); 772 } 773 } 774 else 775 { 776 error.SetErrorStringWithFormat("'%s' does not exist.\n", path); 777 } 778 return error; 779 } 780 781 782 // Make sure no one else can try and get or create a module while this 783 // function is actively working on it by doing an extra lock on the 784 // global mutex list. 785 ModuleList matching_module_list; 786 if (shared_module_list.FindModules (&file_spec, &arch, uuid_ptr, object_name_ptr, matching_module_list) > 0) 787 { 788 module_sp = matching_module_list.GetModuleAtIndex(0); 789 790 // If we didn't have a UUID in mind when looking for the object file, 791 // then we should make sure the modification time hasn't changed! 792 if (uuid_ptr == NULL) 793 { 794 TimeValue file_spec_mod_time(file_spec.GetModificationTime()); 795 if (file_spec_mod_time.IsValid()) 796 { 797 if (file_spec_mod_time != module_sp->GetModificationTime()) 798 { 799 if (old_module_sp_ptr) 800 *old_module_sp_ptr = module_sp; 801 shared_module_list.Remove (module_sp); 802 module_sp.reset(); 803 } 804 } 805 } 806 } 807 808 if (module_sp.get() == NULL) 809 { 810 module_sp.reset (new Module (file_spec, arch, object_name_ptr, object_offset)); 811 if (module_sp) 812 { 813 if (did_create_ptr) 814 *did_create_ptr = true; 815 816 shared_module_list.Append(module_sp); 817 } 818 else 819 { 820 file_spec.GetPath(path, sizeof(path)); 821 822 if (file_spec) 823 { 824 if (arch.IsValid()) 825 error.SetErrorStringWithFormat("Unable to open %s architecture in '%s'.\n", arch.GetArchitectureName(), path); 826 else 827 error.SetErrorStringWithFormat("Unable to open '%s'.\n", path); 828 } 829 else 830 { 831 if (uuid_ptr && uuid_ptr->IsValid()) 832 uuid_ptr->GetAsCString(uuid_cstr, sizeof (uuid_cstr)); 833 else 834 uuid_cstr[0] = '\0'; 835 836 if (uuid_cstr[0]) 837 error.SetErrorStringWithFormat("Cannot locate a module for UUID '%s'.\n", uuid_cstr[0]); 838 else 839 error.SetErrorStringWithFormat("Cannot locate a module.\n", path, arch.GetArchitectureName()); 840 } 841 } 842 } 843 } 844 845 return error; 846 } 847 848 bool 849 ModuleList::RemoveSharedModule (lldb::ModuleSP &module_sp) 850 { 851 return GetSharedModuleList ().Remove (module_sp); 852 } 853 854 855