[Lldb-commits] [lldb] r221399 - Add a setting escape-non-printables that drives whether the StringPrinter should or should not escape sequences such as \t, \n, .. and generally any non-printing character

Enrico Granata egranata at apple.com
Wed Nov 5 13:20:48 PST 2014


Author: enrico
Date: Wed Nov  5 15:20:48 2014
New Revision: 221399

URL: http://llvm.org/viewvc/llvm-project?rev=221399&view=rev
Log:
Add a setting escape-non-printables that drives whether the StringPrinter should or should not escape sequences such as \t, \n, .. and generally any non-printing character

The recent StringPrinter changes made this behavior the default, and the setting defaults to yes
If you want to change this behavior and see non-printables unescaped (e.g. "a\tb" as "a    b"), set it to false

Fixes rdar://12969594


Added:
    lldb/trunk/test/functionalities/data-formatter/stringprinter/
    lldb/trunk/test/functionalities/data-formatter/stringprinter/TestStringPrinter.py
    lldb/trunk/test/functionalities/data-formatter/stringprinter/main.cpp
Modified:
    lldb/trunk/include/lldb/Core/Debugger.h
    lldb/trunk/include/lldb/DataFormatters/StringPrinter.h
    lldb/trunk/source/Core/Debugger.cpp
    lldb/trunk/source/Core/ValueObject.cpp
    lldb/trunk/source/DataFormatters/CXXFormatterFunctions.cpp
    lldb/trunk/source/DataFormatters/StringPrinter.cpp

Modified: lldb/trunk/include/lldb/Core/Debugger.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Debugger.h?rev=221399&r1=221398&r2=221399&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Debugger.h (original)
+++ lldb/trunk/include/lldb/Core/Debugger.h Wed Nov  5 15:20:48 2014
@@ -348,6 +348,9 @@ public:
     GetAutoOneLineSummaries () const;
     
     bool
+    GetEscapeNonPrintables () const;
+    
+    bool
     GetNotifyVoid () const;
 
     

Modified: lldb/trunk/include/lldb/DataFormatters/StringPrinter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/DataFormatters/StringPrinter.h?rev=221399&r1=221398&r2=221399&view=diff
==============================================================================
--- lldb/trunk/include/lldb/DataFormatters/StringPrinter.h (original)
+++ lldb/trunk/include/lldb/DataFormatters/StringPrinter.h Wed Nov  5 15:20:48 2014
@@ -41,6 +41,8 @@ namespace lldb_private {
             {
             }
             
+            ReadStringAndDumpToStreamOptions (ValueObject& valobj);
+            
             ReadStringAndDumpToStreamOptions&
             SetLocation (uint64_t l)
             {
@@ -170,6 +172,8 @@ namespace lldb_private {
             {
             }
             
+            ReadBufferAndDumpToStreamOptions (ValueObject& valobj);
+            
             ReadBufferAndDumpToStreamOptions&
             SetData (DataExtractor d)
             {

Modified: lldb/trunk/source/Core/Debugger.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Debugger.cpp?rev=221399&r1=221398&r2=221399&view=diff
==============================================================================
--- lldb/trunk/source/Core/Debugger.cpp (original)
+++ lldb/trunk/source/Core/Debugger.cpp Wed Nov  5 15:20:48 2014
@@ -144,7 +144,8 @@ g_properties[] =
 {   "thread-format",            OptionValue::eTypeString , true, 0    , DEFAULT_THREAD_FORMAT, NULL, "The default thread format string to use when displaying thread information." },
 {   "use-external-editor",      OptionValue::eTypeBoolean, true, false, NULL, NULL, "Whether to use an external editor or not." },
 {   "use-color",                OptionValue::eTypeBoolean, true, true , NULL, NULL, "Whether to use Ansi color codes or not." },
-{   "auto-one-line-summaries",     OptionValue::eTypeBoolean, true, true, NULL, NULL, "If true, LLDB will automatically display small structs in one-liner format (default: true)." },
+{   "auto-one-line-summaries",  OptionValue::eTypeBoolean, true, true, NULL, NULL, "If true, LLDB will automatically display small structs in one-liner format (default: true)." },
+{   "escape-non-printables",    OptionValue::eTypeBoolean, true, true, NULL, NULL, "If true, LLDB will automatically escape non-printable and escape characters when formatting strings." },
 
     {   NULL,                       OptionValue::eTypeInvalid, true, 0    , NULL, NULL, NULL }
 };
@@ -165,7 +166,8 @@ enum
     ePropertyThreadFormat,
     ePropertyUseExternalEditor,
     ePropertyUseColor,
-    ePropertyAutoOneLineSummaries
+    ePropertyAutoOneLineSummaries,
+    ePropertyEscapeNonPrintables
 };
 
 Debugger::LoadPluginCallbackType Debugger::g_load_plugin_callback = NULL;
@@ -177,6 +179,7 @@ Debugger::SetPropertyValue (const Execut
                             const char *value)
 {
     bool is_load_script = strcmp(property_path,"target.load-script-from-symbol-file") == 0;
+    bool is_escape_non_printables = strcmp(property_path, "escape-non-printables") == 0;
     TargetSP target_sp;
     LoadScriptFromSymFile load_script_old_value;
     if (is_load_script && exe_ctx->GetTargetSP())
@@ -224,6 +227,10 @@ Debugger::SetPropertyValue (const Execut
                 }
             }
         }
+        else if (is_escape_non_printables)
+        {
+            DataVisualization::ForceUpdate();
+        }
     }
     return error;
 }
@@ -366,7 +373,13 @@ Debugger::GetAutoOneLineSummaries () con
 {
     const uint32_t idx = ePropertyAutoOneLineSummaries;
     return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, true);
+}
 
+bool
+Debugger::GetEscapeNonPrintables () const
+{
+    const uint32_t idx = ePropertyEscapeNonPrintables;
+    return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, true);
 }
 
 #pragma mark Debugger

Modified: lldb/trunk/source/Core/ValueObject.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObject.cpp?rev=221399&r1=221398&r2=221399&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObject.cpp (original)
+++ lldb/trunk/source/Core/ValueObject.cpp Wed Nov  5 15:20:48 2014
@@ -1591,13 +1591,12 @@ ValueObject::DumpPrintableRepresentation
                                   0,
                                   (custom_format == eFormatVectorOfChar) ||
                                   (custom_format == eFormatCharArray));
-                lldb_private::formatters::ReadBufferAndDumpToStreamOptions options;
+                lldb_private::formatters::ReadBufferAndDumpToStreamOptions options(*this);
                 options.SetData(DataExtractor(buffer_sp, lldb::eByteOrderInvalid, 8)); // none of this matters for a string - pass some defaults
                 options.SetStream(&s);
                 options.SetPrefixToken(0);
                 options.SetQuote('"');
                 options.SetSourceSize(buffer_sp->GetByteSize());
-                options.SetEscapeNonPrintables(true);
                 lldb_private::formatters::ReadBufferAndDumpToStream<lldb_private::formatters::StringElementType::ASCII>(options);
                 return !error.Fail();
             }

Modified: lldb/trunk/source/DataFormatters/CXXFormatterFunctions.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/CXXFormatterFunctions.cpp?rev=221399&r1=221398&r2=221399&view=diff
==============================================================================
--- lldb/trunk/source/DataFormatters/CXXFormatterFunctions.cpp (original)
+++ lldb/trunk/source/DataFormatters/CXXFormatterFunctions.cpp Wed Nov  5 15:20:48 2014
@@ -202,7 +202,7 @@ lldb_private::formatters::Char16StringSu
     if (!valobj_addr)
         return false;
     
-    ReadStringAndDumpToStreamOptions options;
+    ReadStringAndDumpToStreamOptions options(valobj);
     options.SetLocation(valobj_addr);
     options.SetProcessSP(process_sp);
     options.SetStream(&stream);
@@ -229,7 +229,7 @@ lldb_private::formatters::Char32StringSu
     if (!valobj_addr)
         return false;
     
-    ReadStringAndDumpToStreamOptions options;
+    ReadStringAndDumpToStreamOptions options(valobj);
     options.SetLocation(valobj_addr);
     options.SetProcessSP(process_sp);
     options.SetStream(&stream);
@@ -269,7 +269,7 @@ lldb_private::formatters::WCharStringSum
     ClangASTType wchar_clang_type = ClangASTContext::GetBasicType(ast, lldb::eBasicTypeWChar);
     const uint32_t wchar_size = wchar_clang_type.GetBitSize();
 
-    ReadStringAndDumpToStreamOptions options;
+    ReadStringAndDumpToStreamOptions options(valobj);
     options.SetLocation(data_addr);
     options.SetProcessSP(process_sp);
     options.SetStream(&stream);
@@ -305,7 +305,7 @@ lldb_private::formatters::Char16SummaryP
     if (!value.empty())
         stream.Printf("%s ", value.c_str());
 
-    ReadBufferAndDumpToStreamOptions options;
+    ReadBufferAndDumpToStreamOptions options(valobj);
     options.SetData(data);
     options.SetStream(&stream);
     options.SetPrefixToken('u');
@@ -330,7 +330,7 @@ lldb_private::formatters::Char32SummaryP
     if (!value.empty())
         stream.Printf("%s ", value.c_str());
     
-    ReadBufferAndDumpToStreamOptions options;
+    ReadBufferAndDumpToStreamOptions options(valobj);
     options.SetData(data);
     options.SetStream(&stream);
     options.SetPrefixToken('U');
@@ -350,7 +350,7 @@ lldb_private::formatters::WCharSummaryPr
     if (error.Fail())
         return false;
     
-    ReadBufferAndDumpToStreamOptions options;
+    ReadBufferAndDumpToStreamOptions options(valobj);
     options.SetData(data);
     options.SetStream(&stream);
     options.SetPrefixToken('L');
@@ -481,13 +481,12 @@ lldb_private::formatters::LibcxxStringSu
     size = std::min<decltype(size)>(size, valobj.GetTargetSP()->GetMaximumSizeOfStringSummary());
     location_sp->GetPointeeData(extractor, 0, size);
     
-    lldb_private::formatters::ReadBufferAndDumpToStreamOptions options;
+    ReadBufferAndDumpToStreamOptions options(valobj);
     options.SetData(extractor); // none of this matters for a string - pass some defaults
     options.SetStream(&stream);
     options.SetPrefixToken(0);
     options.SetQuote('"');
     options.SetSourceSize(size);
-    options.SetEscapeNonPrintables(true);
     lldb_private::formatters::ReadBufferAndDumpToStream<lldb_private::formatters::StringElementType::ASCII>(options);
     
     return true;
@@ -836,7 +835,7 @@ lldb_private::formatters::NSStringSummar
             return false;
         if (has_explicit_length && is_unicode)
         {
-            ReadStringAndDumpToStreamOptions options;
+            ReadStringAndDumpToStreamOptions options(valobj);
             options.SetLocation(location);
             options.SetProcessSP(process_sp);
             options.SetStream(&stream);
@@ -848,7 +847,7 @@ lldb_private::formatters::NSStringSummar
         }
         else
         {
-            ReadStringAndDumpToStreamOptions options;
+            ReadStringAndDumpToStreamOptions options(valobj);
             options.SetLocation(location+1);
             options.SetProcessSP(process_sp);
             options.SetStream(&stream);
@@ -883,7 +882,7 @@ lldb_private::formatters::NSStringSummar
             if (error.Fail())
                 return false;
         }
-        ReadStringAndDumpToStreamOptions options;
+        ReadStringAndDumpToStreamOptions options(valobj);
         options.SetLocation(location);
         options.SetProcessSP(process_sp);
         options.SetStream(&stream);
@@ -899,7 +898,7 @@ lldb_private::formatters::NSStringSummar
         explicit_length = reader.GetField<uint32_t>(ConstString("lengthAndRef")) >> 20;
         lldb::addr_t location = valobj.GetValueAsUnsigned(0) + ptr_size + 4;
         
-        ReadStringAndDumpToStreamOptions options;
+        ReadStringAndDumpToStreamOptions options(valobj);
         options.SetLocation(location);
         options.SetProcessSP(process_sp);
         options.SetStream(&stream);
@@ -914,7 +913,7 @@ lldb_private::formatters::NSStringSummar
         uint64_t location = valobj_addr + 2*ptr_size;
         if (!has_explicit_length)
             location++;
