1 //===-- ModuleList.cpp ------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Core/ModuleList.h"
14 // Other libraries and framework includes
16 #include "lldb/Core/Log.h"
17 #include "lldb/Core/Module.h"
18 #include "lldb/Core/ModuleSpec.h"
19 #include "lldb/Host/Host.h"
20 #include "lldb/Host/Symbols.h"
21 #include "lldb/Symbol/ClangNamespaceDecl.h"
22 #include "lldb/Symbol/ObjectFile.h"
23 #include "lldb/Symbol/VariableList.h"
26 using namespace lldb_private;
28 //----------------------------------------------------------------------
29 // ModuleList constructor
30 //----------------------------------------------------------------------
31 ModuleList::ModuleList() :
33 m_modules_mutex (Mutex::eMutexTypeRecursive),
38 //----------------------------------------------------------------------
40 //----------------------------------------------------------------------
41 ModuleList::ModuleList(const ModuleList& rhs) :
43 m_modules_mutex (Mutex::eMutexTypeRecursive)
45 Mutex::Locker lhs_locker(m_modules_mutex);
46 Mutex::Locker rhs_locker(rhs.m_modules_mutex);
47 m_modules = rhs.m_modules;
50 ModuleList::ModuleList (ModuleList::Notifier* notifier) :
52 m_modules_mutex (Mutex::eMutexTypeRecursive),
57 //----------------------------------------------------------------------
58 // Assignment operator
59 //----------------------------------------------------------------------
61 ModuleList::operator= (const ModuleList& rhs)
65 Mutex::Locker lhs_locker(m_modules_mutex);
66 Mutex::Locker rhs_locker(rhs.m_modules_mutex);
67 m_modules = rhs.m_modules;
72 //----------------------------------------------------------------------
74 //----------------------------------------------------------------------
75 ModuleList::~ModuleList()
80 ModuleList::AppendImpl (const ModuleSP &module_sp, bool use_notifier)
84 Mutex::Locker locker(m_modules_mutex);
85 m_modules.push_back(module_sp);
86 if (use_notifier && m_notifier)
87 m_notifier->ModuleAdded(*this, module_sp);
92 ModuleList::Append (const ModuleSP &module_sp)
94 AppendImpl (module_sp);
98 ModuleList::ReplaceEquivalent (const ModuleSP &module_sp)
102 Mutex::Locker locker(m_modules_mutex);
104 // First remove any equivalent modules. Equivalent modules are modules
105 // whose path, platform path and architecture match.
106 ModuleSpec equivalent_module_spec (module_sp->GetFileSpec(), module_sp->GetArchitecture());
107 equivalent_module_spec.GetPlatformFileSpec() = module_sp->GetPlatformFileSpec();
110 while (idx < m_modules.size())
112 ModuleSP module_sp (m_modules[idx]);
113 if (module_sp->MatchesModuleSpec (equivalent_module_spec))
114 RemoveImpl(m_modules.begin() + idx);
118 // Now add the new module to the list
124 ModuleList::AppendIfNeeded (const ModuleSP &module_sp)
128 Mutex::Locker locker(m_modules_mutex);
129 collection::iterator pos, end = m_modules.end();
130 for (pos = m_modules.begin(); pos != end; ++pos)
132 if (pos->get() == module_sp.get())
133 return false; // Already in the list
135 // Only push module_sp on the list if it wasn't already in there.
143 ModuleList::Append (const ModuleList& module_list)
145 for (auto pos : module_list.m_modules)
150 ModuleList::AppendIfNeeded (const ModuleList& module_list)
153 for (auto pos : module_list.m_modules)
155 if (AppendIfNeeded(pos))
162 ModuleList::RemoveImpl (const ModuleSP &module_sp, bool use_notifier)
166 Mutex::Locker locker(m_modules_mutex);
167 collection::iterator pos, end = m_modules.end();
168 for (pos = m_modules.begin(); pos != end; ++pos)
170 if (pos->get() == module_sp.get())
172 m_modules.erase (pos);
173 if (use_notifier && m_notifier)
174 m_notifier->ModuleRemoved(*this, module_sp);
182 ModuleList::collection::iterator
183 ModuleList::RemoveImpl (ModuleList::collection::iterator pos, bool use_notifier)
185 ModuleSP module_sp(*pos);
186 collection::iterator retval = m_modules.erase(pos);
187 if (use_notifier && m_notifier)
188 m_notifier->ModuleRemoved(*this, module_sp);
193 ModuleList::Remove (const ModuleSP &module_sp)
195 return RemoveImpl (module_sp);
199 ModuleList::ReplaceModule (const lldb::ModuleSP &old_module_sp, const lldb::ModuleSP &new_module_sp)
201 if (!RemoveImpl(old_module_sp, false))
203 AppendImpl (new_module_sp, false);
205 m_notifier->ModuleUpdated(*this, old_module_sp,new_module_sp);
210 ModuleList::RemoveIfOrphaned (const Module *module_ptr)
214 Mutex::Locker locker(m_modules_mutex);
215 collection::iterator pos, end = m_modules.end();
216 for (pos = m_modules.begin(); pos != end; ++pos)
218 if (pos->get() == module_ptr)
222 pos = RemoveImpl(pos);
234 ModuleList::RemoveOrphans (bool mandatory)
236 Mutex::Locker locker;
240 locker.Lock (m_modules_mutex);
244 // Not mandatory, remove orphans if we can get the mutex
245 if (!locker.TryLock(m_modules_mutex))
248 collection::iterator pos = m_modules.begin();
249 size_t remove_count = 0;
250 while (pos != m_modules.end())
254 pos = RemoveImpl(pos);
266 ModuleList::Remove (ModuleList &module_list)
268 Mutex::Locker locker(m_modules_mutex);
269 size_t num_removed = 0;
270 collection::iterator pos, end = module_list.m_modules.end();
271 for (pos = module_list.m_modules.begin(); pos != end; ++pos)
287 ModuleList::Destroy()
293 ModuleList::ClearImpl (bool use_notifier)
295 Mutex::Locker locker(m_modules_mutex);
296 if (use_notifier && m_notifier)
297 m_notifier->WillClearList(*this);
302 ModuleList::GetModulePointerAtIndex (size_t idx) const
304 Mutex::Locker locker(m_modules_mutex);
305 return GetModulePointerAtIndexUnlocked(idx);
309 ModuleList::GetModulePointerAtIndexUnlocked (size_t idx) const
311 if (idx < m_modules.size())
312 return m_modules[idx].get();
317 ModuleList::GetModuleAtIndex(size_t idx) const
319 Mutex::Locker locker(m_modules_mutex);
320 return GetModuleAtIndexUnlocked(idx);
324 ModuleList::GetModuleAtIndexUnlocked(size_t idx) const
327 if (idx < m_modules.size())
328 module_sp = m_modules[idx];
333 ModuleList::FindFunctions (const ConstString &name,
334 uint32_t name_type_mask,
335 bool include_symbols,
336 bool include_inlines,
338 SymbolContextList &sc_list) const
343 const size_t old_size = sc_list.GetSize();
345 if (name_type_mask & eFunctionNameTypeAuto)
347 ConstString lookup_name;
348 uint32_t lookup_name_type_mask = 0;
349 bool match_name_after_lookup = false;
350 Module::PrepareForFunctionNameLookup (name, name_type_mask,
352 lookup_name_type_mask,
353 match_name_after_lookup);
355 Mutex::Locker locker(m_modules_mutex);
356 collection::const_iterator pos, end = m_modules.end();
357 for (pos = m_modules.begin(); pos != end; ++pos)
359 (*pos)->FindFunctions (lookup_name,
361 lookup_name_type_mask,
368 if (match_name_after_lookup)
372 while (i<sc_list.GetSize())
374 if (sc_list.GetContextAtIndex(i, sc))
376 const char *func_name = sc.GetFunctionName().GetCString();
377 if (func_name && strstr (func_name, name.GetCString()) == NULL)
379 // Remove the current context
380 sc_list.RemoveContextAtIndex(i);
381 // Don't increment i and continue in the loop
392 Mutex::Locker locker(m_modules_mutex);
393 collection::const_iterator pos, end = m_modules.end();
394 for (pos = m_modules.begin(); pos != end; ++pos)
396 (*pos)->FindFunctions (name, NULL, name_type_mask, include_symbols, include_inlines, true, sc_list);
399 return sc_list.GetSize() - old_size;
403 ModuleList::FindFunctionSymbols (const ConstString &name,
404 uint32_t name_type_mask,
405 SymbolContextList& sc_list)
407 const size_t old_size = sc_list.GetSize();
409 if (name_type_mask & eFunctionNameTypeAuto)
411 ConstString lookup_name;
412 uint32_t lookup_name_type_mask = 0;
413 bool match_name_after_lookup = false;
414 Module::PrepareForFunctionNameLookup (name, name_type_mask,
416 lookup_name_type_mask,
417 match_name_after_lookup);
419 Mutex::Locker locker(m_modules_mutex);
420 collection::const_iterator pos, end = m_modules.end();
421 for (pos = m_modules.begin(); pos != end; ++pos)
423 (*pos)->FindFunctionSymbols (lookup_name,
424 lookup_name_type_mask,
428 if (match_name_after_lookup)
432 while (i<sc_list.GetSize())
434 if (sc_list.GetContextAtIndex(i, sc))
436 const char *func_name = sc.GetFunctionName().GetCString();
437 if (func_name && strstr (func_name, name.GetCString()) == NULL)
439 // Remove the current context
440 sc_list.RemoveContextAtIndex(i);
441 // Don't increment i and continue in the loop
452 Mutex::Locker locker(m_modules_mutex);
453 collection::const_iterator pos, end = m_modules.end();
454 for (pos = m_modules.begin(); pos != end; ++pos)
456 (*pos)->FindFunctionSymbols (name, name_type_mask, sc_list);
460 return sc_list.GetSize() - old_size;
464 ModuleList::FindCompileUnits (const FileSpec &path,
466 SymbolContextList &sc_list) const
471 Mutex::Locker locker(m_modules_mutex);
472 collection::const_iterator pos, end = m_modules.end();
473 for (pos = m_modules.begin(); pos != end; ++pos)
475 (*pos)->FindCompileUnits (path, true, sc_list);
478 return sc_list.GetSize();
482 ModuleList::FindGlobalVariables (const ConstString &name,
485 VariableList& variable_list) const
487 size_t initial_size = variable_list.GetSize();
488 Mutex::Locker locker(m_modules_mutex);
489 collection::const_iterator pos, end = m_modules.end();
490 for (pos = m_modules.begin(); pos != end; ++pos)
492 (*pos)->FindGlobalVariables (name, NULL, append, max_matches, variable_list);
494 return variable_list.GetSize() - initial_size;
499 ModuleList::FindGlobalVariables (const RegularExpression& regex,
502 VariableList& variable_list) const
504 size_t initial_size = variable_list.GetSize();
505 Mutex::Locker locker(m_modules_mutex);
506 collection::const_iterator pos, end = m_modules.end();
507 for (pos = m_modules.begin(); pos != end; ++pos)
509 (*pos)->FindGlobalVariables (regex, append, max_matches, variable_list);
511 return variable_list.GetSize() - initial_size;
516 ModuleList::FindSymbolsWithNameAndType (const ConstString &name,
517 SymbolType symbol_type,
518 SymbolContextList &sc_list,
521 Mutex::Locker locker(m_modules_mutex);
524 size_t initial_size = sc_list.GetSize();
526 collection::const_iterator pos, end = m_modules.end();
527 for (pos = m_modules.begin(); pos != end; ++pos)
528 (*pos)->FindSymbolsWithNameAndType (name, symbol_type, sc_list);
529 return sc_list.GetSize() - initial_size;
533 ModuleList::FindSymbolsMatchingRegExAndType (const RegularExpression ®ex,
534 lldb::SymbolType symbol_type,
535 SymbolContextList &sc_list,
538 Mutex::Locker locker(m_modules_mutex);
541 size_t initial_size = sc_list.GetSize();
543 collection::const_iterator pos, end = m_modules.end();
544 for (pos = m_modules.begin(); pos != end; ++pos)
545 (*pos)->FindSymbolsMatchingRegExAndType (regex, symbol_type, sc_list);
546 return sc_list.GetSize() - initial_size;
550 ModuleList::FindModules (const ModuleSpec &module_spec, ModuleList& matching_module_list) const
552 size_t existing_matches = matching_module_list.GetSize();
554 Mutex::Locker locker(m_modules_mutex);
555 collection::const_iterator pos, end = m_modules.end();
556 for (pos = m_modules.begin(); pos != end; ++pos)
558 ModuleSP module_sp(*pos);
559 if (module_sp->MatchesModuleSpec (module_spec))
560 matching_module_list.Append(module_sp);
562 return matching_module_list.GetSize() - existing_matches;
566 ModuleList::FindModule (const Module *module_ptr) const
570 // Scope for "locker"
572 Mutex::Locker locker(m_modules_mutex);
573 collection::const_iterator pos, end = m_modules.end();
575 for (pos = m_modules.begin(); pos != end; ++pos)
577 if ((*pos).get() == module_ptr)
589 ModuleList::FindModule (const UUID &uuid) const
595 Mutex::Locker locker(m_modules_mutex);
596 collection::const_iterator pos, end = m_modules.end();
598 for (pos = m_modules.begin(); pos != end; ++pos)
600 if ((*pos)->GetUUID() == uuid)
612 ModuleList::FindTypes (const SymbolContext& sc, const ConstString &name, bool name_is_fully_qualified, size_t max_matches, TypeList& types) const
614 Mutex::Locker locker(m_modules_mutex);
616 size_t total_matches = 0;
617 collection::const_iterator pos, end = m_modules.end();
620 // The symbol context "sc" contains a module so we want to search that
621 // one first if it is in our list...
622 for (pos = m_modules.begin(); pos != end; ++pos)
624 if (sc.module_sp.get() == (*pos).get())
626 total_matches += (*pos)->FindTypes (sc, name, name_is_fully_qualified, max_matches, types);
628 if (total_matches >= max_matches)
634 if (total_matches < max_matches)
636 SymbolContext world_sc;
637 for (pos = m_modules.begin(); pos != end; ++pos)
639 // Search the module if the module is not equal to the one in the symbol
640 // context "sc". If "sc" contains a empty module shared pointer, then
641 // the comparisong will always be true (valid_module_ptr != NULL).
642 if (sc.module_sp.get() != (*pos).get())
643 total_matches += (*pos)->FindTypes (world_sc, name, name_is_fully_qualified, max_matches, types);
645 if (total_matches >= max_matches)
650 return total_matches;
654 ModuleList::FindSourceFile (const FileSpec &orig_spec, FileSpec &new_spec) const
656 Mutex::Locker locker(m_modules_mutex);
657 collection::const_iterator pos, end = m_modules.end();
658 for (pos = m_modules.begin(); pos != end; ++pos)
660 if ((*pos)->FindSourceFile (orig_spec, new_spec))
667 ModuleList::FindAddressesForLine (const lldb::TargetSP target_sp,
668 const FileSpec &file, uint32_t line,
670 std::vector<Address> &output_local, std::vector<Address> &output_extern)
672 Mutex::Locker locker(m_modules_mutex);
673 collection::const_iterator pos, end = m_modules.end();
674 for (pos = m_modules.begin(); pos != end; ++pos)
676 (*pos)->FindAddressesForLine(target_sp, file, line, function, output_local, output_extern);
681 ModuleList::FindFirstModule (const ModuleSpec &module_spec) const
684 Mutex::Locker locker(m_modules_mutex);
685 collection::const_iterator pos, end = m_modules.end();
686 for (pos = m_modules.begin(); pos != end; ++pos)
688 ModuleSP module_sp(*pos);
689 if (module_sp->MatchesModuleSpec (module_spec))
697 ModuleList::GetSize() const
701 Mutex::Locker locker(m_modules_mutex);
702 size = m_modules.size();
709 ModuleList::Dump(Stream *s) const
711 // s.Printf("%.*p: ", (int)sizeof(void*) * 2, this);
713 // s << "ModuleList\n";
715 Mutex::Locker locker(m_modules_mutex);
716 collection::const_iterator pos, end = m_modules.end();
717 for (pos = m_modules.begin(); pos != end; ++pos)
724 ModuleList::LogUUIDAndPaths (Log *log, const char *prefix_cstr)
728 Mutex::Locker locker(m_modules_mutex);
729 collection::const_iterator pos, begin = m_modules.begin(), end = m_modules.end();
730 for (pos = begin; pos != end; ++pos)
732 Module *module = pos->get();
733 const FileSpec &module_file_spec = module->GetFileSpec();
734 log->Printf ("%s[%u] %s (%s) \"%s\"",
735 prefix_cstr ? prefix_cstr : "",
736 (uint32_t)std::distance (begin, pos),
737 module->GetUUID().GetAsString().c_str(),
738 module->GetArchitecture().GetArchitectureName(),
739 module_file_spec.GetPath().c_str());
745 ModuleList::ResolveFileAddress (lldb::addr_t vm_addr, Address& so_addr) const
747 Mutex::Locker locker(m_modules_mutex);
748 collection::const_iterator pos, end = m_modules.end();
749 for (pos = m_modules.begin(); pos != end; ++pos)
751 if ((*pos)->ResolveFileAddress (vm_addr, so_addr))
759 ModuleList::ResolveSymbolContextForAddress (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc) const
761 // The address is already section offset so it has a module
762 uint32_t resolved_flags = 0;
763 ModuleSP module_sp (so_addr.GetModule());
766 resolved_flags = module_sp->ResolveSymbolContextForAddress (so_addr,
772 Mutex::Locker locker(m_modules_mutex);
773 collection::const_iterator pos, end = m_modules.end();
774 for (pos = m_modules.begin(); pos != end; ++pos)
776 resolved_flags = (*pos)->ResolveSymbolContextForAddress (so_addr,
779 if (resolved_flags != 0)
784 return resolved_flags;
788 ModuleList::ResolveSymbolContextForFilePath
790 const char *file_path,
793 uint32_t resolve_scope,
794 SymbolContextList& sc_list
797 FileSpec file_spec(file_path, false);
798 return ResolveSymbolContextsForFileSpec (file_spec, line, check_inlines, resolve_scope, sc_list);
802 ModuleList::ResolveSymbolContextsForFileSpec (const FileSpec &file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list) const
804 Mutex::Locker locker(m_modules_mutex);
805 collection::const_iterator pos, end = m_modules.end();
806 for (pos = m_modules.begin(); pos != end; ++pos)
808 (*pos)->ResolveSymbolContextsForFileSpec (file_spec, line, check_inlines, resolve_scope, sc_list);
811 return sc_list.GetSize();
815 ModuleList::GetIndexForModule (const Module *module) const
819 Mutex::Locker locker(m_modules_mutex);
820 collection::const_iterator pos;
821 collection::const_iterator begin = m_modules.begin();
822 collection::const_iterator end = m_modules.end();
823 for (pos = begin; pos != end; ++pos)
825 if ((*pos).get() == module)
826 return std::distance (begin, pos);
829 return LLDB_INVALID_INDEX32;
833 GetSharedModuleList ()
835 // NOTE: Intentionally leak the module list so a program doesn't have to
836 // cleanup all modules and object files as it exits. This just wastes time
837 // doing a bunch of cleanup that isn't required.
838 static ModuleList *g_shared_module_list = NULL;
839 if (g_shared_module_list == NULL)
840 g_shared_module_list = new ModuleList(); // <--- Intentional leak!!!
842 return *g_shared_module_list;
846 ModuleList::ModuleIsInCache (const Module *module_ptr)
850 ModuleList &shared_module_list = GetSharedModuleList ();
851 return shared_module_list.FindModule (module_ptr).get() != NULL;
857 ModuleList::FindSharedModules (const ModuleSpec &module_spec, ModuleList &matching_module_list)
859 return GetSharedModuleList ().FindModules (module_spec, matching_module_list);
863 ModuleList::RemoveOrphanSharedModules (bool mandatory)
865 return GetSharedModuleList ().RemoveOrphans(mandatory);
869 ModuleList::GetSharedModule
871 const ModuleSpec &module_spec,
873 const FileSpecList *module_search_paths_ptr,
874 ModuleSP *old_module_sp_ptr,
875 bool *did_create_ptr,
879 ModuleList &shared_module_list = GetSharedModuleList ();
880 Mutex::Locker locker(shared_module_list.m_modules_mutex);
888 *did_create_ptr = false;
889 if (old_module_sp_ptr)
890 old_module_sp_ptr->reset();
892 const UUID *uuid_ptr = module_spec.GetUUIDPtr();
893 const FileSpec &module_file_spec = module_spec.GetFileSpec();
894 const ArchSpec &arch = module_spec.GetArchitecture();
896 // Make sure no one else can try and get or create a module while this
897 // function is actively working on it by doing an extra lock on the
898 // global mutex list.
899 if (always_create == false)
901 ModuleList matching_module_list;
902 const size_t num_matching_modules = shared_module_list.FindModules (module_spec, matching_module_list);
903 if (num_matching_modules > 0)
905 for (size_t module_idx = 0; module_idx < num_matching_modules; ++module_idx)
907 module_sp = matching_module_list.GetModuleAtIndex(module_idx);
909 // Make sure the file for the module hasn't been modified
910 if (module_sp->FileHasChanged())
912 if (old_module_sp_ptr && !old_module_sp_ptr->get())
913 *old_module_sp_ptr = module_sp;
915 Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_MODULES));
917 log->Printf("module changed: %p, removing from global module list", module_sp.get());
919 shared_module_list.Remove (module_sp);
924 // The module matches and the module was not modified from
925 // when it was last loaded.
936 module_sp.reset (new Module (module_spec));
937 // Make sure there are a module and an object file since we can specify
938 // a valid file path with an architecture that might not be in that file.
939 // By getting the object file we can guarantee that the architecture matches
942 if (module_sp->GetObjectFile())
944 // If we get in here we got the correct arch, now we just need
945 // to verify the UUID if one was given
946 if (uuid_ptr && *uuid_ptr != module_sp->GetUUID())
951 *did_create_ptr = true;
953 shared_module_list.ReplaceEquivalent(module_sp);
962 // Either the file didn't exist where at the path, or no path was given, so
963 // we now have to use more extreme measures to try and find the appropriate
966 // Fixup the incoming path in case the path points to a valid file, yet
967 // the arch or UUID (if one was passed in) don't match.
968 FileSpec file_spec = Symbols::LocateExecutableObjectFile (module_spec);
970 // Don't look for the file if it appears to be the same one we already
971 // checked for above...
972 if (file_spec != module_file_spec)
974 if (!file_spec.Exists())
976 file_spec.GetPath(path, sizeof(path));
978 module_file_spec.GetPath(path, sizeof(path));
979 if (file_spec.Exists())
981 std::string uuid_str;
982 if (uuid_ptr && uuid_ptr->IsValid())
983 uuid_str = uuid_ptr->GetAsString();
987 if (!uuid_str.empty())
988 error.SetErrorStringWithFormat("'%s' does not contain the %s architecture and UUID %s", path, arch.GetArchitectureName(), uuid_str.c_str());
990 error.SetErrorStringWithFormat("'%s' does not contain the %s architecture.", path, arch.GetArchitectureName());
995 error.SetErrorStringWithFormat("'%s' does not exist", path);
1003 // Make sure no one else can try and get or create a module while this
1004 // function is actively working on it by doing an extra lock on the
1005 // global mutex list.
1006 ModuleSpec platform_module_spec(module_spec);
1007 platform_module_spec.GetFileSpec() = file_spec;
1008 platform_module_spec.GetPlatformFileSpec() = file_spec;
1009 ModuleList matching_module_list;
1010 if (shared_module_list.FindModules (platform_module_spec, matching_module_list) > 0)
1012 module_sp = matching_module_list.GetModuleAtIndex(0);
1014 // If we didn't have a UUID in mind when looking for the object file,
1015 // then we should make sure the modification time hasn't changed!
1016 if (platform_module_spec.GetUUIDPtr() == NULL)
1018 TimeValue file_spec_mod_time(file_spec.GetModificationTime());
1019 if (file_spec_mod_time.IsValid())
1021 if (file_spec_mod_time != module_sp->GetModificationTime())
1023 if (old_module_sp_ptr)
1024 *old_module_sp_ptr = module_sp;
1025 shared_module_list.Remove (module_sp);
1032 if (module_sp.get() == NULL)
1034 module_sp.reset (new Module (platform_module_spec));
1035 // Make sure there are a module and an object file since we can specify
1036 // a valid file path with an architecture that might not be in that file.
1037 // By getting the object file we can guarantee that the architecture matches
1038 if (module_sp && module_sp->GetObjectFile())
1041 *did_create_ptr = true;
1043 shared_module_list.ReplaceEquivalent(module_sp);
1047 file_spec.GetPath(path, sizeof(path));
1052 error.SetErrorStringWithFormat("unable to open %s architecture in '%s'", arch.GetArchitectureName(), path);
1054 error.SetErrorStringWithFormat("unable to open '%s'", path);
1058 std::string uuid_str;
1059 if (uuid_ptr && uuid_ptr->IsValid())
1060 uuid_str = uuid_ptr->GetAsString();
1062 if (!uuid_str.empty())
1063 error.SetErrorStringWithFormat("cannot locate a module for UUID '%s'", uuid_str.c_str());
1065 error.SetErrorStringWithFormat("cannot locate a module");
1075 ModuleList::RemoveSharedModule (lldb::ModuleSP &module_sp)
1077 return GetSharedModuleList ().Remove (module_sp);
1081 ModuleList::RemoveSharedModuleIfOrphaned (const Module *module_ptr)
1083 return GetSharedModuleList ().RemoveIfOrphaned (module_ptr);
1087 ModuleList::LoadScriptingResourcesInTarget (Target *target,
1088 std::list<Error>& errors,
1089 Stream *feedback_stream,
1090 bool continue_on_error)
1094 Mutex::Locker locker(m_modules_mutex);
1095 for (auto module : m_modules)
1100 if (!module->LoadScriptingResourceInTarget(target, error, feedback_stream))
1102 if (error.Fail() && error.AsCString())
1104 error.SetErrorStringWithFormat("unable to load scripting data for module %s - error reported was %s",
1105 module->GetFileSpec().GetFileNameStrippingExtension().GetCString(),
1107 errors.push_back(error);
1109 if (!continue_on_error)
1114 return errors.size() == 0;