[Lldb-commits] [lldb] r242555 - Improve the NSString data formatter so that explicitly-lengthed Unicode strings print embedded NULs correctly

Enrico Granata egranata at apple.com
Fri Jul 17 11:22:51 PDT 2015


Author: enrico
Date: Fri Jul 17 13:22:51 2015
New Revision: 242555

URL: http://llvm.org/viewvc/llvm-project?rev=242555&view=rev
Log:
Improve the NSString data formatter so that explicitly-lengthed Unicode strings print embedded NULs correctly


Modified:
    lldb/trunk/source/DataFormatters/CXXFormatterFunctions.cpp
    lldb/trunk/test/functionalities/data-formatter/data-formatter-objc/nsstring/TestDataFormatterNSString.py
    lldb/trunk/test/functionalities/data-formatter/data-formatter-objc/nsstring/main.m

Modified: lldb/trunk/source/DataFormatters/CXXFormatterFunctions.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/CXXFormatterFunctions.cpp?rev=242555&r1=242554&r2=242555&view=diff
==============================================================================
--- lldb/trunk/source/DataFormatters/CXXFormatterFunctions.cpp (original)
+++ lldb/trunk/source/DataFormatters/CXXFormatterFunctions.cpp Fri Jul 17 13:22:51 2015
@@ -879,11 +879,11 @@ lldb_private::formatters::NSStringSummar
     bool is_inline = (info_bits & 0x60) == 0;
     bool has_explicit_length = (info_bits & (1 | 4)) != 4;
     bool is_unicode = (info_bits & 0x10) == 0x10;
-    bool is_special = strcmp(class_name,"NSPathStore2") == 0;
+    bool is_path_store = strcmp(class_name,"NSPathStore2") == 0;
     bool has_null = (info_bits & 8) == 8;
     
     size_t explicit_length = 0;
-    if (!has_null && has_explicit_length && !is_special)
+    if (!has_null && has_explicit_length && !is_path_store)
     {
         lldb::addr_t explicit_length_offset = 2*ptr_size;
         if (is_mutable && !is_inline)
@@ -933,6 +933,7 @@ lldb_private::formatters::NSStringSummar
             options.SetSourceSize(explicit_length);
             options.SetNeedsZeroTermination(false);
             options.SetIgnoreMaxLength(summary_options.GetCapping() == TypeSummaryCapping::eTypeSummaryUncapped);
+            options.SetBinaryZeroIsTerminator(false);
             return ReadStringAndDumpToStream<StringElementType::UTF16>(options);
         }
         else
@@ -945,10 +946,11 @@ lldb_private::formatters::NSStringSummar
             options.SetSourceSize(explicit_length);
             options.SetNeedsZeroTermination(false);
             options.SetIgnoreMaxLength(summary_options.GetCapping() == TypeSummaryCapping::eTypeSummaryUncapped);
+            options.SetBinaryZeroIsTerminator(false);
             return ReadStringAndDumpToStream<StringElementType::ASCII>(options);
         }
     }
-    else if (is_inline && has_explicit_length && !is_unicode && !is_special && !is_mutable)
+    else if (is_inline && has_explicit_length && !is_unicode && !is_path_store && !is_mutable)
     {
         uint64_t location = 3 * ptr_size + valobj_addr;
         return ReadAsciiBufferAndDumpToStream(location,process_sp,stream,explicit_length);
@@ -981,9 +983,10 @@ lldb_private::formatters::NSStringSummar
         options.SetSourceSize(explicit_length);
         options.SetNeedsZeroTermination(has_explicit_length == false);
         options.SetIgnoreMaxLength(summary_options.GetCapping() == TypeSummaryCapping::eTypeSummaryUncapped);
+        options.SetBinaryZeroIsTerminator(has_explicit_length == false);
         return ReadStringAndDumpToStream<StringElementType::UTF16> (options);
     }
-    else if (is_special)
+    else if (is_path_store)
     {
         ProcessStructReader reader(valobj.GetProcessSP().get(), valobj.GetValueAsUnsigned(0), GetNSPathStore2Type(*valobj.GetTargetSP()));
         explicit_length = reader.GetField<uint32_t>(ConstString("lengthAndRef")) >> 20;
@@ -998,6 +1001,7 @@ lldb_private::formatters::NSStringSummar
         options.SetSourceSize(explicit_length);
         options.SetNeedsZeroTermination(has_explicit_length == false);
         options.SetIgnoreMaxLength(summary_options.GetCapping() == TypeSummaryCapping::eTypeSummaryUncapped);
+        options.SetBinaryZeroIsTerminator(has_explicit_length == false);
         return ReadStringAndDumpToStream<StringElementType::UTF16> (options);
     }
     else if (is_inline)

Modified: lldb/trunk/test/functionalities/data-formatter/data-formatter-objc/nsstring/TestDataFormatterNSString.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/data-formatter-objc/nsstring/TestDataFormatterNSString.py?rev=242555&r1=242554&r2=242555&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/data-formatter/data-formatter-objc/nsstring/TestDataFormatterNSString.py (original)
+++ lldb/trunk/test/functionalities/data-formatter/data-formatter-objc/nsstring/TestDataFormatterNSString.py Fri Jul 17 13:22:51 2015
@@ -102,6 +102,10 @@ class NSStringDataFormatterTestCase(Test
         self.expect('expr -d run-target -- path',substrs = ['usr/blah/stuff'])
         self.expect('frame variable path',substrs = ['usr/blah/stuff'])
 
+        self.expect('po strwithNULs', substrs=['a very much boring task to write'])
+        self.expect('expr [strwithNULs length]', substrs=['54'])
+        self.expect('frame variable strwithNULs', substrs=['@"a very much boring task to write\\0a string this way!!'])
+
 if __name__ == '__main__':
     import atexit
     lldb.SBDebugger.Initialize()

Modified: lldb/trunk/test/functionalities/data-formatter/data-formatter-objc/nsstring/main.m
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/data-formatter-objc/nsstring/main.m?rev=242555&r1=242554&r2=242555&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/data-formatter/data-formatter-objc/nsstring/main.m (original)
+++ lldb/trunk/test/functionalities/data-formatter/data-formatter-objc/nsstring/main.m Fri Jul 17 13:22:51 2015
@@ -79,6 +79,13 @@ int main (int argc, const char * argv[])
 	NSArray *components = @[@"usr", @"blah", @"stuff"];
 	NSString *path = [NSString pathWithComponents: components];
 
+  const unichar someOfTheseAreNUL[] = {'a',' ', 'v','e','r','y',' ',
+      'm','u','c','h',' ','b','o','r','i','n','g',' ','t','a','s','k',
+      ' ','t','o',' ','w','r','i','t','e', 0, 'a', ' ', 's', 't', 'r', 'i', 'n', 'g', ' ',
+      't','h','i','s',' ','w','a','y','!','!', 0x03C3, 0};
+  NSString *strwithNULs = [NSString stringWithCharacters: someOfTheseAreNUL
+                                           length: sizeof someOfTheseAreNUL / sizeof *someOfTheseAreNUL];
+
     [pool drain]; // break here
     return 0;
 }





More information about the lldb-commits mailing list