[Lldb-commits] [lldb] r157727 - in /lldb/trunk: include/lldb/Interpreter/CommandInterpreter.h source/API/SBCommandInterpreter.cpp source/Commands/CommandObjectBreakpointCommand.cpp source/Commands/CommandObjectCommands.cpp source/Interpreter/CommandInterpreter.cpp source/Interpreter/CommandObjectRegexCommand.cpp source/Target/Target.cpp

Enrico Granata egranata at apple.com
Wed May 30 18:09:07 PDT 2012


Author: enrico
Date: Wed May 30 20:09:06 2012
New Revision: 157727

URL: http://llvm.org/viewvc/llvm-project?rev=157727&view=rev
Log:
<rdar://problem/11328896> Fixing a bug where regex commands were saved in the history even if they came from a 'command sourced' file - this fix introduces a command sourcing depth and disables history for all levels of depth > 0, which means no commands go into history when being sourced from a file. we need an integer depth because command files might themselves source other command files, ...

Modified:
    lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h
    lldb/trunk/source/API/SBCommandInterpreter.cpp
    lldb/trunk/source/Commands/CommandObjectBreakpointCommand.cpp
    lldb/trunk/source/Commands/CommandObjectCommands.cpp
    lldb/trunk/source/Interpreter/CommandInterpreter.cpp
    lldb/trunk/source/Interpreter/CommandObjectRegexCommand.cpp
    lldb/trunk/source/Target/Target.cpp

Modified: lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h?rev=157727&r1=157726&r2=157727&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h (original)
+++ lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h Wed May 30 20:09:06 2012
@@ -146,7 +146,7 @@
 
     bool
     HandleCommand (const char *command_line, 
-                   bool add_to_history, 
+                   LazyBool add_to_history,
                    CommandReturnObject &result, 
                    ExecutionContext *override_context = NULL,
                    bool repeat_on_empty_command = true,
@@ -179,7 +179,8 @@
                     bool stop_on_continue, 
                     bool stop_on_error, 
                     bool echo_commands,
-                    bool print_results, 
+                    bool print_results,
+                    LazyBool add_to_history,
                     CommandReturnObject &result);
 
     //------------------------------------------------------------------
@@ -209,7 +210,8 @@
                             bool stop_on_continue, 
                             bool stop_on_error, 
                             bool echo_commands,
-                            bool print_results, 
+                            bool print_results,
+                            LazyBool add_to_history,
                             CommandReturnObject &result);
 
     CommandObject *
@@ -477,6 +479,7 @@
     char m_repeat_char;
     bool m_batch_command_mode;
     ChildrenTruncatedWarningStatus m_truncation_warning;    // Whether we truncated children and whether the user has been told
+    uint32_t m_command_source_depth;
     
 };
 

Modified: lldb/trunk/source/API/SBCommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBCommandInterpreter.cpp?rev=157727&r1=157726&r2=157727&view=diff
==============================================================================
--- lldb/trunk/source/API/SBCommandInterpreter.cpp (original)
+++ lldb/trunk/source/API/SBCommandInterpreter.cpp Wed May 30 20:09:06 2012
@@ -94,7 +94,7 @@
         Mutex::Locker api_locker;
         if (target_sp)
             api_locker.Lock(target_sp->GetAPIMutex());
-        m_opaque_ptr->HandleCommand (command_line, add_to_history, result.ref());
+        m_opaque_ptr->HandleCommand (command_line, add_to_history ? eLazyBoolYes : eLazyBoolNo, result.ref());
     }
     else
     {

Modified: lldb/trunk/source/Commands/CommandObjectBreakpointCommand.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectBreakpointCommand.cpp?rev=157727&r1=157726&r2=157727&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectBreakpointCommand.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectBreakpointCommand.cpp Wed May 30 20:09:06 2012
@@ -866,7 +866,8 @@
                                                              stop_on_continue, 
                                                              data->stop_on_error, 
                                                              echo_commands, 
-                                                             print_results, 
+                                                             print_results,
+                                                             eLazyBoolNo,
                                                              result);
             result.GetImmediateOutputStream()->Flush();
             result.GetImmediateErrorStream()->Flush();

Modified: lldb/trunk/source/Commands/CommandObjectCommands.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectCommands.cpp?rev=157727&r1=157726&r2=157727&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectCommands.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectCommands.cpp Wed May 30 20:09:06 2012
@@ -284,7 +284,8 @@
                                                   m_options.m_stop_on_continue, 
                                                   m_options.m_stop_on_error, 
                                                   echo_commands, 
-                                                  print_results, 
+                                                  print_results,
+                                                  eLazyBoolCalculate,
                                                   result);
         }
         else
@@ -295,6 +296,36 @@
         return result.Succeeded();
 
     }
