[Lldb-commits] [lldb] r152592 - in /lldb/trunk: examples/summaries/cocoa/ source/Core/ test/functionalities/data-formatter/data-formatter-objc/ test/functionalities/data-formatter/rdar-3534688/

Enrico Granata egranata at apple.com
Mon Mar 12 17:26:00 PDT 2012


Author: enrico
Date: Mon Mar 12 19:25:59 2012
New Revision: 152592

URL: http://llvm.org/viewvc/llvm-project?rev=152592&view=rev
Log:
Changed several of the Cocoa formatters to match the output style that Xcode uses internally to provide summaries
This has been done for those summaries where the difference is only cosmetic (e.g. naming things as items instead of values, ...)
The LLDB output style has been preserved when it provides more information (e.g. telling the type as well as the value of an NSNumber)

Test cases have been updated to reflect the updated output style where necessary

Modified:
    lldb/trunk/examples/summaries/cocoa/CFArray.py
    lldb/trunk/examples/summaries/cocoa/CFBag.py
    lldb/trunk/examples/summaries/cocoa/CFBinaryHeap.py
    lldb/trunk/examples/summaries/cocoa/CFDictionary.py
    lldb/trunk/examples/summaries/cocoa/NSData.py
    lldb/trunk/examples/summaries/cocoa/NSDate.py
    lldb/trunk/examples/summaries/cocoa/NSException.py
    lldb/trunk/examples/summaries/cocoa/NSSet.py
    lldb/trunk/examples/summaries/cocoa/NSURL.py
    lldb/trunk/source/Core/FormatManager.cpp
    lldb/trunk/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjC.py
    lldb/trunk/test/functionalities/data-formatter/rdar-3534688/TestFormattersOneIsSingular.py

Modified: lldb/trunk/examples/summaries/cocoa/CFArray.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/summaries/cocoa/CFArray.py?rev=152592&r1=152591&r2=152592&view=diff
==============================================================================
--- lldb/trunk/examples/summaries/cocoa/CFArray.py (original)
+++ lldb/trunk/examples/summaries/cocoa/CFArray.py Mon Mar 12 19:25:59 2012
@@ -166,7 +166,8 @@
 	    if summary == None:
 	        summary = 'no valid array here'
 	    else:
-	        summary = str(summary) + (" objects" if summary > 1 else " object")
+	        # we format it like it were a CFString to make it look the same as the summary from Xcode
+	        summary = '@"' + str(summary) + (" objects" if summary > 1 else " object") + '"'
 	    return summary
 	return ''
 

Modified: lldb/trunk/examples/summaries/cocoa/CFBag.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/summaries/cocoa/CFBag.py?rev=152592&r1=152591&r2=152592&view=diff
==============================================================================
--- lldb/trunk/examples/summaries/cocoa/CFBag.py (original)
+++ lldb/trunk/examples/summaries/cocoa/CFBag.py Mon Mar 12 19:25:59 2012
@@ -120,9 +120,9 @@
 			if provider.sys_params.is_64_bit:
 				summary = summary & ~0x1fff000000000000
 			if summary == 1:
-				summary = '1 item'
+				summary = '@"1 value"'
 			else:
-				summary = str(summary) + ' items'
+				summary = '@"' + str(summary) + ' values"'
 		return summary
 	return ''
 

Modified: lldb/trunk/examples/summaries/cocoa/CFBinaryHeap.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/summaries/cocoa/CFBinaryHeap.py?rev=152592&r1=152591&r2=152592&view=diff
==============================================================================
--- lldb/trunk/examples/summaries/cocoa/CFBinaryHeap.py (original)
+++ lldb/trunk/examples/summaries/cocoa/CFBinaryHeap.py Mon Mar 12 19:25:59 2012
@@ -114,9 +114,9 @@
 			if provider.sys_params.is_64_bit:
 				summary = summary & ~0x1fff000000000000
 			if summary == 1:
-				return '1 item'
+				return '@"1 item"'
 			else:
-				summary = str(summary) + ' items'
+				summary = '@"' + str(summary) + ' items"'
 		return summary
 	return ''
 

Modified: lldb/trunk/examples/summaries/cocoa/CFDictionary.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/summaries/cocoa/CFDictionary.py?rev=152592&r1=152591&r2=152592&view=diff
==============================================================================
--- lldb/trunk/examples/summaries/cocoa/CFDictionary.py (original)
+++ lldb/trunk/examples/summaries/cocoa/CFDictionary.py Mon Mar 12 19:25:59 2012
@@ -197,7 +197,7 @@
 		# needed on OSX Mountain Lion
 			if provider.sys_params.is_64_bit:
 				summary = summary & ~0x0f1f000000000000
