JDevlieghere created this revision.
JDevlieghere added reviewers: aprantl, teemperor.
JDevlieghere requested review of this revision.
Currently, we'll try to instantiate a ClangREPL for every known language. The
plugin manager already knows what languages are supported, so rely on that to
only instantiate a REPL when we know the requested language in supported.
rdar://86439474
https://reviews.llvm.org/D115698
Files:
lldb/include/lldb/Core/PluginManager.h
lldb/source/Core/PluginManager.cpp
lldb/source/Expression/REPL.cpp
lldb/test/Shell/REPL/Basic.test
Index: lldb/test/Shell/REPL/Basic.test
===================================================================
--- /dev/null
+++ 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"
Index: lldb/source/Expression/REPL.cpp
===================================================================
--- lldb/source/Expression/REPL.cpp
+++ lldb/source/Expression/REPL.cpp
@@ -39,7 +39,11 @@
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;
Index: lldb/source/Core/PluginManager.cpp
===================================================================
--- lldb/source/Core/PluginManager.cpp
+++ lldb/source/Core/PluginManager.cpp
@@ -1345,6 +1345,12 @@
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;
Index: lldb/include/lldb/Core/PluginManager.h
===================================================================
--- lldb/include/lldb/Core/PluginManager.h
+++ lldb/include/lldb/Core/PluginManager.h
@@ -449,6 +449,8 @@
static REPLCreateInstance GetREPLCreateCallbackAtIndex(uint32_t idx);
+ static LanguageSet GetREPLSupportedLanguagesAtIndex(uint32_t idx);
+
static LanguageSet GetREPLAllTypeSystemSupportedLanguages();
// Some plug-ins might register a DebuggerInitializeCallback callback when
Index: lldb/test/Shell/REPL/Basic.test
===================================================================
--- /dev/null
+++ 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"
Index: lldb/source/Expression/REPL.cpp
===================================================================
--- lldb/source/Expression/REPL.cpp
+++ lldb/source/Expression/REPL.cpp
@@ -39,7 +39,11 @@
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;
Index: lldb/source/Core/PluginManager.cpp
===================================================================
--- lldb/source/Core/PluginManager.cpp
+++ lldb/source/Core/PluginManager.cpp
@@ -1345,6 +1345,12 @@
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;
Index: lldb/include/lldb/Core/PluginManager.h
===================================================================
--- lldb/include/lldb/Core/PluginManager.h
+++ lldb/include/lldb/Core/PluginManager.h
@@ -449,6 +449,8 @@
static REPLCreateInstance GetREPLCreateCallbackAtIndex(uint32_t idx);
+ static LanguageSet GetREPLSupportedLanguagesAtIndex(uint32_t idx);
+
static LanguageSet GetREPLAllTypeSystemSupportedLanguages();
// Some plug-ins might register a DebuggerInitializeCallback callback when
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits