[Lldb-commits] [lldb] r148719 - in /lldb/trunk: source/Commands/CommandObjectSettings.cpp source/Commands/CommandObjectSettings.h test/functionalities/completion/TestCompletion.py test/settings/TestSettings.py

Johnny Chen johnny.chen at apple.com
Mon Jan 23 11:49:28 PST 2012


Author: johnny
Date: Mon Jan 23 13:49:28 2012
New Revision: 148719

URL: http://llvm.org/viewvc/llvm-project?rev=148719&view=rev
Log:
Followup check in for http://llvm.org/viewvc/llvm-project?rev=148491&view=rev,
where we changed the CommandObjectSettingsSet object impl to require raw command string.

Do the same for CommandObjectSettingsAppend/InsertBefore/InsertAfter classes and
add test cases for basic functionalities as well as for variable name completion.

Modified:
    lldb/trunk/source/Commands/CommandObjectSettings.cpp
    lldb/trunk/source/Commands/CommandObjectSettings.h
    lldb/trunk/test/functionalities/completion/TestCompletion.py
    lldb/trunk/test/settings/TestSettings.py

Modified: lldb/trunk/source/Commands/CommandObjectSettings.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectSettings.cpp?rev=148719&r1=148718&r2=148719&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectSettings.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectSettings.cpp Mon Jan 23 13:49:28 2012
@@ -144,12 +144,12 @@
     // Split the raw command into var_name and value pair.
     std::string var_name_string = var_name;
     llvm::StringRef raw_str(raw_command);
