Fix bug where using incomplete strings for command names causes
lldb to crash (because of attempt to look for full names when full
names were not used).
git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@121607 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Interpreter/CommandInterpreter.cpp b/source/Interpreter/CommandInterpreter.cpp
index 4651ad9..abd0943 100644
--- a/source/Interpreter/CommandInterpreter.cpp
+++ b/source/Interpreter/CommandInterpreter.cpp
@@ -710,6 +710,7 @@
// replacements taken care of; 3). whether or not the Execute function wants raw input or not.
StreamString revised_command_line;
+ size_t actual_cmd_name_len = 0;
while (!done)
{
StripFirstWord (command_string, next_word);
@@ -720,12 +721,14 @@
revised_command_line.Printf ("%s", alias_result.c_str());
if (cmd_obj)
wants_raw_input = cmd_obj->WantsRawCommandString ();
+ actual_cmd_name_len = strlen (cmd_obj->GetCommandName());
}
else if (!cmd_obj)
{
cmd_obj = GetCommandObject (next_word.c_str());
if (cmd_obj)
{
+ actual_cmd_name_len += next_word.length();
revised_command_line.Printf ("%s", next_word.c_str());
wants_raw_input = cmd_obj->WantsRawCommandString ();
}
@@ -739,6 +742,7 @@
CommandObject *sub_cmd_obj = ((CommandObjectMultiword *) cmd_obj)->GetSubcommandObject (next_word.c_str());
if (sub_cmd_obj)
{
+ actual_cmd_name_len += next_word.length() + 1;
revised_command_line.Printf (" %s", next_word.c_str());
cmd_obj = sub_cmd_obj;
wants_raw_input = cmd_obj->WantsRawCommandString ();
@@ -805,7 +809,12 @@
command_string = revised_command_line.GetData();
std::string command_name (cmd_obj->GetCommandName());
- std::string remainder (command_string.substr (command_name.size()));
+ std::string remainder;
+ if (actual_cmd_name_len < command_string.length())
+ remainder = command_string.substr (actual_cmd_name_len); // Note: 'actual_cmd_name_len' may be considerably shorter
+ // than cmd_obj->GetCommandName(), because name completion
+ // allows users to enter short versions of the names,
+ // e.g. 'br s' for 'breakpoint set'.
// Remove any initial spaces
std::string white_space (" \t\v");