[Lldb-commits] [PATCH] D154643: [lldb] Prevent crash when completing ambiguous subcommands

2023-07-10 Thread Jonas Devlieghere via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfb10b01cca85: [lldb] Prevent crash when completing ambiguous 
subcommands (authored by JDevlieghere).
Herald added a project: LLDB.

Changed prior to commit:
  https://reviews.llvm.org/D154643?vs=537829=538837#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154643/new/

https://reviews.llvm.org/D154643

Files:
  lldb/source/Commands/CommandObjectMultiword.cpp
  lldb/test/API/functionalities/completion/TestCompletion.py


Index: lldb/test/API/functionalities/completion/TestCompletion.py
===
--- lldb/test/API/functionalities/completion/TestCompletion.py
+++ lldb/test/API/functionalities/completion/TestCompletion.py
@@ -880,3 +880,11 @@
 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", [])
Index: lldb/source/Commands/CommandObjectMultiword.cpp
===
--- lldb/source/Commands/CommandObjectMultiword.cpp
+++ lldb/source/Commands/CommandObjectMultiword.cpp
@@ -274,10 +274,10 @@
 
   StringList new_matches;
   CommandObject *sub_command_object = GetSubcommandObject(arg0, _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);


Index: lldb/test/API/functionalities/completion/TestCompletion.py
===
--- lldb/test/API/functionalities/completion/TestCompletion.py
+++ lldb/test/API/functionalities/completion/TestCompletion.py
@@ -880,3 +880,11 @@
 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", [])
Index: lldb/source/Commands/CommandObjectMultiword.cpp
===
--- lldb/source/Commands/CommandObjectMultiword.cpp
+++ lldb/source/Commands/CommandObjectMultiword.cpp
@@ -274,10 +274,10 @@
 
   StringList new_matches;
   CommandObject *sub_command_object = GetSubcommandObject(arg0, _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);
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D154643: [lldb] Prevent crash when completing ambiguous subcommands

2023-07-10 Thread Jim Ingham via Phabricator via lldb-commits
jingham accepted this revision.
jingham added a comment.
This revision is now accepted and ready to land.

This looks like it might be the place where we also say "`set s` could either 
be `set` or `show`".  But that's actually done elsewhere so this change is 
okay.  We should maybe make sure we have a test for `setting s` -> {`set` 
or `show`} options.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154643/new/

https://reviews.llvm.org/D154643

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D154643: [lldb] Prevent crash when completing ambiguous subcommands

2023-07-06 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere created this revision.
JDevlieghere added a reviewer: jingham.
Herald added a project: All.
JDevlieghere requested review of this revision.

Fix a crash when trying to complete an ambiguous subcommand. Take `set s tar` 
for example: here `s` is ambiguous between `set` and `show`. Pressing TAB after 
this input currently crashes LLDB because we go look for the subcommand and 
fail to find one, but still add the original command (`s`) as a completion. 
This causes problems later on when we're trying to insert the completion and 
find that the "completed string" is shorter than the input string and call 
`std::string::substr` to eliminate the common prefix.

  frame #12: 0x000133fafb44 
liblldb.17.0.0git.dylib`lldb_private::Editline::TabCommand(this=0x00010a645aa0,
 ch=9) at Editline.cpp:1044:24
 1041   std::string longest_prefix = completions.LongestCommonPrefix();
 1042   if (!longest_prefix.empty())
 1043 longest_prefix =
  -> 1044 
longest_prefix.substr(request.GetCursorArgumentPrefix().size());
  (lldb) v longest_prefix
  (std::string) longest_prefix = "s"
  (lldb) p request.GetCursorArgumentPrefix().size()
  (size_t) 3

rdar://111848598


https://reviews.llvm.org/D154643

Files:
  lldb/source/Commands/CommandObjectMultiword.cpp
  lldb/test/API/functionalities/completion/TestCompletion.py


Index: lldb/test/API/functionalities/completion/TestCompletion.py
===
--- lldb/test/API/functionalities/completion/TestCompletion.py
+++ lldb/test/API/functionalities/completion/TestCompletion.py
@@ -868,3 +868,7 @@
 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_option(self):
+"""Make sure we don't crash when completing ambiguous commands"""
+self.complete_from_to("set s ta", [])
Index: lldb/source/Commands/CommandObjectMultiword.cpp
===
--- lldb/source/Commands/CommandObjectMultiword.cpp
+++ lldb/source/Commands/CommandObjectMultiword.cpp
@@ -274,10 +274,10 @@
 
   StringList new_matches;
   CommandObject *sub_command_object = GetSubcommandObject(arg0, _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);


Index: lldb/test/API/functionalities/completion/TestCompletion.py
===
--- lldb/test/API/functionalities/completion/TestCompletion.py
+++ lldb/test/API/functionalities/completion/TestCompletion.py
@@ -868,3 +868,7 @@
 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_option(self):
+"""Make sure we don't crash when completing ambiguous commands"""
+self.complete_from_to("set s ta", [])
Index: lldb/source/Commands/CommandObjectMultiword.cpp
===
--- lldb/source/Commands/CommandObjectMultiword.cpp
+++ lldb/source/Commands/CommandObjectMultiword.cpp
@@ -274,10 +274,10 @@
 
   StringList new_matches;
   CommandObject *sub_command_object = GetSubcommandObject(arg0, _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);
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits