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"
16 #include <mutex> // std::once
18 // Other libraries and framework includes
20 #include "lldb/Core/Log.h"
21 #include "lldb/Core/Module.h"
22 #include "lldb/Core/ModuleSpec.h"
23 #include "lldb/Host/Host.h"
24 #include "lldb/Host/Symbols.h"
25 #include "lldb/Symbol/ClangNamespaceDecl.h"
26 #include "lldb/Symbol/ObjectFile.h"
27 #include "lldb/Symbol/VariableList.h"
30 using namespace lldb_private;
32 //----------------------------------------------------------------------
33 // ModuleList constructor
34 //----------------------------------------------------------------------
35 ModuleList::ModuleList() :
37 m_modules_mutex (Mutex::eMutexTypeRecursive),
42 //----------------------------------------------------------------------
44 //----------------------------------------------------------------------
45 ModuleList::ModuleList(const ModuleList& rhs) :
47 m_modules_mutex (Mutex::eMutexTypeRecursive),
50 Mutex::Locker lhs_locker(m_modules_mutex);
51 Mutex::Locker rhs_locker(rhs.m_modules_mutex);
52 m_modules = rhs.m_modules;
55 ModuleList::ModuleList (ModuleList::Notifier* notifier) :
57 m_modules_mutex (Mutex::eMutexTypeRecursive),
62 //----------------------------------------------------------------------
63 // Assignment operator
64 //----------------------------------------------------------------------
66 ModuleList::operator= (const ModuleList& rhs)
70 // That's probably me nit-picking, but in theoretical situation:
72 // * that two threads A B and
73 // * two ModuleList's x y do opposite assignemnts ie.:
75 // in thread A: | in thread B:
78 // This establishes correct(same) lock taking order and thus
79 // avoids priority inversion.
80 if (uintptr_t(this) > uintptr_t(&rhs))
82 Mutex::Locker lhs_locker(m_modules_mutex);
83 Mutex::Locker rhs_locker(rhs.m_modules_mutex);
84 m_modules = rhs.m_modules;
88 Mutex::Locker rhs_locker(rhs.m_modules_mutex);
89 Mutex::Locker lhs_locker(m_modules_mutex);
90 m_modules = rhs.m_modules;
96 //----------------------------------------------------------------------
98 //----------------------------------------------------------------------
99 ModuleList::~ModuleList()
104 ModuleList::AppendImpl (const ModuleSP &module_sp, bool use_notifier)
108 Mutex::Locker locker(m_modules_mutex);
109 m_modules.push_back(module_sp);
110 if (use_notifier && m_notifier)
111 m_notifier->ModuleAdded(*this, module_sp);
116 ModuleList::Append (const ModuleSP &module_sp)
118 AppendImpl (module_sp);
122 ModuleList::ReplaceEquivalent (const ModuleSP &module_sp)
126 Mutex::Locker locker(m_modules_mutex);
128 // First remove any equivalent modules. Equivalent modules are modules
129 // whose path, platform path and architecture match.
130 ModuleSpec equivalent_module_spec (module_sp->GetFileSpec(), module_sp->GetArchitecture());
131 equivalent_module_spec.GetPlatformFileSpec() = module_sp->GetPlatformFileSpec();
134 while (idx < m_modules.size())
136 ModuleSP module_sp (m_modules[idx]);
137 if (module_sp->MatchesModuleSpec (equivalent_module_spec))
138 RemoveImpl(m_modules.begin() + idx);
142 // Now add the new module to the list
148 ModuleList::AppendIfNeeded (const ModuleSP &module_sp)
152 Mutex::Locker locker(m_modules_mutex);
153 collection::iterator pos, end = m_modules.end();
154 for (pos = m_modules.begin(); pos != end; ++pos)
156 if (pos->get() == module_sp.get())
157 return false; // Already in the list
159 // Only push module_sp on the list if it wasn't already in there.
167 ModuleList::Append (const ModuleList& module_list)
169 for (auto pos : module_list.m_modules)
174 ModuleList::AppendIfNeeded (const ModuleList& module_list)
177 for (auto pos : module_list.m_modules)
179 if (AppendIfNeeded(pos))
186 ModuleList::RemoveImpl (const ModuleSP &module_sp, bool use_notifier)
190 Mutex::Locker locker(m_modules_mutex);
191 collection::iterator pos, end = m_modules.end();
192 for (pos = m_modules.begin(); pos != end; ++pos)
194 if (pos->get() == module_sp.get())
196 m_modules.erase (pos);
197 if (use_notifier && m_notifier)
198 m_notifier->ModuleRemoved(*this, module_sp);
206 ModuleList::collection::iterator
207 ModuleList::RemoveImpl (ModuleList::collection::iterator pos, bool use_notifier)
209 ModuleSP module_sp(*pos);
210 collection::iterator retval = m_modules.erase(pos);
211 if (use_notifier && m_notifier)
212 m_notifier->ModuleRemoved(*this, module_sp);
217 ModuleList::Remove (const ModuleSP &module_sp)
219 return RemoveImpl (module_sp);
223 ModuleList::ReplaceModule (const lldb::ModuleSP &old_module_sp, const lldb::ModuleSP &new_module_sp)
225 if (!RemoveImpl(old_module_sp, false))
227 AppendImpl (new_module_sp, false);
229 m_notifier->ModuleUpdated(*this, old_module_sp,new_module_sp);
234 ModuleList::RemoveIfOrphaned (const Module *module_ptr)
238 Mutex::Locker locker(m_modules_mutex);
239 collection::iterator pos, end = m_modules.end();
240 for (pos = m_modules.begin(); pos != end; ++pos)
242 if (pos->get() == module_ptr)
246 pos = RemoveImpl(pos);
258 ModuleList::RemoveOrphans (bool mandatory)
260 Mutex::Locker locker;
264 locker.Lock (m_modules_mutex);
268 // Not mandatory, remove orphans if we can get the mutex
269 if (!locker.TryLock(m_modules_mutex))
272 collection::iterator pos = m_modules.begin();
273 size_t remove_count = 0;
274 while (pos != m_modules.end())
278 pos = RemoveImpl(pos);
290 ModuleList::Remove (ModuleList &module_list)
292 Mutex::Locker locker(m_modules_mutex);
293 size_t num_removed = 0;
294 collection::iterator pos, end = module_list.m_modules.end();
295 for (pos = module_list.m_modules.begin(); pos != end; ++pos)
311 ModuleList::Destroy()
317 ModuleList::ClearImpl (bool use_notifier)
319 Mutex::Locker locker(m_modules_mutex);
320 if (use_notifier && m_notifier)
321 m_notifier->WillClearList(*this);
326 ModuleList::GetModulePointerAtIndex (size_t idx) const
328 Mutex::Locker locker(m_modules_mutex);
329 return GetModulePointerAtIndexUnlocked(idx);
333 ModuleList::GetModulePointerAtIndexUnlocked (size_t idx) const
335 if (idx < m_modules.size())
336 return m_modules[idx].get();
341 ModuleList::GetModuleAtIndex(size_t idx) const
343 Mutex::Locker locker(m_modules_mutex);
344 return GetModuleAtIndexUnlocked(idx);
348 ModuleList::GetModuleAtIndexUnlocked(size_t idx) const
351 if (idx < m_modules.size())
352 module_sp = m_modules[idx];
357 ModuleList::FindFunctions (const ConstString &name,
358 uint32_t name_type_mask,
359 bool include_symbols,
360 bool include_inlines,
362 SymbolContextList &sc_list) const
367 const size_t old_size = sc_list.GetSize();
369 if (name_type_mask & eFunctionNameTypeAuto)
371 ConstString lookup_name;
372 uint32_t lookup_name_type_mask = 0;
373 bool match_name_after_lookup = false;
374 Module::PrepareForFunctionNameLookup (name, name_type_mask,
376 lookup_name_type_mask,
377 match_name_after_lookup);
379 Mutex::Locker locker(m_modules_mutex);
380 collection::const_iterator pos, end = m_modules.end();
381 for (pos = m_modules.begin(); pos != end; ++pos)
383 (*pos)->FindFunctions (lookup_name,
385 lookup_name_type_mask,
392 if (match_name_after_lookup)
396 while (i<sc_list.GetSize())
398 if (sc_list.GetContextAtIndex(i, sc))
400 const char *func_name = sc.GetFunctionName().GetCString();
401 if (func_name && strstr (func_name, name.GetCString()) == NULL)
403 // Remove the current context
404 sc_list.RemoveContextAtIndex(i);
405 // Don't increment i and continue in the loop
416 Mutex::Locker locker(m_modules_mutex);
417 collection::const_iterator pos, end = m_modules.end();
418 for (pos = m_modules.begin(); pos != end; ++pos)
420 (*pos)->FindFunctions (name, NULL, name_type_mask, include_symbols, include_inlines, true, sc_list);
423 return sc_list.GetSize() - old_size;
427 ModuleList::FindFunctionSymbols (const ConstString &name,
428 uint32_t name_type_mask,
429 SymbolContextList& sc_list)
431 const size_t old_size = sc_list.GetSize();
433 if (name_type_mask & eFunctionNameTypeAuto)
435 ConstString lookup_name;
436 uint32_t lookup_name_type_mask = 0;
437 bool match_name_after_lookup = false;
438 Module::PrepareForFunctionNameLookup (name, name_type_mask,
440 lookup_name_type_mask,
441 match_name_after_lookup);
443 Mutex::Locker locker(m_modules_mutex);
444 collection::const_iterator pos, end = m_modules.end();
445 for (pos = m_modules.begin(); pos != end; ++pos)
447 (*pos)->FindFunctionSymbols (lookup_name,
448 lookup_name_type_mask,
452 if (match_name_after_lookup)
456 while (i<sc_list.GetSize())
458 if (sc_list.GetContextAtIndex(i, sc))
460 const char *func_name = sc.GetFunctionName().GetCString();
461 if (func_name && strstr (func_name, name.GetCString()) == NULL)
463 // Remove the current context
464 sc_list.RemoveContextAtIndex(i);
465 // Don't increment i and continue in the loop
476 Mutex::Locker locker(m_modules_mutex);
477 collection::const_iterator pos, end = m_modules.end();
478 for (pos = m_modules.begin(); pos != end; ++pos)
480 (*pos)->FindFunctionSymbols (name, name_type_mask, sc_list);
484 return sc_list.GetSize() - old_size;
489 ModuleList::FindFunctions(const RegularExpression &name,
490 bool include_symbols,
491 bool include_inlines,
493 SymbolContextList& sc_list)
495 const size_t old_size = sc_list.GetSize();
497 Mutex::Locker locker(m_modules_mutex);
498 collection::const_iterator pos, end = m_modules.end();
499 for (pos = m_modules.begin(); pos != end; ++pos)
501 (*pos)->FindFunctions (name, include_symbols, include_inlines, append, sc_list);
504 return sc_list.GetSize() - old_size;
508 ModuleList::FindCompileUnits (const FileSpec &path,
510 SymbolContextList &sc_list) const
515 Mutex::Locker locker(m_modules_mutex);
516 collection::const_iterator pos, end = m_modules.end();
517 for (pos = m_modules.begin(); pos != end; ++pos)
519 (*pos)->FindCompileUnits (path, true, sc_list);
522 return sc_list.GetSize();
526 ModuleList::FindGlobalVariables (const ConstString &name,
529 VariableList& variable_list) const
531 size_t initial_size = variable_list.GetSize();
532 Mutex::Locker locker(m_modules_mutex);
533 collection::const_iterator pos, end = m_modules.end();
534 for (pos = m_modules.begin(); pos != end; ++pos)
536 (*pos)->FindGlobalVariables (name, NULL, append, max_matches, variable_list);
538 return variable_list.GetSize() - initial_size;
543 ModuleList::FindGlobalVariables (const RegularExpression& regex,
546 VariableList& variable_list) const
548 size_t initial_size = variable_list.GetSize();
549 Mutex::Locker locker(m_modules_mutex);
550 collection::const_iterator pos, end = m_modules.end();
551 for (pos = m_modules.begin(); pos != end; ++pos)
553 (*pos)->FindGlobalVariables (regex, append, max_matches, variable_list);
555 return variable_list.GetSize() - initial_size;
560 ModuleList::FindSymbolsWithNameAndType (const ConstString &name,
561 SymbolType symbol_type,
562 SymbolContextList &sc_list,
565 Mutex::Locker locker(m_modules_mutex);
568 size_t initial_size = sc_list.GetSize();
570 collection::const_iterator pos, end = m_modules.end();
571 for (pos = m_modules.begin(); pos != end; ++pos)
572 (*pos)->FindSymbolsWithNameAndType (name, symbol_type, sc_list);
573 return sc_list.GetSize() - initial_size;
577 ModuleList::FindSymbolsMatchingRegExAndType (const RegularExpression ®ex,
578 lldb::SymbolType symbol_type,
579 SymbolContextList &sc_list,
582 Mutex::Locker locker(m_modules_mutex);
585 size_t initial_size = sc_list.GetSize();
587 collection::const_iterator pos, end = m_modules.end();
588 for (pos = m_modules.begin(); pos != end; ++pos)
589 (*pos)->FindSymbolsMatchingRegExAndType (regex, symbol_type, sc_list);
590 return sc_list.GetSize() - initial_size;
594 ModuleList::FindModules (const ModuleSpec &module_spec, ModuleList& matching_module_list) const
596 size_t existing_matches = matching_module_list.GetSize();
598 Mutex::Locker locker(m_modules_mutex);
599 collection::const_iterator pos, end = m_modules.end();
600 for (pos = m_modules.begin(); pos != end; ++pos)
602 ModuleSP module_sp(*pos);
603 if (module_sp->MatchesModuleSpec (module_spec))
604 matching_module_list.Append(module_sp);
606 return matching_module_list.GetSize() - existing_matches;
610 ModuleList::FindModule (const Module *module_ptr) const
614 // Scope for "locker"
616 Mutex::Locker locker(m_modules_mutex);
617 collection::const_iterator pos, end = m_modules.end();
619 for (pos = m_modules.begin(); pos != end; ++pos)
621 if ((*pos).get() == module_ptr)
633 ModuleList::FindModule (const UUID &uuid) const
639 Mutex::Locker locker(m_modules_mutex);
640 collection::const_iterator pos, end = m_modules.end();
642 for (pos = m_modules.begin(); pos != end; ++pos)
644 if ((*pos)->GetUUID() == uuid)
656 ModuleList::FindTypes (const SymbolContext& sc, const ConstString &name, bool name_is_fully_qualified, size_t max_matches, TypeList& types) const
658 Mutex::Locker locker(m_modules_mutex);
660 size_t total_matches = 0;
661 collection::const_iterator pos, end = m_modules.end();
664 // The symbol context "sc" contains a module so we want to search that
665 // one first if it is in our list...
666 for (pos = m_modules.begin(); pos != end; ++pos)
668 if (sc.module_sp.get() == (*pos).get())
670 total_matches += (*pos)->FindTypes (sc, name, name_is_fully_qualified, max_matches, types);
672 if (total_matches >= max_matches)
678 if (total_matches < max_matches)
680 SymbolContext world_sc;
681 for (pos = m_modules.begin(); pos != end; ++pos)
683 // Search the module if the module is not equal to the one in the symbol
684 // context "sc". If "sc" contains a empty module shared pointer, then
685 // the comparisong will always be true (valid_module_ptr != NULL).
686 if (sc.module_sp.get() != (*pos).get())
687 total_matches += (*pos)->FindTypes (world_sc, name, name_is_fully_qualified, max_matches, types);
689 if (total_matches >= max_matches)
694 return total_matches;
698 ModuleList::FindSourceFile (const FileSpec &orig_spec, FileSpec &new_spec) const
700 Mutex::Locker locker(m_modules_mutex);
701 collection::const_iterator pos, end = m_modules.end();
702 for (pos = m_modules.begin(); pos != end; ++pos)
704 if ((*pos)->FindSourceFile (orig_spec, new_spec))
711 ModuleList::FindAddressesForLine (const lldb::TargetSP target_sp,
712 const FileSpec &file, uint32_t line,
714 std::vector<Address> &output_local, std::vector<Address> &output_extern)
716 Mutex::Locker locker(m_modules_mutex);
717 collection::const_iterator pos, end = m_modules.end();
718 for (pos = m_modules.begin(); pos != end; ++pos)
720 (*pos)->FindAddressesForLine(target_sp, file, line, function, output_local, output_extern);
725 ModuleList::FindFirstModule (const ModuleSpec &module_spec) const
728 Mutex::Locker locker(m_modules_mutex);
729 collection::const_iterator pos, end = m_modules.end();
730 for (pos = m_modules.begin(); pos != end; ++pos)
732 ModuleSP module_sp(*pos);
733 if (module_sp->MatchesModuleSpec (module_spec))
741 ModuleList::GetSize() const
745 Mutex::Locker locker(m_modules_mutex);
746 size = m_modules.size();
753 ModuleList::Dump(Stream *s) const
755 // s.Printf("%.*p: ", (int)sizeof(void*) * 2, this);
757 // s << "ModuleList\n";
759 Mutex::Locker locker(m_modules_mutex);
760 collection::const_iterator pos, end = m_modules.end();
761 for (pos = m_modules.begin(); pos != end; ++pos)
768 ModuleList::LogUUIDAndPaths (Log *log, const char *prefix_cstr)
772 Mutex::Locker locker(m_modules_mutex);
773 collection::const_iterator pos, begin = m_modules.begin(), end = m_modules.end();
774 for (pos = begin; pos != end; ++pos)
776 Module *module = pos->get();
777 const FileSpec &module_file_spec = module->GetFileSpec();
778 log->Printf ("%s[%u] %s (%s) \"%s\"",
779 prefix_cstr ? prefix_cstr : "",
780 (uint32_t)std::distance (begin, pos),
781 module->GetUUID().GetAsString().c_str(),
782 module->GetArchitecture().GetArchitectureName(),
783 module_file_spec.GetPath().c_str());
789 ModuleList::ResolveFileAddress (lldb::addr_t vm_addr, Address& so_addr) const
791 Mutex::Locker locker(m_modules_mutex);
792 collection::const_iterator pos, end = m_modules.end();
793 for (pos = m_modules.begin(); pos != end; ++pos)
795 if ((*pos)->ResolveFileAddress (vm_addr, so_addr))
803 ModuleList::ResolveSymbolContextForAddress (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc) const
805 // The address is already section offset so it has a module
806 uint32_t resolved_flags = 0;
807 ModuleSP module_sp (so_addr.GetModule());
810 resolved_flags = module_sp->ResolveSymbolContextForAddress (so_addr,
816 Mutex::Locker locker(m_modules_mutex);
817 collection::const_iterator pos, end = m_modules.end();
818 for (pos = m_modules.begin(); pos != end; ++pos)
820 resolved_flags = (*pos)->ResolveSymbolContextForAddress (so_addr,
823 if (resolved_flags != 0)
828 return resolved_flags;
832 ModuleList::ResolveSymbolContextForFilePath
834 const char *file_path,
837 uint32_t resolve_scope,
838 SymbolContextList& sc_list
841 FileSpec file_spec(file_path, false);
842 return ResolveSymbolContextsForFileSpec (file_spec, line, check_inlines, resolve_scope, sc_list);
846 ModuleList::ResolveSymbolContextsForFileSpec (const FileSpec &file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list) const
848 Mutex::Locker locker(m_modules_mutex);
849 collection::const_iterator pos, end = m_modules.end();
850 for (pos = m_modules.begin(); pos != end; ++pos)
852 (*pos)->ResolveSymbolContextsForFileSpec (file_spec, line, check_inlines, resolve_scope, sc_list);
855 return sc_list.GetSize();
859 ModuleList::GetIndexForModule (const Module *module) const
863 Mutex::Locker locker(m_modules_mutex);
864 collection::const_iterator pos;
865 collection::const_iterator begin = m_modules.begin();
866 collection::const_iterator end = m_modules.end();
867 for (pos = begin; pos != end; ++pos)
869 if ((*pos).get() == module)
870 return std::distance (begin, pos);
873 return LLDB_INVALID_INDEX32;
877 GetSharedModuleList ()
879 static ModuleList *g_shared_module_list = NULL;
880 static std::once_flag g_once_flag;
881 std::call_once(g_once_flag, [](){
882 // NOTE: Intentionally leak the module list so a program doesn't have to
883 // cleanup all modules and object files as it exits. This just wastes time
884 // doing a bunch of cleanup that isn't required.
885 if (g_shared_module_list == NULL)
886 g_shared_module_list = new ModuleList(); // <--- Intentional leak!!!
888 return *g_shared_module_list;
892 ModuleList::ModuleIsInCache (const Module *module_ptr)
896 ModuleList &shared_module_list = GetSharedModuleList ();
897 return shared_module_list.FindModule (module_ptr).get() != NULL;
903 ModuleList::FindSharedModules (const ModuleSpec &module_spec, ModuleList &matching_module_list)
905 return GetSharedModuleList ().FindModules (module_spec, matching_module_list);
909 ModuleList::RemoveOrphanSharedModules (bool mandatory)
911 return GetSharedModuleList ().RemoveOrphans(mandatory);
915 ModuleList::GetSharedModule
917 const ModuleSpec &module_spec,
919 const FileSpecList *module_search_paths_ptr,
920 ModuleSP *old_module_sp_ptr,
921 bool *did_create_ptr,
925 ModuleList &shared_module_list = GetSharedModuleList ();
926 Mutex::Locker locker(shared_module_list.m_modules_mutex);
934 *did_create_ptr = false;
935 if (old_module_sp_ptr)
936 old_module_sp_ptr->reset();
938 const UUID *uuid_ptr = module_spec.GetUUIDPtr();
939 const FileSpec &module_file_spec = module_spec.GetFileSpec();
940 const ArchSpec &arch = module_spec.GetArchitecture();
942 // Make sure no one else can try and get or create a module while this
943 // function is actively working on it by doing an extra lock on the
944 // global mutex list.
945 if (always_create == false)
947 ModuleList matching_module_list;
948 const size_t num_matching_modules = shared_module_list.FindModules (module_spec, matching_module_list);
949 if (num_matching_modules > 0)
951 for (size_t module_idx = 0; module_idx < num_matching_modules; ++module_idx)
953 module_sp = matching_module_list.GetModuleAtIndex(module_idx);
955 // Make sure the file for the module hasn't been modified
956 if (module_sp->FileHasChanged())
958 if (old_module_sp_ptr && !old_module_sp_ptr->get())
959 *old_module_sp_ptr = module_sp;
961 Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_MODULES));
963 log->Printf("module changed: %p, removing from global module list",
964 static_cast<void*>(module_sp.get()));
966 shared_module_list.Remove (module_sp);
971 // The module matches and the module was not modified from
972 // when it was last loaded.
983 module_sp.reset (new Module (module_spec));
984 // Make sure there are a module and an object file since we can specify
985 // a valid file path with an architecture that might not be in that file.
986 // By getting the object file we can guarantee that the architecture matches
989 if (module_sp->GetObjectFile())
991 // If we get in here we got the correct arch, now we just need
992 // to verify the UUID if one was given
993 if (uuid_ptr && *uuid_ptr != module_sp->GetUUID())
998 *did_create_ptr = true;
1000 shared_module_list.ReplaceEquivalent(module_sp);
1009 // Either the file didn't exist where at the path, or no path was given, so
1010 // we now have to use more extreme measures to try and find the appropriate
1013 // Fixup the incoming path in case the path points to a valid file, yet
1014 // the arch or UUID (if one was passed in) don't match.
1015 FileSpec file_spec = Symbols::LocateExecutableObjectFile (module_spec);
1017 // Don't look for the file if it appears to be the same one we already
1018 // checked for above...
1019 if (file_spec != module_file_spec)
1021 if (!file_spec.Exists())
1023 file_spec.GetPath(path, sizeof(path));
1024 if (path[0] == '\0')
1025 module_file_spec.GetPath(path, sizeof(path));
1026 // How can this check ever be true? This branch it is false, and we haven't modified file_spec.
1027 if (file_spec.Exists())
1029 std::string uuid_str;
1030 if (uuid_ptr && uuid_ptr->IsValid())
1031 uuid_str = uuid_ptr->GetAsString();
1035 if (!uuid_str.empty())
1036 error.SetErrorStringWithFormat("'%s' does not contain the %s architecture and UUID %s", path, arch.GetArchitectureName(), uuid_str.c_str());
1038 error.SetErrorStringWithFormat("'%s' does not contain the %s architecture.", path, arch.GetArchitectureName());
1043 error.SetErrorStringWithFormat("'%s' does not exist", path);
1051 // Make sure no one else can try and get or create a module while this
1052 // function is actively working on it by doing an extra lock on the
1053 // global mutex list.
1054 ModuleSpec platform_module_spec(module_spec);
1055 platform_module_spec.GetFileSpec() = file_spec;
1056 platform_module_spec.GetPlatformFileSpec() = file_spec;
1057 ModuleList matching_module_list;
1058 if (shared_module_list.FindModules (platform_module_spec, matching_module_list) > 0)
1060 module_sp = matching_module_list.GetModuleAtIndex(0);
1062 // If we didn't have a UUID in mind when looking for the object file,
1063 // then we should make sure the modification time hasn't changed!
1064 if (platform_module_spec.GetUUIDPtr() == NULL)
1066 TimeValue file_spec_mod_time(file_spec.GetModificationTime());
1067 if (file_spec_mod_time.IsValid())
1069 if (file_spec_mod_time != module_sp->GetModificationTime())
1071 if (old_module_sp_ptr)
1072 *old_module_sp_ptr = module_sp;
1073 shared_module_list.Remove (module_sp);
1080 if (module_sp.get() == NULL)
1082 module_sp.reset (new Module (platform_module_spec));
1083 // Make sure there are a module and an object file since we can specify
1084 // a valid file path with an architecture that might not be in that file.
1085 // By getting the object file we can guarantee that the architecture matches
1086 if (module_sp && module_sp->GetObjectFile())
1089 *did_create_ptr = true;
1091 shared_module_list.ReplaceEquivalent(module_sp);
1095 file_spec.GetPath(path, sizeof(path));
1100 error.SetErrorStringWithFormat("unable to open %s architecture in '%s'", arch.GetArchitectureName(), path);
1102 error.SetErrorStringWithFormat("unable to open '%s'", path);
1106 std::string uuid_str;
1107 if (uuid_ptr && uuid_ptr->IsValid())
1108 uuid_str = uuid_ptr->GetAsString();
1110 if (!uuid_str.empty())
1111 error.SetErrorStringWithFormat("cannot locate a module for UUID '%s'", uuid_str.c_str());
1113 error.SetErrorStringWithFormat("cannot locate a module");
1123 ModuleList::RemoveSharedModule (lldb::ModuleSP &module_sp)
1125 return GetSharedModuleList ().Remove (module_sp);
1129 ModuleList::RemoveSharedModuleIfOrphaned (const Module *module_ptr)
1131 return GetSharedModuleList ().RemoveIfOrphaned (module_ptr);
1135 ModuleList::LoadScriptingResourcesInTarget (Target *target,
1136 std::list<Error>& errors,
1137 Stream *feedback_stream,
1138 bool continue_on_error)
1142 Mutex::Locker locker(m_modules_mutex);
1143 for (auto module : m_modules)
1148 if (!module->LoadScriptingResourceInTarget(target, error, feedback_stream))
1150 if (error.Fail() && error.AsCString())
1152 error.SetErrorStringWithFormat("unable to load scripting data for module %s - error reported was %s",
1153 module->GetFileSpec().GetFileNameStrippingExtension().GetCString(),
1155 errors.push_back(error);
1157 if (!continue_on_error)
1163 return errors.size() == 0;