+    
+    virtual const char*
+    GetRepeatCommand (Args &current_command_args, uint32_t index)
+    {
+        return "";
+    }
+    
+    int
+    HandleArgumentCompletion (Args &input,
+                              int &cursor_index,
+                              int &cursor_char_position,
+                              OptionElementVector &opt_element_vector,
+                              int match_start_point,
+                              int max_return_elements,
+                              bool &word_complete,
+                              StringList &matches)
+    {
+        std::string completion_str (input.GetArgumentAtIndex(cursor_index));
+        completion_str.erase (cursor_char_position);
+        
+        CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, 
+                                                             CommandCompletions::eDiskFileCompletion,
+                                                             completion_str.c_str(),
+                                                             match_start_point,
+                                                             max_return_elements,
+                                                             NULL,
+                                                             word_complete,
+                                                             matches);
+        return matches.GetSize();
+    }
 };
 
 OptionDefinition

Modified: lldb/trunk/source/Interpreter/CommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandInterpreter.cpp?rev=157727&r1=157726&r2=157727&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandInterpreter.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandInterpreter.cpp Wed May 30 20:09:06 2012
@@ -80,8 +80,8 @@
     m_script_interpreter_ap (),
     m_comment_char ('#'),
     m_repeat_char ('!'),
-    m_batch_command_mode (false),
-    m_truncation_warning(eNoTruncation)
+    m_truncation_warning(eNoTruncation),
+    m_command_source_depth (0)
 {
     const char *dbg_name = debugger.GetInstanceName().AsCString();
     std::string lang_name = ScriptInterpreter::LanguageToString (script_language);
@@ -1218,7 +1218,7 @@
 
 bool
 CommandInterpreter::HandleCommand (const char *command_line, 
-                                   bool add_to_history,
+                                   LazyBool lazy_add_to_history,
                                    CommandReturnObject &result,
                                    ExecutionContext *override_context,
                                    bool repeat_on_empty_command,
@@ -1246,7 +1246,14 @@
     
     if (!no_context_switching)
         UpdateExecutionContext (override_context);
-
+    
+    // <rdar://problem/11328896>
+    bool add_to_history;
+    if (lazy_add_to_history == eLazyBoolCalculate)
+        add_to_history = (m_command_source_depth == 0);
+    else
+        add_to_history = (lazy_add_to_history == eLazyBoolYes);
+    
     bool empty_command = false;
     bool comment_command = false;
     if (command_string.empty())
@@ -2226,7 +2233,7 @@
         bool echo_commands    = false;
         bool print_results    = false;
         
-        HandleCommandsFromFile (init_file, exe_ctx, stop_on_continue, stop_on_error, echo_commands, print_results, result);
+        HandleCommandsFromFile (init_file, exe_ctx, stop_on_continue, stop_on_error, echo_commands, print_results, eLazyBoolNo, result);
     }
     else
     {
@@ -2258,6 +2265,7 @@
                                     bool stop_on_error,
                                     bool echo_commands,
                                     bool print_results,
+                                    LazyBool add_to_history,
                                     CommandReturnObject &result)
 {
     size_t num_lines = commands.GetSize();
@@ -2294,7 +2302,7 @@
         CommandReturnObject tmp_result;
         // If override_context is not NULL, pass no_context_switching = true for
         // HandleCommand() since we updated our context already.
-        bool success = HandleCommand(cmd, false, tmp_result,
+        bool success = HandleCommand(cmd, add_to_history, tmp_result,
                                      NULL, /* override_context */
                                      true, /* repeat_on_empty_command */
                                      override_context != NULL /* no_context_switching */);
@@ -2372,6 +2380,7 @@
                                             bool stop_on_error,
                                             bool echo_command,
                                             bool print_result,
+                                            LazyBool add_to_history,
                                             CommandReturnObject &result)
 {
     if (cmd_file.Exists())
@@ -2385,7 +2394,9 @@
             result.SetStatus (eReturnStatusFailed);
             return;
         }
-        HandleCommands (commands, context, stop_on_continue, stop_on_error, echo_command, print_result, result);
+        m_command_source_depth++;
+        HandleCommands (commands, context, stop_on_continue, stop_on_error, echo_command, print_result, add_to_history, result);
+        m_command_source_depth--;
     }
     else
     {

Modified: lldb/trunk/source/Interpreter/CommandObjectRegexCommand.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandObjectRegexCommand.cpp?rev=157727&r1=157726&r2=157727&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandObjectRegexCommand.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandObjectRegexCommand.cpp Wed May 30 20:09:06 2012
@@ -88,7 +88,7 @@
                 }
                 // Interpret the new command and return this as the result!
                 result.GetOutputStream().Printf("%s\n", new_command.c_str());
-                return m_interpreter.HandleCommand(new_command.c_str(), true, result);
+                return m_interpreter.HandleCommand(new_command.c_str(), eLazyBoolCalculate, result);
             }
         }
         result.SetStatus(eReturnStatusFailed);

Modified: lldb/trunk/source/Target/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=157727&r1=157726&r2=157727&view=diff
==============================================================================
--- lldb/trunk/source/Target/Target.cpp (original)
+++ lldb/trunk/source/Target/Target.cpp Wed May 30 20:09:06 2012
@@ -2001,7 +2001,8 @@
                                                                       stop_on_continue, 
                                                                       stop_on_error, 
                                                                       echo_commands,
-                                                                      print_results, 
+                                                                      print_results,
+                                                                      eLazyBoolNo,
                                                                       result);
 
                 // If the command started the target going again, we should bag out of





More information about the lldb-commits mailing list