[Lldb-commits] [lldb] r238896 - Fixed "format-string" based settings so they can have quotes on them without leaving the quotes in the format string:

Greg Clayton gclayton at apple.com
Tue Jun 2 19:02:48 PDT 2015


Author: gclayton
Date: Tue Jun  2 21:02:48 2015
New Revision: 238896

URL: http://llvm.org/viewvc/llvm-project?rev=238896&view=rev
Log:
Fixed "format-string" based settings so they can have quotes on them without leaving the quotes in the format string:

(lldb) settings set thread-format "abc"
(lldb) settings set thread-format 'abc'
(lldb) settings set thread-format abc

We strip the quotes before processing the format string and return an "error: mismatched quotes" if mismatched quotes are given.

<rdar://problem/21210789>


Modified:
    lldb/trunk/source/Interpreter/OptionValueFormatEntity.cpp
    lldb/trunk/test/settings/TestSettings.py

Modified: lldb/trunk/source/Interpreter/OptionValueFormatEntity.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/OptionValueFormatEntity.cpp?rev=238896&r1=238895&r2=238896&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/OptionValueFormatEntity.cpp (original)
+++ lldb/trunk/source/Interpreter/OptionValueFormatEntity.cpp Tue Jun  2 21:02:48 2015
@@ -66,7 +66,7 @@ OptionValueFormatEntity::DumpValue (cons
 
 Error
 OptionValueFormatEntity::SetValueFromString (llvm::StringRef value_str,
-                                      VarSetOperationType op)
+                                             VarSetOperationType op)
 {
     Error error;
     switch (op)
@@ -79,6 +79,25 @@ OptionValueFormatEntity::SetValueFromStr
         case eVarSetOperationReplace:
         case eVarSetOperationAssign:
             {
+                // Check if the string starts with a quote character after removing leading and trailing spaces.
+                // If it does start with a quote character, make sure it ends with the same quote character
+                // and remove the quotes before we parse the format string. If the string doesn't start with
+                // a quote, leave the string alone and parse as is.
+                llvm::StringRef trimmed_value_str = value_str.trim();
+                if (!trimmed_value_str.empty())
+                {
+                    const char first_char = trimmed_value_str[0];
+                    if (first_char == '"' || first_char == '\'')
+                    {
+                        const size_t trimmed_len = trimmed_value_str.size();
+                        if (trimmed_len == 1 || value_str[trimmed_len-1] != first_char)
+                        {
+                            error.SetErrorStringWithFormat("mismatched quotes");
+                            return error;
+                        }
+                        value_str = trimmed_value_str.substr(1,trimmed_len-2);
+                    }
+                }
                 FormatEntity::Entry entry;
                 error = FormatEntity::Parse(value_str, entry);
                 if (error.Success())

Modified: lldb/trunk/test/settings/TestSettings.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/settings/TestSettings.py?rev=238896&r1=238895&r2=238896&view=diff
==============================================================================
--- lldb/trunk/test/settings/TestSettings.py (original)
+++ lldb/trunk/test/settings/TestSettings.py Tue Jun  2 21:02:48 2015
@@ -358,6 +358,14 @@ class SettingsCommandTestCase(TestBase):
         self.expect ("settings show target.env-vars",
                      substrs = [ 'MY_FILE=this is a file name with spaces.txt' ])
         self.runCmd ("settings clear target.env-vars")
+        # Test and make sure that setting "format-string" settings obeys quotes if they are provided
+        self.runCmd ("settings set thread-format    'abc def'   ")
+        self.expect ("settings show thread-format", 'thread-format (format-string) = "abc def"')
+        self.runCmd ('settings set thread-format    "abc def"   ')
+        self.expect ("settings show thread-format", 'thread-format (format-string) = "abc def"')
+        # Make sure when no quotes are provided that we maintain any trailing spaces
+        self.runCmd ('settings set thread-format abc def   ')
+        self.expect ("settings show thread-format", 'thread-format (format-string) = "abc def   "')
 
     def test_settings_with_trailing_whitespace (self):
         





More information about the lldb-commits mailing list