Author: vedantk
Date: Thu Feb 22 15:48:21 2018
New Revision: 325841

URL: http://llvm.org/viewvc/llvm-project?rev=325841&view=rev
Log:
[ObjC] Fix the NSConcreteData formatter and test it

The length field of an NSConcreteData lives one word past the start of
the object, not two.

Modified:
    
lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjC.py
    
lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/main.m
    lldb/trunk/source/Plugins/Language/ObjC/Cocoa.cpp

Modified: 
lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjC.py
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjC.py?rev=325841&r1=325840&r2=325841&view=diff
==============================================================================
--- 
lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjC.py
 (original)
+++ 
lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjC.py
 Thu Feb 22 15:48:21 2018
@@ -243,7 +243,7 @@ class ObjCDataFormatterTestCase(TestBase
 
     def nsdata_data_formatter_commands(self):
         self.expect(
-            'frame variable immutableData mutableData data_ref 
mutable_data_ref mutable_string_ref',
+            'frame variable immutableData mutableData data_ref 
mutable_data_ref mutable_string_ref concreteData concreteMutableData',
             substrs=[
                 '(NSData *) immutableData = ',
                 ' 4 bytes',
@@ -254,7 +254,12 @@ class ObjCDataFormatterTestCase(TestBase
                 '(CFMutableDataRef) mutable_data_ref = ',
                 '@"5 bytes"',
                 '(CFMutableStringRef) mutable_string_ref = ',
-                ' @"Wish ya knew"'])
+                ' @"Wish ya knew"',
+                '(NSData *) concreteData = ',
+                ' 100000 bytes',
+                '(NSMutableData *) concreteMutableData = ',
+                ' 100000 bytes'])
+
 
     def nsurl_data_formatter_commands(self):
         self.expect(

Modified: 
lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/main.m
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/main.m?rev=325841&r1=325840&r2=325841&view=diff
==============================================================================
--- 
lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/main.m
 (original)
+++ 
lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/main.m
 Thu Feb 22 15:48:21 2018
@@ -396,6 +396,12 @@ int main (int argc, const char * argv[])
            NSData *immutableData = [[NSData alloc] initWithBytes:"HELLO" 
length:4];
            NSData *mutableData = [[NSMutableData alloc] initWithBytes:"NODATA" 
length:6];
 
+           // No-copy versions of NSData initializers use NSConcreteData if 
over 2^16 elements are specified.
+           unsigned concreteLength = 100000;
+           void *zeroes = calloc(1, concreteLength);
+           NSData *concreteData = [[NSData alloc] initWithBytesNoCopy:zeroes 
length:concreteLength];
+           NSMutableData *concreteMutableData = [[NSMutableData alloc] 
initWithBytesNoCopy:zeroes length:concreteLength];
+
            [mutableData appendBytes:"MOREDATA" length:8];
 
            [immutableData length];
@@ -610,6 +616,7 @@ int main (int argc, const char * argv[])
     [molecule setAtoms:nil];
     [molecule setAtoms:[NSMutableArray new]];
 
+    free(zeroes);
     [pool drain];
     return 0;
 }

Modified: lldb/trunk/source/Plugins/Language/ObjC/Cocoa.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Language/ObjC/Cocoa.cpp?rev=325841&r1=325840&r2=325841&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Language/ObjC/Cocoa.cpp (original)
+++ lldb/trunk/source/Plugins/Language/ObjC/Cocoa.cpp Thu Feb 22 15:48:21 2018
@@ -871,28 +871,34 @@ bool lldb_private::formatters::NSDataSum
 
   uint64_t value = 0;
 
-  const char *class_name = descriptor->GetClassName().GetCString();
+  llvm::StringRef class_name = descriptor->GetClassName().GetCString();
 
-  if (!class_name || !*class_name)
+  if (class_name.empty())
     return false;
 
-  if (!strcmp(class_name, "NSConcreteData") ||
-      !strcmp(class_name, "NSConcreteMutableData") ||
-      !strcmp(class_name, "__NSCFData")) {
-    uint32_t offset = (is_64bit ? 16 : 8);
+  bool isNSConcreteData = class_name == "NSConcreteData";
+  bool isNSConcreteMutableData = class_name == "NSConcreteMutableData";
+  bool isNSCFData = class_name == "__NSCFData";
+  if (isNSConcreteData || isNSConcreteMutableData || isNSCFData) {
+    uint32_t offset;
+    if (isNSConcreteData)
+      offset = is_64bit ? 8 : 4;
+    else
+      offset = is_64bit ? 16 : 8;
+
     Status error;
     value = process_sp->ReadUnsignedIntegerFromMemory(
         valobj_addr + offset, is_64bit ? 8 : 4, 0, error);
     if (error.Fail())
       return false;
-  } else if (!strcmp(class_name, "_NSInlineData")) {
+  } else if (class_name == "_NSInlineData") {
     uint32_t offset = (is_64bit ? 8 : 4);
     Status error;
     value = process_sp->ReadUnsignedIntegerFromMemory(valobj_addr + offset, 2,
                                                       0, error);
     if (error.Fail())
       return false;
-  } else if (!strcmp(class_name, "_NSZeroData")) {
+  } else if (class_name == "_NSZeroData") {
     value = 0;
   } else
     return false;


_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to