-        ReadStringAndDumpToStreamOptions options;
+        ReadStringAndDumpToStreamOptions options(valobj);
         options.SetLocation(location);
         options.SetProcessSP(process_sp);
         options.SetStream(&stream);
@@ -930,7 +929,7 @@ lldb_private::formatters::NSStringSummar
             return false;
         if (has_explicit_length && !has_null)
             explicit_length++; // account for the fact that there is no NULL and we need to have one added
-        ReadStringAndDumpToStreamOptions options;
+        ReadStringAndDumpToStreamOptions options(valobj);
         options.SetLocation(location);
         options.SetProcessSP(process_sp);
         options.SetPrefixToken('@');

Modified: lldb/trunk/source/DataFormatters/StringPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/StringPrinter.cpp?rev=221399&r1=221398&r2=221399&view=diff
==============================================================================
--- lldb/trunk/source/DataFormatters/StringPrinter.cpp (original)
+++ lldb/trunk/source/DataFormatters/StringPrinter.cpp Wed Nov  5 15:20:48 2014
@@ -10,7 +10,9 @@
 #include "lldb/DataFormatters/StringPrinter.h"
 
 #include "lldb/Core/DataExtractor.h"
+#include "lldb/Core/Debugger.h"
 #include "lldb/Core/Error.h"
+#include "lldb/Core/ValueObject.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Target/Target.h"
 
@@ -416,6 +418,19 @@ DumpUTFBufferToStream (ConversionResult
     return true;
 }
 
+lldb_private::formatters::ReadStringAndDumpToStreamOptions::ReadStringAndDumpToStreamOptions (ValueObject& valobj) :
+    ReadStringAndDumpToStreamOptions()
+{
+    SetEscapeNonPrintables(valobj.GetTargetSP()->GetDebugger().GetEscapeNonPrintables());
+}
+
+lldb_private::formatters::ReadBufferAndDumpToStreamOptions::ReadBufferAndDumpToStreamOptions (ValueObject& valobj) :
+    ReadBufferAndDumpToStreamOptions()
+{
+    SetEscapeNonPrintables(valobj.GetTargetSP()->GetDebugger().GetEscapeNonPrintables());
+}
+
+
 namespace lldb_private
 {
 

Added: lldb/trunk/test/functionalities/data-formatter/stringprinter/TestStringPrinter.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/stringprinter/TestStringPrinter.py?rev=221399&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/data-formatter/stringprinter/TestStringPrinter.py (added)
+++ lldb/trunk/test/functionalities/data-formatter/stringprinter/TestStringPrinter.py Wed Nov  5 15:20:48 2014
@@ -0,0 +1,3 @@
+import lldbinline
+
+lldbinline.MakeInlineTest(__file__, globals())

Added: lldb/trunk/test/functionalities/data-formatter/stringprinter/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/stringprinter/main.cpp?rev=221399&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/data-formatter/stringprinter/main.cpp (added)
+++ lldb/trunk/test/functionalities/data-formatter/stringprinter/main.cpp Wed Nov  5 15:20:48 2014
@@ -0,0 +1,23 @@
+//===-- main.cpp ------------------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include <string>
+
+int main (int argc, char const *argv[])
+{
+    std::string stdstring("Hello\t\tWorld\nI am here\t\tto say hello\n");
+    const char* constcharstar = stdstring.c_str();
+    return 0; //% self.assertTrue(self.frame().FindVariable('stdstring').GetSummary() == '"Hello\\t\\tWorld\\nI am here\\t\\tto say hello\\n"')
+     //% self.assertTrue(self.frame().FindVariable('constcharstar').GetSummary() == '"Hello\\t\\tWorld\\nI am here\\t\\tto say hello\\n"')
+     //% self.runCmd("setting set escape-non-printables false")
+     //% print self.frame().FindVariable('stdstring').GetSummary()
+     //% self.assertTrue(self.frame().FindVariable('stdstring').GetSummary() == '"Hello\t\tWorld\nI am here\t\tto say hello\n"')
+     //% self.assertTrue(self.frame().FindVariable('constcharstar').GetSummary() == '"Hello\t\tWorld\nI am here\t\tto say hello\n"')
+     //% self.runCmd("setting set escape-non-printables true")
+}





More information about the lldb-commits mailing list