Skip to content

Commit 100863c

Browse files
committed
[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
1 parent bc5f2d1 commit 100863c

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

lldb/include/lldb/Core/PluginManager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,8 @@ class PluginManager {
449449

450450
static REPLCreateInstance GetREPLCreateCallbackAtIndex(uint32_t idx);
451451

452+
static LanguageSet GetREPLSupportedLanguagesAtIndex(uint32_t idx);
453+
452454
static LanguageSet GetREPLAllTypeSystemSupportedLanguages();
453455

454456
// Some plug-ins might register a DebuggerInitializeCallback callback when

lldb/source/Core/PluginManager.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,6 +1345,12 @@ REPLCreateInstance PluginManager::GetREPLCreateCallbackAtIndex(uint32_t idx) {
13451345
return GetREPLInstances().GetCallbackAtIndex(idx);
13461346
}
13471347

1348+
LanguageSet PluginManager::GetREPLSupportedLanguagesAtIndex(uint32_t idx) {
1349+
const auto &instances = GetREPLInstances().GetInstances();
1350+
return idx < instances.size() ? instances[idx].supported_languages
1351+
: LanguageSet();
1352+
}
1353+
13481354
LanguageSet PluginManager::GetREPLAllTypeSystemSupportedLanguages() {
13491355
const auto &instances = GetREPLInstances().GetInstances();
13501356
LanguageSet all;

lldb/source/Expression/REPL.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ lldb::REPLSP REPL::Create(Status &err, lldb::LanguageType language,
3939
lldb::REPLSP ret;
4040

4141
while (REPLCreateInstance create_instance =
42-
PluginManager::GetREPLCreateCallbackAtIndex(idx++)) {
42+
PluginManager::GetREPLCreateCallbackAtIndex(idx)) {
43+
LanguageSet supported_languages =
44+
PluginManager::GetREPLSupportedLanguagesAtIndex(idx++);
45+
if (!supported_languages[language])
46+
continue;
4347
ret = (*create_instance)(err, language, debugger, target, repl_options);
4448
if (ret) {
4549
break;

lldb/test/Shell/REPL/Basic.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Basic sanity checking of the REPL.
2+
3+
// RUN: %lldb --repl --repl-language c++ 2>&1 | FileCheck %s --check-prefix=CPP
4+
// CPP: error: must have a target to create a REPL
5+
6+
// RUN: %lldb --repl --repl-language python 2>&1 | FileCheck %s --check-prefix=PYTHON
7+
// PYTHON: error: couldn't find a REPL for python
8+
9+
// RUN: not %lldb --repl --repl-language bogus 2>&1 | FileCheck %s --check-prefix=BOGUS
10+
// BOGUS: error: Unrecognized language name: "bogus"

0 commit comments

Comments
 (0)