[Lldb-commits] [lldb] r121438 - in /lldb/trunk: include/lldb/Interpreter/Args.h source/Commands/CommandObjectSettings.cpp source/Core/UserSettingsController.cpp source/Interpreter/Args.cpp

Caroline Tice ctice at apple.com
Thu Dec 9 16:26:54 PST 2010


Author: ctice
Date: Thu Dec  9 18:26:54 2010
New Revision: 121438

URL: http://llvm.org/viewvc/llvm-project?rev=121438&view=rev
Log:

Various fixes mostly relating to the User Settings stuff:

- Added new utility function to Arg, GetQuotedCommandString, which re-assembles
the args into a string, replacing quotes that were originally there.

- Modified user settings stuff to always show individual elements when printing out
arrays and dictionaries.

- Added more extensive help to 'settings set', explaining more about dictionaries
and arrays (including current dictionary syntax).

- Fixed bug in user settings  where quotes were being stripped and lost, so that
sometimes array or dictionary elements that ought to have been a single element
were being split up.


Modified:
    lldb/trunk/include/lldb/Interpreter/Args.h
    lldb/trunk/source/Commands/CommandObjectSettings.cpp
    lldb/trunk/source/Core/UserSettingsController.cpp
    lldb/trunk/source/Interpreter/Args.cpp

Modified: lldb/trunk/include/lldb/Interpreter/Args.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/Args.h?rev=121438&r1=121437&r2=121438&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/Args.h (original)
+++ lldb/trunk/include/lldb/Interpreter/Args.h Thu Dec  9 18:26:54 2010
@@ -122,6 +122,9 @@
     bool
     GetCommandString (std::string &command);
 
+    bool
+    GetQuotedCommandString (std::string &command);
+
     //------------------------------------------------------------------
     /// Gets the number of arguments left in this command object.
     ///

Modified: lldb/trunk/source/Commands/CommandObjectSettings.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectSettings.cpp?rev=121438&r1=121437&r2=121438&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectSettings.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectSettings.cpp Thu Dec  9 18:26:54 2010
@@ -90,6 +90,29 @@
     // Push the data for the first argument into the m_arguments vector.
     m_arguments.push_back (arg1);
     m_arguments.push_back (arg2);
+    
+    SetHelpLong (
+"When setting a dictionary or array variable, you can set multiple entries \n\
+at once by giving the values to the set command.  For example: \n\
+\n\
+(lldb) settings set target.process.run-args value1  value2 value3 \n\
+(lldb) settings set target.process.env-vars [\"MYPATH\"]=~/.:/usr/bin  [\"SOME_ENV_VAR\"]=12345 \n\
+\n\
+(lldb) settings show target.process.run-args \n\
+  [0]: 'value1' \n\
+  [1]: 'value2' \n\
+  [3]: 'value3' \n\
+(lldb) settings show target.process.env-vars \n\
+  'MYPATH=~/.:/usr/bin'\n\
+  'SOME_ENV_VAR=12345' \n\
+\n\
+Note the special syntax for setting a dictionary element: [\"<key>\"]=<value> \n\
+\n\
+Warning:  The 'set' command re-sets the entire array or dictionary.  If you \n\
+just want to add, remove or update individual values (or add something to \n\
+the end), use one of the other settings sub-commands: append, replace, \n\
+insert-before or insert-after.\n");
+
 }
 
 CommandObjectSettingsSet::~CommandObjectSettingsSet()
@@ -126,7 +149,7 @@
     const char *var_value;
     std::string value_string;
 
