Index: include/lldb/Target/Process.h =================================================================== --- include/lldb/Target/Process.h +++ include/lldb/Target/Process.h @@ -2701,6 +2701,7 @@ bool m_should_detach; /// Should we detach if the process object goes away /// with an explicit call to Kill or Detach? LanguageRuntimeCollection m_language_runtimes; + std::recursive_mutex m_language_runtimes_mutex; InstrumentationRuntimeCollection m_instrumentation_runtimes; std::unique_ptr m_next_event_action_up; std::vector m_pre_resume_actions; Index: source/Target/Process.cpp =================================================================== --- source/Target/Process.cpp +++ source/Target/Process.cpp @@ -660,7 +660,9 @@ m_image_tokens.clear(); m_memory_cache.Clear(); m_allocated_memory_cache.Clear(); + m_language_runtimes_mutex.lock(); m_language_runtimes.clear(); + m_language_runtimes_mutex.unlock(); m_instrumentation_runtimes.clear(); m_next_event_action_up.reset(); // Clear the last natural stop ID since it has a strong reference to this @@ -1549,6 +1551,7 @@ if (m_finalizing) return nullptr; + std::lock_guard guard(m_language_runtimes_mutex); LanguageRuntimeCollection::iterator pos; pos = m_language_runtimes.find(language); if (pos == m_language_runtimes.end() || (retry_if_null && !(*pos).second)) { @@ -1562,6 +1565,7 @@ } CPPLanguageRuntime *Process::GetCPPLanguageRuntime(bool retry_if_null) { + std::lock_guard guard(m_language_runtimes_mutex); LanguageRuntime *runtime = GetLanguageRuntime(eLanguageTypeC_plus_plus, retry_if_null); if (runtime != nullptr && @@ -1571,6 +1575,7 @@ } ObjCLanguageRuntime *Process::GetObjCLanguageRuntime(bool retry_if_null) { + std::lock_guard guard(m_language_runtimes_mutex); LanguageRuntime *runtime = GetLanguageRuntime(eLanguageTypeObjC, retry_if_null); if (runtime != nullptr && runtime->GetLanguageType() == eLanguageTypeObjC) @@ -5604,7 +5609,9 @@ m_jit_loaders_up.reset(); m_image_tokens.clear(); m_allocated_memory_cache.Clear(); + m_language_runtimes_mutex.lock(); m_language_runtimes.clear(); + m_language_runtimes_mutex.unlock(); m_instrumentation_runtimes.clear(); m_thread_list.DiscardThreadPlans(); m_memory_cache.Clear(true); @@ -5673,6 +5680,7 @@ // Iterate over a copy of this language runtime list in case the language // runtime ModulesDidLoad somehow causes the language runtime to be // unloaded. + m_language_runtimes_mutex.lock(); LanguageRuntimeCollection language_runtimes(m_language_runtimes); for (const auto &pair : language_runtimes) { // We must check language_runtime_sp to make sure it is not nullptr as we @@ -5682,6 +5690,7 @@ if (language_runtime_sp) language_runtime_sp->ModulesDidLoad(module_list); } + m_language_runtimes_mutex.unlock(); // If we don't have an operating system plug-in, try to load one since // loading shared libraries might cause a new one to try and load