[Lldb-commits] [lldb] r121607 - /lldb/trunk/source/Interpreter/CommandInterpreter.cpp

Caroline Tice ctice at apple.com
Sat Dec 11 00:16:56 PST 2010


Author: ctice
Date: Sat Dec 11 02:16:56 2010
New Revision: 121607

URL: http://llvm.org/viewvc/llvm-project?rev=121607&view=rev
Log:
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).


Modified:
    lldb/trunk/source/Interpreter/CommandInterpreter.cpp

Modified: lldb/trunk/source/Interpreter/CommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandInterpreter.cpp?rev=121607&r1=121606&r2=121607&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandInterpreter.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandInterpreter.cpp Sat Dec 11 02:16:56 2010
@@ -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");





More information about the lldb-commits mailing list