-			summary = str(summary) + (" key/value pairs" if summary > 1 else " key/value pair")
+			summary = '@"' + str(summary) + (' entries"' if summary > 1 else ' entry"')
 		return summary
 	return ''
 

Modified: lldb/trunk/examples/summaries/cocoa/NSData.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/summaries/cocoa/NSData.py?rev=152592&r1=152591&r2=152592&view=diff
==============================================================================
--- lldb/trunk/examples/summaries/cocoa/NSData.py (original)
+++ lldb/trunk/examples/summaries/cocoa/NSData.py Mon Mar 12 19:25:59 2012
@@ -111,5 +111,23 @@
 	    return summary
 	return ''
 
+def NSData_SummaryProvider2 (valobj,dict):
+	provider = GetSummary_Impl(valobj);
+	if provider != None:
+	    try:
+	        summary = provider.length();
+	    except:
+	        summary = None
+	    if summary == None:
+	        summary = 'no valid data here'
+	    else:
+	        if summary == 1:
+	           summary = '@"1 byte"'
+	        else:
+	           summary = '@"' + str(summary) + ' bytes"'
+	    return summary
+	return ''
+
 def __lldb_init_module(debugger,dict):
-	debugger.HandleCommand("type summary add -F NSData.NSData_SummaryProvider NSData CFDataRef CFMutableDataRef")
+	debugger.HandleCommand("type summary add -F NSData.NSData_SummaryProvider NSData")
+	debugger.HandleCommand("type summary add -F NSData.NSData_SummaryProvider2 CFDataRef CFMutableDataRef")

Modified: lldb/trunk/examples/summaries/cocoa/NSDate.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/summaries/cocoa/NSDate.py?rev=152592&r1=152591&r2=152592&view=diff
==============================================================================
--- lldb/trunk/examples/summaries/cocoa/NSDate.py (original)
+++ lldb/trunk/examples/summaries/cocoa/NSDate.py Mon Mar 12 19:25:59 2012
@@ -31,6 +31,13 @@
 	else:
 		return osx - osx_epoch
 
+# represent a struct_time as a string in the format used by Xcode
+def xcode_format_time(X):
+	return time.strftime('%Y-%m-%d %H:%M:%S %Z',X)
+
+# represent a count-since-epoch as a string in the format used by Xcode
+def xcode_format_count(X):
+	return xcode_format_time(time.localtime(X))
 
 # despite the similary to synthetic children providers, these classes are not
 # trying to provide anything but the summary for NSDate, so they need not
@@ -56,7 +63,7 @@
 		# while all Python knows about is the "epoch", which is a platform-dependent
 		# year (1970 of *nix) whose Jan 1 at midnight is taken as reference
 		value_double = struct.unpack('d', struct.pack('Q', self.data))[0]
-		return time.ctime(osx_to_python_time(value_double))
+		return xcode_format_count(osx_to_python_time(value_double))
 
 
 class NSUntaggedDate_SummaryProvider:
@@ -81,7 +88,7 @@
 							self.offset(),
 							self.sys_params.types_cache.double)
 		value_double = struct.unpack('d', struct.pack('Q', value.GetValueAsUnsigned(0)))[0]
-		return time.ctime(osx_to_python_time(value_double))
+		return xcode_format_count(osx_to_python_time(value_double))
 
 class NSCalendarDate_SummaryProvider:
 	def adjust_for_architecture(self):
@@ -105,7 +112,7 @@
 							self.offset(),
 							self.sys_params.types_cache.double)
 		value_double = struct.unpack('d', struct.pack('Q', value.GetValueAsUnsigned(0)))[0]
-		return time.ctime(osx_to_python_time(value_double))
+		return xcode_format_count(osx_to_python_time(value_double))
 
 class NSTimeZoneClass_SummaryProvider:
 	def adjust_for_architecture(self):
@@ -215,7 +222,7 @@
 def CFAbsoluteTime_SummaryProvider (valobj,dict):
 	try:
 		value_double = struct.unpack('d', struct.pack('Q', valobj.GetValueAsUnsigned(0)))[0]
-		return time.ctime(osx_to_python_time(value_double))
+		return xcode_format_count(osx_to_python_time(value_double))
 	except:
 		return 'unable to provide a summary'
 

