Index: include/lldb/Target/Language.h =================================================================== --- include/lldb/Target/Language.h +++ include/lldb/Target/Language.h @@ -264,6 +264,8 @@ // etc. static lldb::LanguageType GetPrimaryLanguage(lldb::LanguageType language); + static std::set GetSupportedLanguages(); + static void GetLanguagesSupportingTypeSystems( std::set &languages, std::set &languages_for_expressions); Index: include/lldb/Target/Process.h =================================================================== --- include/lldb/Target/Process.h +++ include/lldb/Target/Process.h @@ -2178,6 +2178,9 @@ OperatingSystem *GetOperatingSystem() { return m_os_up.get(); } + std::vector + GetLanguageRuntimes(bool retry_if_null = true); + LanguageRuntime *GetLanguageRuntime(lldb::LanguageType language, bool retry_if_null = true); Index: source/Target/Language.cpp =================================================================== --- source/Target/Language.cpp +++ source/Target/Language.cpp @@ -348,6 +348,15 @@ } } +std::set Language::GetSupportedLanguages() { + std::set supported_languages; + ForEach([&](Language *lang) { + supported_languages.emplace(lang->GetLanguageType()); + return true; + }); + return supported_languages; +} + void Language::GetLanguagesSupportingTypeSystems( std::set &languages, std::set &languages_for_expressions) { Index: source/Target/Process.cpp =================================================================== --- source/Target/Process.cpp +++ source/Target/Process.cpp @@ -44,6 +44,7 @@ #include "lldb/Target/InstrumentationRuntime.h" #include "lldb/Target/JITLoader.h" #include "lldb/Target/JITLoaderList.h" +#include "lldb/Target/Language.h" #include "lldb/Target/LanguageRuntime.h" #include "lldb/Target/MemoryHistory.h" #include "lldb/Target/MemoryRegionInfo.h" @@ -1547,6 +1548,27 @@ return m_abi_sp; } +std::vector +Process::GetLanguageRuntimes(bool retry_if_null) { + std::vector language_runtimes; + + if (m_finalizing) + return language_runtimes; + + std::lock_guard guard(m_language_runtimes_mutex); + // Before we pass off a copy of the language runtimes, we must make sure that + // our collection is properly populated. It's possible that some of the + // language runtimes were not loaded yet, either because nobody requested it + // yet or the proper condition for loading wasn't yet met (e.g. libc++.so + // hadn't been loaded). + for (const lldb::LanguageType lang_type : Language::GetSupportedLanguages()) { + if (LanguageRuntime *runtime = GetLanguageRuntime(lang_type, retry_if_null)) + language_runtimes.emplace_back(runtime); + } + + return language_runtimes; +} + LanguageRuntime *Process::GetLanguageRuntime(lldb::LanguageType language, bool retry_if_null) { if (m_finalizing) Index: source/Target/Thread.cpp =================================================================== --- source/Target/Thread.cpp +++ source/Target/Thread.cpp @@ -2211,11 +2211,9 @@ // NOTE: Even though this behavior is generalized, only ObjC is actually // supported at the moment. - for (unsigned lang = eLanguageTypeUnknown; lang < eNumLanguageTypes; lang++) { - if (auto runtime = GetProcess()->GetLanguageRuntime( - static_cast(lang))) - if (auto e = runtime->GetExceptionObjectForThread(shared_from_this())) - return e; + for (LanguageRuntime *runtime : GetProcess()->GetLanguageRuntimes()) { + if (auto e = runtime->GetExceptionObjectForThread(shared_from_this())) + return e; } return ValueObjectSP(); @@ -2228,11 +2226,9 @@ // NOTE: Even though this behavior is generalized, only ObjC is actually // supported at the moment. - for (unsigned lang = eLanguageTypeUnknown; lang < eNumLanguageTypes; lang++) { - if (auto runtime = GetProcess()->GetLanguageRuntime( - static_cast(lang))) - if (auto bt = runtime->GetBacktraceThreadFromException(exception)) - return bt; + for (LanguageRuntime *runtime : GetProcess()->GetLanguageRuntimes()) { + if (auto bt = runtime->GetBacktraceThreadFromException(exception)) + return bt; } return ThreadSP();