-    llvm::StringRef value_str = raw_str.split(var_name_string).second;
-    StripLeadingSpaces(value_str);
-    std::string value_string = value_str.str();
+    llvm::StringRef var_value_str = raw_str.split(var_name).second;
+    StripLeadingSpaces(var_value_str);
+    std::string var_value_string = var_value_str.str();
 
     if (!m_options.m_reset
-        && value_string.empty())
+        && var_value_string.empty())
     {
         result.AppendError ("'settings set' command requires a valid variable value unless using '--reset' option;"
                             " No value supplied");
@@ -158,7 +158,7 @@
     else
     {
       Error err = usc_sp->SetVariable (var_name_string.c_str(), 
-                                       value_string.c_str(), 
+                                       var_value_string.c_str(), 
                                        eVarSetOperationAssign, 
                                        m_options.m_override, 
                                        m_interpreter.GetDebugger().GetInstanceName().AsCString());
@@ -835,11 +835,12 @@
 }
 
 bool
-CommandObjectSettingsInsertBefore::Execute (Args& command, CommandReturnObject &result)
+CommandObjectSettingsInsertBefore::ExecuteRawCommandString (const char *raw_command, CommandReturnObject &result)
 {
     UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ());
 
-    const int argc = command.GetArgumentCount ();
+    Args cmd_args(raw_command);
+    const int argc = cmd_args.GetArgumentCount ();
 
     if (argc < 3)
     {
@@ -848,7 +849,7 @@
         return false;
     }
 
-    const char *var_name = command.GetArgumentAtIndex (0);
+    const char *var_name = cmd_args.GetArgumentAtIndex (0);
     std::string var_name_string;
     if ((var_name == NULL) || (var_name[0] == '\0'))
     {
@@ -858,9 +859,9 @@
     }
 
     var_name_string = var_name;
-    command.Shift();
+    cmd_args.Shift();
 
-    const char *index_value = command.GetArgumentAtIndex (0);
+    const char *index_value = cmd_args.GetArgumentAtIndex (0);
     std::string index_value_string;
     if ((index_value == NULL) || (index_value[0] == '\0'))
     {
@@ -870,15 +871,15 @@
     }
 
     index_value_string = index_value;
-    command.Shift();
-
-    const char *var_value;
-    std::string value_string;
+    cmd_args.Shift();
 
-    command.GetQuotedCommandString (value_string);
-    var_value = value_string.c_str();
+    // Split the raw command into var_name, index_value, and value triple.
+    llvm::StringRef raw_str(raw_command);
+    llvm::StringRef var_value_str = raw_str.split(var_name).second.split(index_value).second;
+    StripLeadingSpaces(var_value_str);
+    std::string var_value_string = var_value_str.str();
 
-    if ((var_value == NULL) || (var_value[0] == '\0'))
+    if (var_value_string.empty())
     {
         result.AppendError ("'settings insert-before' command requires a valid variable value;"
                             " No value supplied");
@@ -887,7 +888,7 @@
     else
     {
         Error err = usc_sp->SetVariable (var_name_string.c_str(), 
-                                         var_value, 
+                                         var_value_string.c_str(), 
                                          eVarSetOperationInsertBefore,
                                          true, 
                                          m_interpreter.GetDebugger().GetInstanceName().AsCString(),
@@ -981,11 +982,12 @@
 }
 
 bool
-CommandObjectSettingsInsertAfter::Execute (Args& command, CommandReturnObject &result)
+CommandObjectSettingsInsertAfter::ExecuteRawCommandString (const char *raw_command, CommandReturnObject &result)
 {
     UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ());
 
-    const int argc = command.GetArgumentCount ();
+    Args cmd_args(raw_command);
+    const int argc = cmd_args.GetArgumentCount ();
 
     if (argc < 3)
     {
@@ -994,7 +996,7 @@
         return false;
     }
 
-    const char *var_name = command.GetArgumentAtIndex (0);
+    const char *var_name = cmd_args.GetArgumentAtIndex (0);
     std::string var_name_string;
     if ((var_name == NULL) || (var_name[0] == '\0'))
     {
@@ -1004,9 +1006,9 @@
     }
 
     var_name_string = var_name;
-    command.Shift();
+    cmd_args.Shift();
 
-    const char *index_value = command.GetArgumentAtIndex (0);
+    const char *index_value = cmd_args.GetArgumentAtIndex (0);
     std::string index_value_string;
     if ((index_value == NULL) || (index_value[0] == '\0'))
     {
@@ -1016,15 +1018,15 @@
     }
 
     index_value_string = index_value;
-    command.Shift();
-
-    const char *var_value;
-    std::string value_string;
+    cmd_args.Shift();
 
-    command.GetQuotedCommandString (value_string);
-    var_value = value_string.c_str();
+    // Split the raw command into var_name, index_value, and value triple.
+    llvm::StringRef raw_str(raw_command);
+    llvm::StringRef var_value_str = raw_str.split(var_name).second.split(index_value).second;
+    StripLeadingSpaces(var_value_str);
+    std::string var_value_string = var_value_str.str();
 
-    if ((var_value == NULL) || (var_value[0] == '\0'))
+    if (var_value_string.empty())
     {
         result.AppendError ("'settings insert-after' command requires a valid variable value;"
                             " No value supplied");
@@ -1033,7 +1035,7 @@
     else
     {
         Error err = usc_sp->SetVariable (var_name_string.c_str(), 
-                                         var_value, 
+                                         var_value_string.c_str(), 
                                          eVarSetOperationInsertAfter,
                                          true, 
                                          m_interpreter.GetDebugger().GetInstanceName().AsCString(), 
@@ -1117,11 +1119,12 @@
 }
 
 bool
-CommandObjectSettingsAppend::Execute (Args& command, CommandReturnObject &result)
+CommandObjectSettingsAppend::ExecuteRawCommandString (const char *raw_command, CommandReturnObject &result)
 {
     UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ());
 
-    const int argc = command.GetArgumentCount ();
+    Args cmd_args(raw_command);
+    const int argc = cmd_args.GetArgumentCount ();
 
     if (argc < 2)
     {
@@ -1130,7 +1133,7 @@
         return false;
     }
 
-    const char *var_name = command.GetArgumentAtIndex (0);
+    const char *var_name = cmd_args.GetArgumentAtIndex (0);
     std::string var_name_string;
     if ((var_name == NULL) || (var_name[0] == '\0'))
     {
@@ -1140,15 +1143,15 @@
     }
 
     var_name_string = var_name;
-    command.Shift();
-
-    const char *var_value;
-    std::string value_string;
+    cmd_args.Shift();
 
-    command.GetQuotedCommandString (value_string);
-    var_value = value_string.c_str();
+    // Split the raw command into var_name and value pair.
+    llvm::StringRef raw_str(raw_command);
+    llvm::StringRef var_value_str = raw_str.split(var_name).second;
+    StripLeadingSpaces(var_value_str);
+    std::string var_value_string = var_value_str.str();
 
-    if ((var_value == NULL) || (var_value[0] == '\0'))
+    if (var_value_string.empty())
     {
         result.AppendError ("'settings append' command requires a valid variable value;"
                             " No value supplied");
@@ -1157,7 +1160,7 @@
     else
     {
         Error err = usc_sp->SetVariable (var_name_string.c_str(), 
-                                         var_value, 
+                                         var_value_string.c_str(), 
                                          eVarSetOperationAppend, 
                                          true, 
                                          m_interpreter.GetDebugger().GetInstanceName().AsCString());

Modified: lldb/trunk/source/Commands/CommandObjectSettings.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectSettings.h?rev=148719&r1=148718&r2=148719&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectSettings.h (original)
+++ lldb/trunk/source/Commands/CommandObjectSettings.h Mon Jan 23 13:49:28 2012
@@ -253,7 +253,19 @@
 
     virtual bool
     Execute (Args& command,
-             CommandReturnObject &result);
+             CommandReturnObject &result)
+    { return false; }
+
+    virtual bool
+    WantsRawCommandString() { return true; }
+
+    // Overrides base class's behavior where WantsCompletion = !WantsRawCommandString.
+    virtual bool
+    WantsCompletion() { return true; }
+
+    virtual bool
+    ExecuteRawCommandString (const char *raw_command,
+                             CommandReturnObject &result);
 
     virtual int
     HandleArgumentCompletion (Args &input,
@@ -282,7 +294,19 @@
 
     virtual bool
     Execute (Args& command,
-             CommandReturnObject &result);
+             CommandReturnObject &result)
+    { return false; }
+
+    virtual bool
+    WantsRawCommandString() { return true; }
+
+    // Overrides base class's behavior where WantsCompletion = !WantsRawCommandString.
+    virtual bool
+    WantsCompletion() { return true; }
+
+    virtual bool
+    ExecuteRawCommandString (const char *raw_command,
+                             CommandReturnObject &result);
 
     virtual int
     HandleArgumentCompletion (Args &input,
@@ -311,7 +335,19 @@
 
     virtual bool
     Execute (Args& command,
-             CommandReturnObject &result);
+             CommandReturnObject &result)
+    { return false; }
+
+    virtual bool
+    WantsRawCommandString() { return true; }
+
+    // Overrides base class's behavior where WantsCompletion = !WantsRawCommandString.
+    virtual bool
+    WantsCompletion() { return true; }
+
+    virtual bool
+    ExecuteRawCommandString (const char *raw_command,
+                             CommandReturnObject &result);
 
     virtual int
     HandleArgumentCompletion (Args &input,

Modified: lldb/trunk/test/functionalities/completion/TestCompletion.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/completion/TestCompletion.py?rev=148719&r1=148718&r2=148719&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/completion/TestCompletion.py (original)
+++ lldb/trunk/test/functionalities/completion/TestCompletion.py Mon Jan 23 13:49:28 2012
@@ -18,6 +18,18 @@
         system(["/bin/sh", "-c", "rm -f child_send.txt"])
         system(["/bin/sh", "-c", "rm -f child_read.txt"])
 
+    def test_settings_append_target_er(self):
+        """Test that 'settings append target.er' completes to 'settings append target.error-path'."""
+        self.complete_from_to('settings append target.er', 'settings append target.error-path')
+
+    def test_settings_insert_after_target_en(self):
+        """Test that 'settings insert-after target.en' completes to 'settings insert-after target.env-vars'."""
+        self.complete_from_to('settings insert-after target.en', 'settings insert-after target.env-vars')
+
+    def test_settings_insert_before_target_en(self):
+        """Test that 'settings insert-before target.en' completes to 'settings insert-before target.env-vars'."""
+        self.complete_from_to('settings insert-before target.en', 'settings insert-before target.env-vars')
+
     def test_settings_replace_target_ru(self):
         """Test that 'settings replace target.ru' completes to 'settings replace target.run-args'."""
         self.complete_from_to('settings replace target.ru', 'settings replace target.run-args')

Modified: lldb/trunk/test/settings/TestSettings.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/settings/TestSettings.py?rev=148719&r1=148718&r2=148719&view=diff
==============================================================================
--- lldb/trunk/test/settings/TestSettings.py (original)
+++ lldb/trunk/test/settings/TestSettings.py Mon Jan 23 13:49:28 2012
@@ -27,6 +27,39 @@
                        "environment variables",
                        "executable's environment"])
 
+    def test_append_target_env_vars(self):
+        """Test that 'replace target.run-args' works."""
+        # Append the env-vars.
+        self.runCmd('settings append target.env-vars MY_ENV_VAR=YES')
+        # And add hooks to restore the settings during tearDown().
+        self.addTearDownHook(
+            lambda: self.runCmd("settings set -r target.env-vars"))
+
+        # Check it immediately!
+        self.expect('settings show target.env-vars',
+            substrs = ['MY_ENV_VAR=YES'])
+
+    def test_insert_before_and_after_target_run_args(self):
+        """Test that 'insert-before/after target.run-args' works."""
+        # Set the run-args first.
+        self.runCmd('settings set target.run-args a b c')
+        # And add hooks to restore the settings during tearDown().
+        self.addTearDownHook(
+            lambda: self.runCmd("settings set -r target.run-args"))
+
+        # Now insert-before the index-0 element with '__a__'.
+        self.runCmd('settings insert-before target.run-args 0 __a__')
+        # And insert-after the index-1 element with '__A__'.
+        self.runCmd('settings insert-after target.run-args 1 __A__')
+        # Check it immediately!
+        self.expect('settings show target.run-args',
+            substrs = ['target.run-args (array) = ',
+                       '[0]: "__a__"',
+                       '[1]: "a"',
+                       '[2]: "__A__"',
+                       '[3]: "b"',
+                       '[4]: "c"'])
+
     def test_replace_target_run_args(self):
         """Test that 'replace target.run-args' works."""
         # Set the run-args and then replace the index-0 element.





More information about the lldb-commits mailing list