Modified: lldb/trunk/examples/summaries/cocoa/NSException.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/summaries/cocoa/NSException.py?rev=152592&r1=152591&r2=152592&view=diff
==============================================================================
--- lldb/trunk/examples/summaries/cocoa/NSException.py (original)
+++ lldb/trunk/examples/summaries/cocoa/NSException.py Mon Mar 12 19:25:59 2012
@@ -36,7 +36,7 @@
 		reason_ptr = self.valobj.CreateChildAtOffset("reason",
 							self.offset_reason(),
 							self.sys_params.types_cache.id)
-		return CFString.CFString_SummaryProvider(name_ptr,None) + " " + CFString.CFString_SummaryProvider(reason_ptr,None)
+		return 'name:' + CFString.CFString_SummaryProvider(name_ptr,None) + ' reason:' + CFString.CFString_SummaryProvider(reason_ptr,None)
 
 class NSUnknownException_SummaryProvider:
 	def adjust_for_architecture(self):

Modified: lldb/trunk/examples/summaries/cocoa/NSSet.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/summaries/cocoa/NSSet.py?rev=152592&r1=152591&r2=152592&view=diff
==============================================================================
--- lldb/trunk/examples/summaries/cocoa/NSSet.py (original)
+++ lldb/trunk/examples/summaries/cocoa/NSSet.py Mon Mar 12 19:25:59 2012
@@ -225,7 +225,7 @@
 		else:
 			if provider.sys_params.is_64_bit:
 				summary = summary & ~0x1fff000000000000
-		 	summary = str(summary) + (' objects' if summary > 1 else ' object')
+		 	summary = '@"' + str(summary) + (' values"' if summary > 1 else ' value"')
 		return summary
 	return ''
 

Modified: lldb/trunk/examples/summaries/cocoa/NSURL.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/summaries/cocoa/NSURL.py?rev=152592&r1=152591&r2=152592&view=diff
==============================================================================
--- lldb/trunk/examples/summaries/cocoa/NSURL.py (original)
+++ lldb/trunk/examples/summaries/cocoa/NSURL.py Mon Mar 12 19:25:59 2012
@@ -47,8 +47,15 @@
 							self.offset_base(),
 							self.sys_params.types_cache.NSURL)
 		my_string = CFString.CFString_SummaryProvider(text,None)
-		if base.GetValueAsUnsigned(0) != 0:
-			my_string = my_string + " (base path: " + NSURL_SummaryProvider(base,None) + ")"
+		if len(my_string) > 0 and base.GetValueAsUnsigned(0) != 0:
+			# remove final " from myself
+			my_string = my_string[0:len(my_string)-1]
+			my_string = my_string + ' -- '
+			my_base_string = NSURL_SummaryProvider(base,None)
+			if len(my_base_string) > 2:
+				# remove @" marker from base URL string
+				my_base_string = my_base_string[2:]
+			my_string = my_string + my_base_string
 		return my_string
 
 

Modified: lldb/trunk/source/Core/FormatManager.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/FormatManager.cpp?rev=152592&r1=152591&r2=152592&view=diff
==============================================================================
--- lldb/trunk/source/Core/FormatManager.cpp (original)
+++ lldb/trunk/source/Core/FormatManager.cpp Mon Mar 12 19:25:59 2012
@@ -906,8 +906,8 @@
     AddScriptSummary(appkit_category_sp, "NSBundle.NSBundle_SummaryProvider", ConstString("NSBundle"), appkit_flags);
     
     AddScriptSummary(appkit_category_sp, "NSData.NSData_SummaryProvider", ConstString("NSData"), appkit_flags);
-    AddScriptSummary(appkit_category_sp, "NSData.NSData_SummaryProvider", ConstString("CFDataRef"), appkit_flags);
-    AddScriptSummary(appkit_category_sp, "NSData.NSData_SummaryProvider", ConstString("CFMutableDataRef"), appkit_flags);
+    AddScriptSummary(appkit_category_sp, "NSData.NSData_SummaryProvider2", ConstString("CFDataRef"), appkit_flags);
+    AddScriptSummary(appkit_category_sp, "NSData.NSData_SummaryProvider2", ConstString("CFMutableDataRef"), appkit_flags);
     
     AddScriptSummary(appkit_category_sp, "NSException.NSException_SummaryProvider", ConstString("NSException"), appkit_flags);
 

