diff options
author | Jonas Devlieghere <jonas@devlieghere.com> | 2023-07-10 13:59:07 -0700 |
---|---|---|
committer | Jonas Devlieghere <jonas@devlieghere.com> | 2023-07-10 14:50:40 -0700 |
commit | fb10b01cca85306c8a94826e31e8a4dfb8aff502 (patch) | |
tree | 18ab5396b69a87dbb04cf7d9fa5c65f7284373f8 | |
parent | 0e7ff05fb35169addd970f55b2692382ad290b78 (diff) | |
download | llvm-fb10b01cca85306c8a94826e31e8a4dfb8aff502.zip llvm-fb10b01cca85306c8a94826e31e8a4dfb8aff502.tar.gz llvm-fb10b01cca85306c8a94826e31e8a4dfb8aff502.tar.bz2 |
[lldb] Prevent crash when completing ambiguous subcommands
Fix a crash when trying to complete an ambiguous subcommand. Take `set s
tar` for example: for the subcommand `s` there's ambiguity between set
and show. Pressing TAB after this input currently crashes LLDB. The
problem is that we're trying to complete `tar` but give up at `s`
because of the ambiguity. LLDB doesn't expect the completed string to be
shorter than the current string and crashes when trying to eliminate the
common prefix.
rdar://111848598
Differential revision: https://reviews.llvm.org/D154643
-rw-r--r-- | lldb/source/Commands/CommandObjectMultiword.cpp | 6 | ||||
-rw-r--r-- | lldb/test/API/functionalities/completion/TestCompletion.py | 8 |
2 files changed, 11 insertions, 3 deletions
diff --git a/lldb/source/Commands/CommandObjectMultiword.cpp b/lldb/source/Commands/CommandObjectMultiword.cpp index bae2717..7ef829a 100644 --- a/lldb/source/Commands/CommandObjectMultiword.cpp +++ b/lldb/source/Commands/CommandObjectMultiword.cpp @@ -274,10 +274,10 @@ void CommandObjectMultiword::HandleCompletion(CompletionRequest &request) { StringList new_matches; CommandObject *sub_command_object = GetSubcommandObject(arg0, &new_matches); - if (sub_command_object == nullptr) { - request.AddCompletions(new_matches); + + // The subcommand is ambiguous. The completion isn't meaningful. + if (!sub_command_object) return; - } // Remove the one match that we got from calling GetSubcommandObject. new_matches.DeleteStringAtIndex(0); diff --git a/lldb/test/API/functionalities/completion/TestCompletion.py b/lldb/test/API/functionalities/completion/TestCompletion.py index 2d83abd..4b41326 100644 --- a/lldb/test/API/functionalities/completion/TestCompletion.py +++ b/lldb/test/API/functionalities/completion/TestCompletion.py @@ -880,3 +880,11 @@ class CommandLineCompletionTestCase(TestBase): self.complete_from_to("breakpoint set -N n", "breakpoint set -N n") self.assertTrue(bp1.AddNameWithErrorHandling("nn")) self.complete_from_to("breakpoint set -N ", "breakpoint set -N nn") + + def test_ambiguous_command(self): + """Test completing an ambiguous commands""" + self.complete_from_to("settings s", ['set', 'show']) + + def test_ambiguous_subcommand(self): + """Test completing a subcommand of an ambiguous command""" + self.complete_from_to("settings s ta", []) |