[Lldb-commits] [lldb] r156961 - in /lldb/trunk: source/Interpreter/CommandInterpreter.cpp test/functionalities/abbreviation/TestAbbreviations.py
Filipe Cabecinhas
me at filcab.net
Wed May 16 16:25:55 PDT 2012
Author: filcab
Date: Wed May 16 18:25:54 2012
New Revision: 156961
URL: http://llvm.org/viewvc/llvm-project?rev=156961&view=rev
Log:
Warn the user when several commands match the input given.
Added a testcase.
Modified:
lldb/trunk/source/Interpreter/CommandInterpreter.cpp
lldb/trunk/test/functionalities/abbreviation/TestAbbreviations.py
Modified: lldb/trunk/source/Interpreter/CommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandInterpreter.cpp?rev=156961&r1=156960&r2=156961&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandInterpreter.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandInterpreter.cpp Wed May 16 18:25:54 2012
@@ -1326,6 +1326,7 @@
StreamString revised_command_line;
size_t actual_cmd_name_len = 0;
std::string next_word;
+ StringList matches;
while (!done)
{
char quote_char = '\0';
@@ -1346,7 +1347,7 @@
}
else
{
- cmd_obj = GetCommandObject (next_word.c_str());
+ cmd_obj = GetCommandObject (next_word.c_str(), &matches);
if (cmd_obj)
{
actual_cmd_name_len += next_word.length();
@@ -1392,7 +1393,26 @@
if (cmd_obj == NULL)
{
- result.AppendErrorWithFormat ("'%s' is not a valid command.\n", next_word.c_str());
+ uint32_t num_matches = matches.GetSize();
+ if (matches.GetSize() > 1) {
+ std::string error_msg;
+ error_msg.assign ("Ambiguous command '");
+ error_msg.append(next_word.c_str());
+ error_msg.append ("'.");
+
+ error_msg.append (" Possible matches:");
+
+ for (uint32_t i = 0; i < num_matches; ++i) {
+ error_msg.append ("\n\t");
+ error_msg.append (matches.GetStringAtIndex(i));
+ }
+ error_msg.append ("\n");
+ result.AppendRawError (error_msg.c_str(), error_msg.size());
+ } else {
+ // We didn't have only one match, otherwise we wouldn't get here.
+ assert(num_matches == 0);
+ result.AppendErrorWithFormat ("'%s' is not a valid command.\n", next_word.c_str());
+ }
result.SetStatus (eReturnStatusFailed);
return false;
}
Modified: lldb/trunk/test/functionalities/abbreviation/TestAbbreviations.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/abbreviation/TestAbbreviations.py?rev=156961&r1=156960&r2=156961&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/abbreviation/TestAbbreviations.py (original)
+++ lldb/trunk/test/functionalities/abbreviation/TestAbbreviations.py Wed May 16 18:25:54 2012
@@ -30,9 +30,15 @@
COMMAND_FAILED_AS_EXPECTED, error = True,
substrs = ["error: 'gurp' is not a valid command."])
+ # Only one matching command: execute it.
self.expect("h",
startstr = "The following is a list of built-in, permanent debugger commands:")
+ # Several matching commands: list them and error out.
+ self.expect("t",
+ COMMAND_FAILED_AS_EXPECTED, error = True,
+ substrs = ["Ambiguous command 't'. Possible matches:",
+ "target", "thread", "type"])
self.expect("com sou ./change_prompt.lldb",
patterns = ["Executing commands in '.*change_prompt.lldb'"])
More information about the lldb-commits
mailing list