diff --git a/lldb/include/lldb/Target/ModuleCache.h b/lldb/include/lldb/Target/ModuleCache.h index 9dc0e0903196a6a3b64ac06a87994ec5c895c3d5..010b367aa966e3e9d20cefaf58d06a1bee93d6b3 100644 --- a/lldb/include/lldb/Target/ModuleCache.h +++ b/lldb/include/lldb/Target/ModuleCache.h @@ -67,6 +67,7 @@ private: bool *did_create_ptr); std::unordered_map m_loaded_modules; + std::recursive_mutex m_cache_mutex; }; } // namespace lldb_private diff --git a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp index 3146c2ae296310920eb0bf3288cf70c0621a9cb6..a1e985442f673a0c177c10823f9c6c996d2d502d 100644 --- a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp +++ b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp @@ -23,6 +23,7 @@ #include "lldb/Target/ThreadPlanRunToAddress.h" #include "lldb/Utility/Log.h" #include "lldb/Utility/ProcessInfo.h" +#include "llvm/Support/ThreadPool.h" #include @@ -607,22 +608,26 @@ void DynamicLoaderPOSIXDYLD::LoadAllCurrentModules() { m_process->PrefetchModuleSpecs( module_names, m_process->GetTarget().GetArchitecture().GetTriple()); + llvm::ThreadPool pool(llvm::hardware_concurrency(DynamicLoaderPOSIXDYLD::DYLD_CONCURRENCY_THREADING)); for (I = m_rendezvous.begin(), E = m_rendezvous.end(); I != E; ++I) { - ModuleSP module_sp = - LoadModuleAtAddress(I->file_spec, I->link_addr, I->base_addr, true); - if (module_sp.get()) { - LLDB_LOG(log, "LoadAllCurrentModules loading module: {0}", - I->file_spec.GetFilename()); - module_list.Append(module_sp); - } else { + pool.async([&](const FileSpec &file_spec, addr_t link_addr, addr_t base_addr) { Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER)); - LLDB_LOGF( - log, - "DynamicLoaderPOSIXDYLD::%s failed loading module %s at 0x%" PRIx64, - __FUNCTION__, I->file_spec.GetCString(), I->base_addr); - } + ModuleSP module_sp = + LoadModuleAtAddress(file_spec, link_addr, base_addr, true); + if (module_sp.get()) { + LLDB_LOGF(log, "LoadAllCurrentModules loading module: %s", file_spec.GetFilename().GetCString()); + module_list.Append(module_sp); + } else { + LLDB_LOGF( + log, + "DynamicLoaderPOSIXDYLD:: failed loading module %s at 0x%" PRIx64, + file_spec.GetCString(), base_addr); + } + }, I->file_spec, I->link_addr, I->base_addr); } + pool.wait(); + m_process->GetTarget().ModulesDidLoad(module_list); m_initial_modules_added = true; } diff --git a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h index 61567801fdd003121f29499547f446d2d858e763..c52e211b798de2929db5b31b89b21eb28777af31 100644 --- a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h +++ b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h @@ -88,6 +88,9 @@ protected: std::map> m_loaded_modules; + /// number of woker in ThreadPool + static constexpr int DYLD_CONCURRENCY_THREADING {3}; + /// If possible sets a breakpoint on a function called by the runtime /// linker each time a module is loaded or unloaded. bool SetRendezvousBreakpoint(); diff --git a/lldb/source/Target/ModuleCache.cpp b/lldb/source/Target/ModuleCache.cpp index 20661a7b7a25e8e92cb32e0aad9fbf54b6211f13..84309068d4319bd76b60313a1c31a8175452771d 100644 --- a/lldb/source/Target/ModuleCache.cpp +++ b/lldb/source/Target/ModuleCache.cpp @@ -214,13 +214,16 @@ Status ModuleCache::Put(const FileSpec &root_dir_spec, const char *hostname, Status ModuleCache::Get(const FileSpec &root_dir_spec, const char *hostname, const ModuleSpec &module_spec, ModuleSP &cached_module_sp, bool *did_create_ptr) { - const auto find_it = - m_loaded_modules.find(module_spec.GetUUID().GetAsString()); - if (find_it != m_loaded_modules.end()) { - cached_module_sp = (*find_it).second.lock(); - if (cached_module_sp) - return Status(); - m_loaded_modules.erase(find_it); + { + std::lock_guard lock(m_cache_mutex); + const auto find_it = + m_loaded_modules.find(module_spec.GetUUID().GetAsString()); + if (find_it != m_loaded_modules.end()) { + cached_module_sp = (*find_it).second.lock(); + if (cached_module_sp) + return Status(); + m_loaded_modules.erase(find_it); + } } const auto module_spec_dir = @@ -259,6 +262,7 @@ Status ModuleCache::Get(const FileSpec &root_dir_spec, const char *hostname, if (FileSystem::Instance().Exists(symfile_spec)) cached_module_sp->SetSymbolFileFileSpec(symfile_spec); + std::lock_guard lock(m_cache_mutex); m_loaded_modules.insert( std::make_pair(module_spec.GetUUID().GetAsString(), cached_module_sp));