Fixing a bug where the summary for certain NSStrings was being returned as empty...
authorEnrico Granata <egranata@apple.com>
Tue, 15 May 2012 01:22:45 +0000 (01:22 +0000)
committerEnrico Granata <egranata@apple.com>
Tue, 15 May 2012 01:22:45 +0000 (01:22 +0000)
llvm-svn: 156793

lldb/examples/summaries/cocoa/CFString.py
lldb/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjC.py
lldb/test/functionalities/data-formatter/data-formatter-objc/main.m

index 2ad4c67..d8b1275 100644 (file)
@@ -65,14 +65,14 @@ class CFStringSynthProvider:
                        return 0;
                return 6;
 
-       def read_unicode(self, pointer):
+       def read_unicode(self, pointer,max_len=2048):
                logger = lldb.formatters.Logger.Logger()
                process = self.valobj.GetTarget().GetProcess()
                error = lldb.SBError()
                pystr = u''
                # cannot do the read at once because the length value has
                # a weird encoding. better play it safe here
-               while True:
+               while max_len > 0:
                        content = process.ReadMemory(pointer, 2, error)
                        new_bytes = bytearray(content)
                        b0 = new_bytes[0]
@@ -89,6 +89,8 @@ class CFStringSynthProvider:
                        else:
                                value = b0 * 256 + b1
                        pystr = pystr + unichr(value)
+                       # read max_len unicode values, not max_len bytes
+                       max_len = max_len - 1
                return pystr
 
        # handle the special case strings
@@ -150,8 +152,11 @@ class CFStringSynthProvider:
                data = self.valobj.CreateChildAtOffset("content",
                        offset, self.valobj.GetType().GetBasicType(lldb.eBasicTypeChar).GetPointerType());
                data_value = data.GetValueAsUnsigned(0)
-               data_value = data_value + 1
-               return self.valobj.CreateValueFromExpression("content", "(char*)(" + str(data_value) + ")")
+               if self.explicit and self.unicode:
+                       return self.read_unicode(data_value).encode('utf-8')
+               else:
+                       data_value = data_value + 1
+                       return self.valobj.CreateValueFromExpression("content", "(char*)(" + str(data_value) + ")")
 
        def handle_UTF8_inline(self):
                logger = lldb.formatters.Logger.Logger()
index 1cccef3..2d28a35 100644 (file)
@@ -136,6 +136,8 @@ class ObjCDataFormatterTestCase(TestBase):
         self.expect('frame variable french', substrs = ['Que veut cette horde d\'esclaves, De traîtres, de rois conjurés?'])
         self.expect('frame variable german', substrs = ['Über-Ich und aus den Ansprüchen der sozialen Umwelt'])
         self.expect('frame variable japanese', substrs = ['色は匂へど散りぬるを'])
+        self.expect('frame variable hebrew', substrs = ['לילה טוב'])
+
 
     def plain_data_formatter_commands(self):
         """Test basic ObjC formatting behavior."""
index 5271c4d..598ad4f 100644 (file)
@@ -285,6 +285,8 @@ int main (int argc, const char * argv[])
            NSString* german = @"Über-Ich und aus den Ansprüchen der sozialen Umwelt";
 
            void* data_set[3] = {str1,str2,str3};
+       
+               NSString *hebrew = [NSString stringWithString:@"לילה טוב"];
 
            NSArray* newArray = [[NSMutableArray alloc] init];
            [newArray addObject:str1];