Modified: lldb/trunk/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjC.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjC.py?rev=152592&r1=152591&r2=152592&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjC.py (original)
+++ lldb/trunk/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjC.py Mon Mar 12 19:25:59 2012
@@ -218,13 +218,13 @@
                     '(NSString *) str12 = ',' @"Process Name:  a.out Process Id:'])
 
         self.expect('frame variable newArray newDictionary newMutableDictionary cfdict_ref mutable_dict_ref cfarray_ref mutable_array_ref',
-                    substrs = ['(NSArray *) newArray = ',' 50 objects',
+                    substrs = ['(NSArray *) newArray = ','@"50 objects"',
                     '(NSDictionary *) newDictionary = ',' 12 key/value pairs',
                     '(NSDictionary *) newMutableDictionary = ',' 21 key/value pairs',
-                    '(CFDictionaryRef) cfdict_ref = ',' 3 key/value pairs',
-                    '(CFMutableDictionaryRef) mutable_dict_ref = ',' 12 key/value pairs',
-                    '(CFArrayRef) cfarray_ref = ',' 3 objects',
-                    '(CFMutableArrayRef) mutable_array_ref = ',' 11 objects'])
+                    '(CFDictionaryRef) cfdict_ref = ','@"3 entries"',
+                    '(CFMutableDictionaryRef) mutable_dict_ref = ','@"12 entries"',
+                    '(CFArrayRef) cfarray_ref = ','@"3 objects"',
+                    '(CFMutableArrayRef) mutable_array_ref = ','@"11 objects"'])
 
         self.expect('frame variable attrString mutableAttrString mutableGetConst',
                     substrs = ['(NSAttributedString *) attrString = ',' @"hello world from foo"',
@@ -234,24 +234,24 @@
         self.expect('frame variable immutableData mutableData data_ref mutable_data_ref mutable_string_ref',
                     substrs = ['(NSData *) immutableData = ',' 4 bytes',
                     '(NSData *) mutableData = ',' 14 bytes',
-                    '(CFDataRef) data_ref = ',' 5 bytes',
-                    '(CFMutableDataRef) mutable_data_ref = ',' 5 bytes',
+                    '(CFDataRef) data_ref = ','@"5 bytes"',
+                    '(CFMutableDataRef) mutable_data_ref = ','@"5 bytes"',
                     '(CFMutableStringRef) mutable_string_ref = ',' @"Wish ya knew"'])
 
         self.expect('frame variable mutable_bag_ref cfbag_ref binheap_ref',
-                    substrs = ['(CFMutableBagRef) mutable_bag_ref = ',' 17 items',
-                    '(CFBagRef) cfbag_ref = ',' 15 items',
-                    '(CFBinaryHeapRef) binheap_ref = ',' 21 items'])
+                    substrs = ['(CFMutableBagRef) mutable_bag_ref = ','@"17 values"',
+                    '(CFBagRef) cfbag_ref = ','@"15 values"',
+                    '(CFBinaryHeapRef) binheap_ref = ','@"21 items"'])
 
         self.expect('frame variable cfurl_ref cfchildurl_ref cfgchildurl_ref',
-                    substrs = ['(CFURLRef) cfurl_ref = ',' @"http://www.foo.bar/"',
-                    'cfchildurl_ref = ',' @"page.html" (base path: @"http://www.foo.bar/")',
-                    '(CFURLRef) cfgchildurl_ref = ',' @"?whatever" (base path: @"http://www.foo.bar/page.html")'])
+                    substrs = ['(CFURLRef) cfurl_ref = ','@"http://www.foo.bar',
+                    'cfchildurl_ref = ','@"page.html -- http://www.foo.bar',
+                    '(CFURLRef) cfgchildurl_ref = ','@"?whatever -- http://www.foo.bar/page.html"'])
 
         self.expect('frame variable nsurl nsurl2 nsurl3',
-                    substrs = ['(NSURL *) nsurl = ',' @"http://www.foo.bar"',
-                    '(NSURL *) nsurl2 =',' @"page.html" (base path: @"http://www.foo.bar")',
-                    '(NSURL *) nsurl3 = ',' @"?whatever" (base path: @"http://www.foo.bar/page.html")'])
+                    substrs = ['(NSURL *) nsurl = ','@"http://www.foo.bar',
+                    '(NSURL *) nsurl2 =','@"page.html -- http://www.foo.bar',
+                    '(NSURL *) nsurl3 = ','@"?whatever -- http://www.foo.bar/page.html"'])
 
         self.expect('frame variable bundle_string bundle_url main_bundle',
                     substrs = ['(NSBundle *) bundle_string = ',' @"/System/Library/Frameworks/Accelerate.framework"',
@@ -259,16 +259,16 @@
                     '(NSBundle *) main_bundle = ','test/functionalities/data-formatter/data-formatter-objc'])
 
         self.expect('frame variable except0 except1 except2 except3',
-                    substrs = ['(NSException *) except0 = ',' @"TheGuyWhoHasNoName" @"cuz it\'s funny"',
-                    '(NSException *) except1 = ',' @"TheGuyWhoHasNoName~1" @"cuz it\'s funny"',
-                    '(NSException *) except2 = ',' @"TheGuyWhoHasNoName`2" @"cuz it\'s funny"',
-                    '(NSException *) except3 = ',' @"TheGuyWhoHasNoName/3" @"cuz it\'s funny"'])
+                    substrs = ['(NSException *) except0 = ','name:@"TheGuyWhoHasNoName" reason:@"cuz it\'s funny"',
+                    '(NSException *) except1 = ','name:@"TheGuyWhoHasNoName~1" reason:@"cuz it\'s funny"',
+                    '(NSException *) except2 = ','name:@"TheGuyWhoHasNoName`2" reason:@"cuz it\'s funny"',
+                    '(NSException *) except3 = ','name:@"TheGuyWhoHasNoName/3" reason:@"cuz it\'s funny"'])
 
         self.expect('frame variable port',
                     substrs = ['(NSMachPort *) port = ',' mach port: '])
 
         self.expect('frame variable date1 date2',
-                    substrs = ['10','1985','1','2011'])
+                    substrs = ['1985-04','2011-01'])
 
         # this test might fail if we hit the breakpoint late on December 31st of some given year
         # and midnight comes between hitting the breakpoint and running this line of code