-    command.GetCommandString (value_string);
+    command.GetQuotedCommandString (value_string);
     var_value = value_string.c_str();
 
     if (!m_options.m_reset
@@ -342,14 +365,17 @@
 
             if (value.GetSize() == 0)
                 result.AppendMessageWithFormat ("%s%s = ''\n", variable_name, type_name);
-            else if (value.GetSize() == 1)
+            else if ((var_type != lldb::eSetVarTypeArray) && (var_type != lldb::eSetVarTypeDictionary))
                 result.AppendMessageWithFormat ("%s%s = '%s'\n", variable_name, type_name, value.GetStringAtIndex (0));
             else
             {
                 result.AppendMessageWithFormat ("%s%s:\n", variable_name, type_name);
                 for (unsigned i = 0, e = value.GetSize(); i != e; ++i)
                 {
-                    result.AppendMessageWithFormat ("  [%d]: '%s'\n", i, value.GetStringAtIndex (i));
+                    if (var_type == lldb::eSetVarTypeArray)
+                        result.AppendMessageWithFormat ("  [%d]: '%s'\n", i, value.GetStringAtIndex (i));
+                    else if (var_type == lldb::eSetVarTypeDictionary)
+                        result.AppendMessageWithFormat ("  '%s'\n", value.GetStringAtIndex (i));
                 }
             }
             result.SetStatus (eReturnStatusSuccessFinishNoResult);
@@ -727,7 +753,7 @@
     const char *var_value;
     std::string value_string;
 
-    command.GetCommandString (value_string);
+    command.GetQuotedCommandString (value_string);
     var_value = value_string.c_str();
 
     if ((var_value == NULL) || (var_value[0] == '\0'))
@@ -872,7 +898,7 @@
     const char *var_value;
     std::string value_string;
 
-    command.GetCommandString (value_string);
+    command.GetQuotedCommandString (value_string);
     var_value = value_string.c_str();
 
     if ((var_value == NULL) || (var_value[0] == '\0'))
@@ -1019,7 +1045,7 @@
     const char *var_value;
     std::string value_string;
 
-    command.GetCommandString (value_string);
+    command.GetQuotedCommandString (value_string);
     var_value = value_string.c_str();
 
     if ((var_value == NULL) || (var_value[0] == '\0'))
@@ -1144,7 +1170,7 @@
     const char *var_value;
     std::string value_string;
 
-    command.GetCommandString (value_string);
+    command.GetQuotedCommandString (value_string);
     var_value = value_string.c_str();
 
     if ((var_value == NULL) || (var_value[0] == '\0'))

Modified: lldb/trunk/source/Core/UserSettingsController.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/UserSettingsController.cpp?rev=121438&r1=121437&r2=121438&view=diff
==============================================================================
--- lldb/trunk/source/Core/UserSettingsController.cpp (original)
+++ lldb/trunk/source/Core/UserSettingsController.cpp Thu Dec  9 18:26:54 2010
@@ -780,18 +780,31 @@
         m_default_settings->GetInstanceSettingsValue (entry, var_name, tmp_value, NULL);
 
         StreamString value_string;
+        bool multi_value = false;
 
         if (tmp_value.GetSize() == 1)
             value_string.Printf ("%s", tmp_value.GetStringAtIndex (0));
         else
         {
             for (int j = 0; j < tmp_value.GetSize(); ++j)
-                value_string.Printf ("%s ", tmp_value.GetStringAtIndex (j));
+            {
+                if (entry.var_type == lldb::eSetVarTypeArray)
+                    value_string.Printf ("\n  [%d]: '%s'", j, tmp_value.GetStringAtIndex (j));
+                else if (entry.var_type == lldb::eSetVarTypeDictionary)
+                    value_string.Printf ("\n  '%s'", tmp_value.GetStringAtIndex (j));
+            }
+            multi_value = true;
         }
 
         if (! parent_prefix.empty())
-            result_stream.Printf ("%s.%s (%s) = '%s'\n", prefix, var_name.AsCString(),
-                                  UserSettingsController::GetTypeString (entry.var_type), value_string.GetData());
+        {
+            if (multi_value)
+                result_stream.Printf ("%s.%s (%s):%s\n", prefix, var_name.AsCString(),
+                                      UserSettingsController::GetTypeString (entry.var_type), value_string.GetData());
+            else
+                result_stream.Printf ("%s.%s (%s) = '%s'\n", prefix, var_name.AsCString(),
+                                      UserSettingsController::GetTypeString (entry.var_type), value_string.GetData());
+        }
     }
 }
 
@@ -1366,10 +1379,12 @@
                                 value.GetStringAtIndex (0));
         else
         {
-            description.Printf ("%s (%s) = '", full_var_name.GetData(), GetTypeString (entry.var_type));
+            description.Printf ("%s (%s):\n", full_var_name.GetData(), GetTypeString (entry.var_type));
             for (int j = 0; j < value.GetSize(); ++j)
-                description.Printf ("%s ", value.GetStringAtIndex (j));
-            description.Printf ("'");
+                if (entry.var_type == lldb::eSetVarTypeArray)
+                    description.Printf ("  [%d]: '%s'\n", j, value.GetStringAtIndex (j));
+                else if (entry.var_type == lldb::eSetVarTypeDictionary)
+                    description.Printf ("  '%s'\n", value.GetStringAtIndex (j));
         }
 
         result_stream.Printf ("%s\n", description.GetData());

Modified: lldb/trunk/source/Interpreter/Args.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/Args.cpp?rev=121438&r1=121437&r2=121438&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/Args.cpp (original)
+++ lldb/trunk/source/Interpreter/Args.cpp Thu Dec  9 18:26:54 2010
@@ -93,6 +93,28 @@
     return argc > 0;
 }
 
+bool
+Args::GetQuotedCommandString (std::string &command)
+{
+    command.clear ();
+    int argc = GetArgumentCount ();
+    for (int i = 0; i < argc; ++i)
+    {
+        if (i > 0)
+            command += ' ';
+        char quote_char = m_args_quote_char[i];
+        if (quote_char != '\0')
+        {
+            command += quote_char;
+            command += m_argv[i];
+            command += quote_char;
+        }
+        else
+            command += m_argv[i];
+    }
+    return argc > 0;
+}
+
 void
 Args::SetCommandString (const char *command, size_t len)
 {





More information about the lldb-commits mailing list