Skip to content

Commit fb10b01

Browse files
committed
[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
1 parent 0e7ff05 commit fb10b01

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

lldb/source/Commands/CommandObjectMultiword.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,10 @@ void CommandObjectMultiword::HandleCompletion(CompletionRequest &request) {
274274

275275
StringList new_matches;
276276
CommandObject *sub_command_object = GetSubcommandObject(arg0, &new_matches);
277-
if (sub_command_object == nullptr) {
278-
request.AddCompletions(new_matches);
277+
278+
// The subcommand is ambiguous. The completion isn't meaningful.
279+
if (!sub_command_object)
279280
return;
280-
}
281281

282282
// Remove the one match that we got from calling GetSubcommandObject.
283283
new_matches.DeleteStringAtIndex(0);

lldb/test/API/functionalities/completion/TestCompletion.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,3 +880,11 @@ def test_complete_breakpoint_with_names(self):
880880
self.complete_from_to("breakpoint set -N n", "breakpoint set -N n")
881881
self.assertTrue(bp1.AddNameWithErrorHandling("nn"))
882882
self.complete_from_to("breakpoint set -N ", "breakpoint set -N nn")
883+
884+
def test_ambiguous_command(self):
885+
"""Test completing an ambiguous commands"""
886+
self.complete_from_to("settings s", ['set', 'show'])
887+
888+
def test_ambiguous_subcommand(self):
889+
"""Test completing a subcommand of an ambiguous command"""
890+
self.complete_from_to("settings s ta", [])

0 commit comments

Comments
 (0)