@@ -279,7 +279,7 @@
                     substrs = [now_year,'1970'])
 
         self.expect('frame variable date1_abs date2_abs',
-                    substrs = ['10','1985','1','2011'])
+                    substrs = ['1985-04','2011-01'])
 
         self.expect('frame variable date3_abs date4_abs',
                     substrs = [now_year,'1970'])
@@ -417,7 +417,7 @@
              '(Point *) point_ptr = (v=7, h=12)',
              '(HIPoint) hi_point = (x=7, y=12)',
              '(HIRect) hi_rect = origin=(x=3, y=5) size=(width=4, height=6)',
-             '@"TheGuyWhoHasNoName" @"cuz it\'s funny"',
+             'name:@"TheGuyWhoHasNoName" reason:@"cuz it\'s funny"',
              '1985',
              'foo_selector_impl'])
         self.runCmd('log timers dump')

Modified: lldb/trunk/test/functionalities/data-formatter/rdar-3534688/TestFormattersOneIsSingular.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/rdar-3534688/TestFormattersOneIsSingular.py?rev=152592&r1=152591&r2=152592&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/data-formatter/rdar-3534688/TestFormattersOneIsSingular.py (original)
+++ lldb/trunk/test/functionalities/data-formatter/rdar-3534688/TestFormattersOneIsSingular.py Mon Mar 12 19:25:59 2012
@@ -63,11 +63,11 @@
         # Now enable AppKit and check we are displaying Cocoa classes correctly
         self.runCmd("type category enable AppKit")
         self.expect('frame variable key',
-                    substrs = ['1 object'])
+                    substrs = ['@"1 object"'])
         self.expect('frame variable key', matching=False,
                     substrs = ['1 objects'])
         self.expect('frame variable value',
-                    substrs = ['1 object'])
+                    substrs = ['@"1 object"'])
         self.expect('frame variable value', matching=False,
                     substrs = ['1 objects'])
         self.expect('frame variable dict',
@@ -75,9 +75,9 @@
         self.expect('frame variable dict', matching=False,
                     substrs = ['1 key/value pairs'])
         self.expect('frame variable mutable_bag_ref',
-                    substrs = ['1 item'])
+                    substrs = ['@"1 value"'])
         self.expect('frame variable mutable_bag_ref', matching=False,
-                    substrs = ['1 items'])
+                    substrs = ['1 values'])
         self.expect('frame variable nscounted_set',
                     substrs = ['1 object'])
         self.expect('frame variable nscounted_set', matching=False,
@@ -87,7 +87,7 @@
         self.expect('frame variable imset', matching=False,
                     substrs = ['1 objects'])
         self.expect('frame variable binheap_ref',
-                    substrs = ['1 item'])
+                    substrs = ['@"1 item"'])
         self.expect('frame variable binheap_ref', matching=False,
                     substrs = ['1 items'])
         self.expect('frame variable nsset',





More information about the lldb-commits mailing list