[Lldb-commits] [lldb] fb10b01 - [lldb] Prevent crash when completing ambiguous subcommands
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Mon Jul 10 14:50:44 PDT 2023
Author: Jonas Devlieghere
Date: 2023-07-10T14:50:40-07:00
New Revision: fb10b01cca85306c8a94826e31e8a4dfb8aff502
URL: https://github.com/llvm/llvm-project/commit/fb10b01cca85306c8a94826e31e8a4dfb8aff502
DIFF: https://github.com/llvm/llvm-project/commit/fb10b01cca85306c8a94826e31e8a4dfb8aff502.diff
LOG: [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
Added:
Modified:
lldb/source/Commands/CommandObjectMultiword.cpp
lldb/test/API/functionalities/completion/TestCompletion.py
Removed:
################################################################################
diff --git a/lldb/source/Commands/CommandObjectMultiword.cpp b/lldb/source/Commands/CommandObjectMultiword.cpp
index bae2717ffe68ec..7ef829afaab6e7 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 2d83abd7a6573e..4b413260279b9c 100644
--- a/lldb/test/API/functionalities/completion/TestCompletion.py
+++ b/lldb/test/API/functionalities/completion/TestCompletion.py
@@ -880,3 +880,11 @@ def test_complete_breakpoint_with_names(self):
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", [])
More information about the lldb-commits
mailing list