Author: Jonas Devlieghere Date: 2021-12-14T12:05:35-08:00 New Revision: 100863ccd8d41091f90749ba76d91f6dfafdde57
URL: https://github.com/llvm/llvm-project/commit/100863ccd8d41091f90749ba76d91f6dfafdde57 DIFF: https://github.com/llvm/llvm-project/commit/100863ccd8d41091f90749ba76d91f6dfafdde57.diff LOG: [lldb] Check if language is supported before creating a REPL instance Currently, we'll try to instantiate a ClangREPL for every known language. The plugin manager already knows what languages it supports, so rely on that to only instantiate a REPL when we know the requested language is supported. rdar://86439474 Differential revision: https://reviews.llvm.org/D115698 Added: lldb/test/Shell/REPL/Basic.test Modified: lldb/include/lldb/Core/PluginManager.h lldb/source/Core/PluginManager.cpp lldb/source/Expression/REPL.cpp Removed: ################################################################################ diff --git a/lldb/include/lldb/Core/PluginManager.h b/lldb/include/lldb/Core/PluginManager.h index 7dc99bf3e7558..1ab9d26d3af4f 100644 --- a/lldb/include/lldb/Core/PluginManager.h +++ b/lldb/include/lldb/Core/PluginManager.h @@ -449,6 +449,8 @@ class PluginManager { static REPLCreateInstance GetREPLCreateCallbackAtIndex(uint32_t idx); + static LanguageSet GetREPLSupportedLanguagesAtIndex(uint32_t idx); + static LanguageSet GetREPLAllTypeSystemSupportedLanguages(); // Some plug-ins might register a DebuggerInitializeCallback callback when diff --git a/lldb/source/Core/PluginManager.cpp b/lldb/source/Core/PluginManager.cpp index 801591129244f..37050494aa2ea 100644 --- a/lldb/source/Core/PluginManager.cpp +++ b/lldb/source/Core/PluginManager.cpp @@ -1345,6 +1345,12 @@ REPLCreateInstance PluginManager::GetREPLCreateCallbackAtIndex(uint32_t idx) { return GetREPLInstances().GetCallbackAtIndex(idx); } +LanguageSet PluginManager::GetREPLSupportedLanguagesAtIndex(uint32_t idx) { + const auto &instances = GetREPLInstances().GetInstances(); + return idx < instances.size() ? instances[idx].supported_languages + : LanguageSet(); +} + LanguageSet PluginManager::GetREPLAllTypeSystemSupportedLanguages() { const auto &instances = GetREPLInstances().GetInstances(); LanguageSet all; diff --git a/lldb/source/Expression/REPL.cpp b/lldb/source/Expression/REPL.cpp index 9cd6129eedd7a..be41c60ebb5ff 100644 --- a/lldb/source/Expression/REPL.cpp +++ b/lldb/source/Expression/REPL.cpp @@ -39,7 +39,11 @@ lldb::REPLSP REPL::Create(Status &err, lldb::LanguageType language, lldb::REPLSP ret; while (REPLCreateInstance create_instance = - PluginManager::GetREPLCreateCallbackAtIndex(idx++)) { + PluginManager::GetREPLCreateCallbackAtIndex(idx)) { + LanguageSet supported_languages = + PluginManager::GetREPLSupportedLanguagesAtIndex(idx++); + if (!supported_languages[language]) + continue; ret = (*create_instance)(err, language, debugger, target, repl_options); if (ret) { break; diff --git a/lldb/test/Shell/REPL/Basic.test b/lldb/test/Shell/REPL/Basic.test new file mode 100644 index 0000000000000..39791133d5f2c --- /dev/null +++ b/lldb/test/Shell/REPL/Basic.test @@ -0,0 +1,10 @@ +// Basic sanity checking of the REPL. + +// RUN: %lldb --repl --repl-language c++ 2>&1 | FileCheck %s --check-prefix=CPP +// CPP: error: must have a target to create a REPL + +// RUN: %lldb --repl --repl-language python 2>&1 | FileCheck %s --check-prefix=PYTHON +// PYTHON: error: couldn't find a REPL for python + +// RUN: not %lldb --repl --repl-language bogus 2>&1 | FileCheck %s --check-prefix=BOGUS +// BOGUS: error: Unrecognized language name: "bogus" _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits