[Lldb-commits] [lldb] r152673 - in /lldb/trunk: examples/summaries/cocoa/ source/Core/

Enrico Granata egranata at apple.com
Tue Mar 13 14:52:01 PDT 2012


Author: enrico
Date: Tue Mar 13 16:52:00 2012
New Revision: 152673

URL: http://llvm.org/viewvc/llvm-project?rev=152673&view=rev
Log:
The Cocoa formatters now provide error messages for many of the common things-went-wrong situations. Previously they would say nothing or log failures to the Python console

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/CFBitVector.py
    lldb/trunk/examples/summaries/cocoa/CFDictionary.py
    lldb/trunk/examples/summaries/cocoa/CFString.py
    lldb/trunk/examples/summaries/cocoa/NSBundle.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/NSIndexSet.py
    lldb/trunk/examples/summaries/cocoa/NSMachPort.py
    lldb/trunk/examples/summaries/cocoa/NSNotification.py
    lldb/trunk/examples/summaries/cocoa/NSNumber.py
    lldb/trunk/examples/summaries/cocoa/NSSet.py
    lldb/trunk/examples/summaries/cocoa/NSURL.py
    lldb/trunk/examples/summaries/cocoa/Selector.py
    lldb/trunk/examples/summaries/cocoa/attrib_fromdict.py
    lldb/trunk/examples/summaries/cocoa/cache.py
    lldb/trunk/examples/summaries/cocoa/metrics.py
    lldb/trunk/examples/summaries/cocoa/objc_runtime.py
    lldb/trunk/source/Core/FormatManager.cpp

Modified: lldb/trunk/examples/summaries/cocoa/CFArray.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/summaries/cocoa/CFArray.py?rev=152673&r1=152672&r2=152673&view=diff
==============================================================================
--- lldb/trunk/examples/summaries/cocoa/CFArray.py (original)
+++ lldb/trunk/examples/summaries/cocoa/CFArray.py Tue Mar 13 16:52:00 2012
@@ -1,3 +1,10 @@
+"""
+LLDB AppKit formatters
+
+part of The LLVM Compiler Infrastructure
+This file is distributed under the University of Illinois Open Source
+License. See LICENSE.TXT for details.
+"""
 # synthetic children provider for NSArray
 import lldb
 import ctypes
@@ -29,7 +36,9 @@
 		stream = lldb.SBStream()
 		self.valobj.GetExpressionPath(stream)
 		num_children_vo = self.valobj.CreateValueFromExpression("count","(int)[" + stream.GetData() + " count]");
-		return num_children_vo.GetValueAsUnsigned(0)
+		if num_children_vo.IsValid():
+			return num_children_vo.GetValueAsUnsigned(0)
+		return "<variable is not NSArray>"
 
 # much less functional than the other two cases below
 # just runs code to get to the count and then returns
@@ -107,7 +116,8 @@
 	def __init__(self, valobj, dict):
 		self.valobj = valobj;
 		self.adjust_for_architecture()
-		self.wrapper = self.make_wrapper(valobj,dict)
+		self.error = False
+		self.wrapper = self.make_wrapper()
 		self.invalid = (self.wrapper == None)
 
 	def num_children(self):
@@ -122,54 +132,50 @@
 
 	# this code acts as our defense against NULL and unitialized
 	# NSArray pointers, which makes it much longer than it would be otherwise
-	def make_wrapper(self,valobj,dict):
-		global statistics
-		class_data = objc_runtime.ObjCRuntime(valobj)
-		if class_data.is_valid() == False:
-			statistics.metric_hit('invalid_pointer',valobj)
-			wrapper = None
-			return
-		class_data = class_data.read_class_data()
-		if class_data.is_valid() == False:
-			statistics.metric_hit('invalid_isa',valobj)
-			wrapper = None
-			return
-		if class_data.is_kvo():
-			class_data = class_data.get_superclass()
-		if class_data.is_valid() == False:
-			statistics.metric_hit('invalid_isa',valobj)
-			wrapper = None
-			return
+	def make_wrapper(self):
+		if self.valobj.GetValueAsUnsigned() == 0:
+			self.error = True
+			return objc_runtime.InvalidPointer_Description(True)
+		else:
+			global statistics
+			class_data,wrapper = objc_runtime.Utilities.prepare_class_detection(self.valobj,statistics)
+			if wrapper:
+				self.error = True
+				return wrapper
 		
 		name_string = class_data.class_name()
 		if name_string == '__NSArrayI':
-			wrapper = NSArrayI_SynthProvider(valobj, dict, class_data.sys_params)
-			statistics.metric_hit('code_notrun',valobj)
+			wrapper = NSArrayI_SynthProvider(self.valobj, dict, class_data.sys_params)
+			statistics.metric_hit('code_notrun',self.valobj)
 		elif name_string == '__NSArrayM':
-			wrapper = NSArrayM_SynthProvider(valobj, dict, class_data.sys_params)
-			statistics.metric_hit('code_notrun',valobj)
+			wrapper = NSArrayM_SynthProvider(self.valobj, dict, class_data.sys_params)
+			statistics.metric_hit('code_notrun',self.valobj)
 		elif name_string == '__NSCFArray':
-			wrapper = NSArrayCF_SynthProvider(valobj, dict, class_data.sys_params)
-			statistics.metric_hit('code_notrun',valobj)
+			wrapper = NSArrayCF_SynthProvider(self.valobj, dict, class_data.sys_params)
+			statistics.metric_hit('code_notrun',self.valobj)
 		else:
-			wrapper = NSArrayKVC_SynthProvider(valobj, dict, class_data.sys_params)
-			statistics.metric_hit('unknown_class',str(valobj) + " seen as " + name_string)
+			wrapper = NSArrayKVC_SynthProvider(self.valobj, dict, class_data.sys_params)
+			statistics.metric_hit('unknown_class',str(self.valobj) + " seen as " + name_string)
 		return wrapper;
 
 def CFArray_SummaryProvider (valobj,dict):
 	provider = NSArray_SynthProvider(valobj,dict);
 	if provider.invalid == False:
-	    try:
-	        summary = int(provider.num_children());
-	    except:
-	        summary = None
-	    if summary == None:
-	        summary = 'no valid array here'
-	    else:
-	        # 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 ''
+		if provider.error == True:
+			return provider.wrapper.message()
+		try:
+			summary = int(provider.num_children());
+		except:
+			summary = None
+		if summary == None:
+			summary = '<variable is not NSArray>'
+		elif isinstance(summary,basestring):
+			pass
+		else:
+			# 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 'Summary Unavailable'
 
 def __lldb_init_module(debugger,dict):
 	debugger.HandleCommand("type summary add -F CFArray.CFArray_SummaryProvider NSArray CFArrayRef CFMutableArrayRef")

Modified: lldb/trunk/examples/summaries/cocoa/CFBag.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/summaries/cocoa/CFBag.py?rev=152673&r1=152672&r2=152673&view=diff
==============================================================================
--- lldb/trunk/examples/summaries/cocoa/CFBag.py (original)
+++ lldb/trunk/examples/summaries/cocoa/CFBag.py Tue Mar 13 16:52:00 2012
@@ -1,3 +1,10 @@
+"""
+LLDB AppKit formatters
+
+part of The LLVM Compiler Infrastructure
+This file is distributed under the University of Illinois Open Source
+License. See LICENSE.TXT for details.
+"""
 # summary provider for CFBag
 import lldb
 import ctypes
@@ -61,43 +68,33 @@
 	def length(self):
 		stream = lldb.SBStream()
 		self.valobj.GetExpressionPath(stream)
-		num_children_vo = self.valobj.CreateValueFromExpression("count","(int)CFBagGetCount(" + stream.GetData() + " )");
-		return num_children_vo.GetValueAsUnsigned(0)
+		num_children_vo = self.valobj.CreateValueFromExpression("count","(int)CFBagGetCount(" + stream.GetData() + " )")
+		if num_children_vo.IsValid():
+			return num_children_vo.GetValueAsUnsigned(0)
+		return "<variable is not CFBag>"
 
 
 def GetSummary_Impl(valobj):
 	global statistics
-	class_data = objc_runtime.ObjCRuntime(valobj)
-	if class_data.is_valid() == False:
-		statistics.metric_hit('invalid_pointer',valobj)
-		wrapper = None
-		return
-	class_data = class_data.read_class_data()
-	if class_data.is_valid() == False:
-		statistics.metric_hit('invalid_isa',valobj)
-		wrapper = None
-		return
-	if class_data.is_kvo():
-		class_data = class_data.get_superclass()
-	if class_data.is_valid() == False:
-		statistics.metric_hit('invalid_isa',valobj)
-		wrapper = None
-		return
+	class_data,wrapper = objc_runtime.Utilities.prepare_class_detection(valobj,statistics)
+	if wrapper:
+		return wrapper
 	
 	name_string = class_data.class_name()
 	actual_name = name_string
-	if name_string == '__NSCFType':
+	if class_data.is_cftype():
 		# CFBag does not expose an actual NSWrapper type, so we have to check that this is
 		# an NSCFType and then check we are a pointer-to __CFBag
 		valobj_type = valobj.GetType()
 		if valobj_type.IsValid() and valobj_type.IsPointerType():
-			pointee_type = valobj_type.GetPointeeType()
-			actual_name = pointee_type.GetName()
-			if actual_name == '__CFBag' or \
-			   actual_name == 'const struct __CFBag':
-				wrapper = CFBagRef_SummaryProvider(valobj, class_data.sys_params)
-				statistics.metric_hit('code_notrun',valobj)
-				return wrapper
+			valobj_type = valobj_type.GetPointeeType()
+			if valobj_type.IsValid():
+				actual_name = valobj_type.GetName()
+		if actual_name == '__CFBag' or \
+		   actual_name == 'const struct __CFBag':
+			wrapper = CFBagRef_SummaryProvider(valobj, class_data.sys_params)
+			statistics.metric_hit('code_notrun',valobj)
+			return wrapper
 	wrapper = CFBagUnknown_SummaryProvider(valobj, class_data.sys_params)
 	statistics.metric_hit('unknown_class',str(valobj) + " seen as " + actual_name)
 	return wrapper;
@@ -105,6 +102,8 @@
 def CFBag_SummaryProvider (valobj,dict):
 	provider = GetSummary_Impl(valobj);
 	if provider != None:
+		if isinstance(provider,objc_runtime.SpecialSituation_Description):
+			return provider.message()
 		try:
 			summary = provider.length();
 		except:
@@ -115,7 +114,9 @@
 		# (if counts start looking weird, then most probably
 		#  the mask needs to be changed)
 		if summary == None:
-			summary = 'no valid set here'
+			summary = '<variable is not CFBag>'
+		elif isinstance(summary,basestring):
+			pass
 		else:
 			if provider.sys_params.is_64_bit:
 				summary = summary & ~0x1fff000000000000
@@ -124,7 +125,7 @@
 			else:
 				summary = '@"' + str(summary) + ' values"'
 		return summary
-	return ''
+	return 'Summary Unavailable'
 
 def __lldb_init_module(debugger,dict):
 	debugger.HandleCommand("type summary add -F CFBag.CFBag_SummaryProvider CFBagRef CFMutableBagRef")

Modified: lldb/trunk/examples/summaries/cocoa/CFBinaryHeap.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/summaries/cocoa/CFBinaryHeap.py?rev=152673&r1=152672&r2=152673&view=diff
==============================================================================
--- lldb/trunk/examples/summaries/cocoa/CFBinaryHeap.py (original)
+++ lldb/trunk/examples/summaries/cocoa/CFBinaryHeap.py Tue Mar 13 16:52:00 2012
@@ -1,3 +1,10 @@
+"""
+LLDB AppKit formatters
+
+part of The LLVM Compiler Infrastructure
+This file is distributed under the University of Illinois Open Source
+License. See LICENSE.TXT for details.
+"""
 # summary provider for CFBinaryHeap
 import lldb
 import ctypes
@@ -59,39 +66,31 @@
 		stream = lldb.SBStream()
 		self.valobj.GetExpressionPath(stream)
 		num_children_vo = self.valobj.CreateValueFromExpression("count","(int)CFBinaryHeapGetCount(" + stream.GetData() + " )");
-		return num_children_vo.GetValueAsUnsigned(0)
+		if num_children_vo.IsValid():
+			return num_children_vo.GetValueAsUnsigned(0)
+		return '<variable is not CFBinaryHeap>'
 
 
 def GetSummary_Impl(valobj):
 	global statistics
-	class_data = objc_runtime.ObjCRuntime(valobj)
-	if class_data.is_valid() == False:
-		statistics.metric_hit('invalid_pointer',valobj)
-		wrapper = None
-		return
-	class_data = class_data.read_class_data()
-	if class_data.is_valid() == False:
-		statistics.metric_hit('invalid_isa',valobj)
-		wrapper = None
-		return
-	if class_data.is_kvo():
-		class_data = class_data.get_superclass()
-	if class_data.is_valid() == False:
-		statistics.metric_hit('invalid_isa',valobj)
-		wrapper = None
-		return
+	class_data,wrapper = objc_runtime.Utilities.prepare_class_detection(valobj,statistics)
+	if wrapper:
+		return wrapper
 	
 	name_string = class_data.class_name()
-	if name_string == '__NSCFType':
+	actual_name = class_data.class_name()
+	if class_data.is_cftype():
 		# CFBinaryHeap does not expose an actual NSWrapper type, so we have to check that this is
 		# an NSCFType and then check we are a pointer-to CFBinaryHeap
 		valobj_type = valobj.GetType()
 		if valobj_type.IsValid() and valobj_type.IsPointerType():
-			pointee_type = valobj_type.GetPointeeType()
-			if pointee_type.GetName() == '__CFBinaryHeap':
-				wrapper = CFBinaryHeapRef_SummaryProvider(valobj, class_data.sys_params)
-				statistics.metric_hit('code_notrun',valobj)
-				return wrapper
+			valobj_type = valobj_type.GetPointeeType()
+			if valobj_type.IsValid():
+				actual_name = valobj_type.GetName()
+		if actual_name == '__CFBinaryHeap':
+			wrapper = CFBinaryHeapRef_SummaryProvider(valobj, class_data.sys_params)
+			statistics.metric_hit('code_notrun',valobj)
+			return wrapper
 	wrapper = CFBinaryHeapUnknown_SummaryProvider(valobj, class_data.sys_params)
 	statistics.metric_hit('unknown_class',str(valobj) + " seen as " + name_string)
 	return wrapper;
@@ -99,6 +98,8 @@
 def CFBinaryHeap_SummaryProvider (valobj,dict):
 	provider = GetSummary_Impl(valobj);
 	if provider != None:
+		if isinstance(provider,objc_runtime.SpecialSituation_Description):
+			return provider.message()
 		try:
 			summary = provider.length();
 		except:
@@ -109,7 +110,9 @@
 		# (if counts start looking weird, then most probably
 		#  the mask needs to be changed)
 		if summary == None:
-			summary = 'no valid set here'
+			summary = '<variable is not CFBinaryHeap>'
+		elif isinstance(summary,basestring):
+			pass
 		else:
 			if provider.sys_params.is_64_bit:
 				summary = summary & ~0x1fff000000000000
@@ -118,7 +121,7 @@
 			else:
 				summary = '@"' + str(summary) + ' items"'
 		return summary
-	return ''
+	return 'Summary Unavailable'
 
 def __lldb_init_module(debugger,dict):
 	debugger.HandleCommand("type summary add -F CFBinaryHeap.CFBinaryHeap_SummaryProvider CFBinaryHeapRef")

Modified: lldb/trunk/examples/summaries/cocoa/CFBitVector.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/summaries/cocoa/CFBitVector.py?rev=152673&r1=152672&r2=152673&view=diff
==============================================================================
--- lldb/trunk/examples/summaries/cocoa/CFBitVector.py (original)
+++ lldb/trunk/examples/summaries/cocoa/CFBitVector.py Tue Mar 13 16:52:00 2012
@@ -1,3 +1,10 @@
+"""
+LLDB AppKit formatters
+
+part of The LLVM Compiler Infrastructure
+This file is distributed under the University of Illinois Open Source
+License. See LICENSE.TXT for details.
+"""
 # summary provider for CF(Mutable)BitVector
 import lldb
 import ctypes
@@ -101,41 +108,31 @@
 		self.adjust_for_architecture();
 
 	def contents(self):
-		return '*** unknown class *** very bad thing *** find out my name ***'
+		return '<unable to summarize this CFBitVector>'
 
 
 def GetSummary_Impl(valobj):
 	global statistics
-	class_data = objc_runtime.ObjCRuntime(valobj)
-	if class_data.is_valid() == False:
-		statistics.metric_hit('invalid_pointer',valobj)
-		wrapper = None
-		return
-	class_data = class_data.read_class_data()
-	if class_data.is_valid() == False:
-		statistics.metric_hit('invalid_isa',valobj)
-		wrapper = None
-		return
-	if class_data.is_kvo():
-		class_data = class_data.get_superclass()
-	if class_data.is_valid() == False:
-		statistics.metric_hit('invalid_isa',valobj)
-		wrapper = None
-		return
+	class_data,wrapper = objc_runtime.Utilities.prepare_class_detection(valobj,statistics)
+	if wrapper:
+		return wrapper
 
 	name_string = class_data.class_name()
-	if name_string == '__NSCFType':
+	actual_name = name_string
+	if class_data.is_cftype():
 		# CFBitVectorRef does not expose an actual NSWrapper type, so we have to check that this is
 		# an NSCFType and then check we are a pointer-to CFBitVectorRef
 		valobj_type = valobj.GetType()
 		if valobj_type.IsValid() and valobj_type.IsPointerType():
-			pointee_type = valobj_type.GetPointeeType()
-			if pointee_type.GetName() == '__CFBitVector' or pointee_type.GetName() == '__CFMutableBitVector':
-				wrapper = CFBitVectorKnown_SummaryProvider(valobj, class_data.sys_params)
-				statistics.metric_hit('code_notrun',valobj)
-			else:
-				wrapper = CFBitVectorUnknown_SummaryProvider(valobj)
-				print pointee_type.GetName()
+			valobj_type = valobj_type.GetPointeeType()
+			if valobj_type.IsValid():
+				actual_name = valobj_type.GetName()
+		if actual_name == '__CFBitVector' or actual_name == '__CFMutableBitVector':
+			wrapper = CFBitVectorKnown_SummaryProvider(valobj, class_data.sys_params)
+			statistics.metric_hit('code_notrun',valobj)
+		else:
+			wrapper = CFBitVectorUnknown_SummaryProvider(valobj, class_data.sys_params)
+			print actual_name
 	else:
 		wrapper = CFBitVectorUnknown_SummaryProvider(valobj, class_data.sys_params)
 		print name_string
@@ -145,14 +142,16 @@
 def CFBitVector_SummaryProvider (valobj,dict):
 	provider = GetSummary_Impl(valobj);
 	if provider != None:
-	    #try:
-	    summary = provider.contents();
-	    #except:
-	    #    summary = None
-	    if summary == None or summary == '':
-	        summary = 'no valid bitvector here'
-	    return summary
-	return ''
+		if isinstance(provider,objc_runtime.SpecialSituation_Description):
+			return provider.message()
+		try:
+			summary = provider.contents();
+		except:
+			summary = None
+		if summary == None or summary == '':
+			summary = '<variable is not CFBitVector>'
+		return summary
+	return 'Summary Unavailable'
 
 def __lldb_init_module(debugger,dict):
 	debugger.HandleCommand("type summary add -F CFBitVector.CFBitVector_SummaryProvider CFBitVectorRef CFMutableBitVectorRef")

Modified: lldb/trunk/examples/summaries/cocoa/CFDictionary.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/summaries/cocoa/CFDictionary.py?rev=152673&r1=152672&r2=152673&view=diff
==============================================================================
--- lldb/trunk/examples/summaries/cocoa/CFDictionary.py (original)
+++ lldb/trunk/examples/summaries/cocoa/CFDictionary.py Tue Mar 13 16:52:00 2012
@@ -1,3 +1,10 @@
+"""
+LLDB AppKit formatters
+
+part of The LLVM Compiler Infrastructure
+This file is distributed under the University of Illinois Open Source
+License. See LICENSE.TXT for details.
+"""
 # summary provider for NSDictionary
 import lldb
 import ctypes
@@ -135,27 +142,16 @@
 		stream = lldb.SBStream()
 		self.valobj.GetExpressionPath(stream)
 		num_children_vo = self.valobj.CreateValueFromExpression("count","(int)[" + stream.GetData() + " count]");
-		return num_children_vo.GetValueAsUnsigned(0)
+		if num_children_vo.IsValid():
+			return num_children_vo.GetValueAsUnsigned(0)
+		return '<variable is not NSDictionary>'
 
 
 def GetSummary_Impl(valobj):
 	global statistics
-	class_data = objc_runtime.ObjCRuntime(valobj)
-	if class_data.is_valid() == False:
-		statistics.metric_hit('invalid_pointer',valobj)
-		wrapper = None
-		return
-	class_data = class_data.read_class_data()
-	if class_data.is_valid() == False:
-		statistics.metric_hit('invalid_isa',valobj)
-		wrapper = None
-		return
-	if class_data.is_kvo():
-		class_data = class_data.get_superclass()
-	if class_data.is_valid() == False:
-		statistics.metric_hit('invalid_isa',valobj)
-		wrapper = None
-		return
+	class_data,wrapper = objc_runtime.Utilities.prepare_class_detection(valobj,statistics)
+	if wrapper:
+		return wrapper
 	
 	name_string = class_data.class_name()
 	if name_string == '__NSCFDictionary':
@@ -175,31 +171,39 @@
 def CFDictionary_SummaryProvider (valobj,dict):
 	provider = GetSummary_Impl(valobj);
 	if provider != None:
-	    try:
-	        summary = provider.num_children();
-	    except:
-	        summary = None
-	    if summary == None:
-	        summary = 'no valid dictionary here'
-	    return str(summary) + (" key/value pairs" if summary > 1 else " key/value pair")
-	return ''
+		if isinstance(provider,objc_runtime.SpecialSituation_Description):
+			return provider.message()
+		try:
+			summary = provider.num_children();
+		except:
+			summary = None
+		if summary == None:
+			return '<variable is not NSDictionary>'
+		if isinstance(summary,basestring):
+			return summary
+		return str(summary) + (" key/value pairs" if summary != 1 else " key/value pair")
+	return 'Summary Unavailable'
 
 def CFDictionary_SummaryProvider2 (valobj,dict):
 	provider = GetSummary_Impl(valobj);
 	if provider != None:
+		if isinstance(provider,objc_runtime.SpecialSituation_Description):
+			return provider.message()
 		try:
 			summary = provider.num_children();
 		except:
 			summary = None
 		if summary == None:
-			summary = 'no valid dictionary here'
+			summary = '<variable is not CFDictionary>'
+		if isinstance(summary,basestring):
+			return summary
 		else:
 		# needed on OSX Mountain Lion
 			if provider.sys_params.is_64_bit:
 				summary = summary & ~0x0f1f000000000000
-			summary = '@"' + str(summary) + (' entries"' if summary > 1 else ' entry"')
+			summary = '@"' + str(summary) + (' entries"' if summary != 1 else ' entry"')
 		return summary
-	return ''
+	return 'Summary Unavailable'
 
 def __lldb_init_module(debugger,dict):
 	debugger.HandleCommand("type summary add -F CFDictionary.CFDictionary_SummaryProvider NSDictionary")

Modified: lldb/trunk/examples/summaries/cocoa/CFString.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/summaries/cocoa/CFString.py?rev=152673&r1=152672&r2=152673&view=diff
==============================================================================
--- lldb/trunk/examples/summaries/cocoa/CFString.py (original)
+++ lldb/trunk/examples/summaries/cocoa/CFString.py Tue Mar 13 16:52:00 2012
@@ -1,3 +1,10 @@
+"""
+LLDB AppKit formatters
+
+part of The LLVM Compiler Infrastructure
+This file is distributed under the University of Illinois Open Source
+License. See LICENSE.TXT for details.
+"""
 # synthetic children and summary provider for CFString
 # (and related NSString class)
 import lldb
@@ -6,19 +13,19 @@
 def CFString_SummaryProvider (valobj,dict):
 	provider = CFStringSynthProvider(valobj,dict);
 	if provider.invalid == False:
-	    try:
-	        summary = provider.get_child_at_index(provider.get_child_index("content")).GetSummary();
-	    except:
-	        summary = None
-	    if summary == None:
-	        summary = 'no valid string here'
-	    return '@'+summary
+		try:
+			summary = provider.get_child_at_index(provider.get_child_index("content")).GetSummary();
+		except:
+			summary = None
+		if summary == None:
+			summary = '<variable is not NSString>'
+		return '@'+summary
 	return ''
 
 def CFAttributedString_SummaryProvider (valobj,dict):
 	offset = valobj.GetTarget().GetProcess().GetAddressByteSize()
 	pointee = valobj.GetValueAsUnsigned(0)
-	summary = 'no valid string here'
+	summary = '<variable is not NSAttributedString>'
 	if pointee != None and pointee != 0:
 		pointee = pointee + offset
 		child_ptr = valobj.CreateValueFromAddress("string_ptr",pointee,valobj.GetType())
@@ -28,9 +35,9 @@
 			try:
 				summary = provider.get_child_at_index(provider.get_child_index("content")).GetSummary();
 			except:
-				summary = 'no valid string here'
+				summary = '<variable is not NSAttributedString>'
 	if summary == None:
-		summary = 'no valid string here'
+		summary = '<variable is not NSAttributedString>'
 	return '@'+summary
 
 

Modified: lldb/trunk/examples/summaries/cocoa/NSBundle.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/summaries/cocoa/NSBundle.py?rev=152673&r1=152672&r2=152673&view=diff
==============================================================================
--- lldb/trunk/examples/summaries/cocoa/NSBundle.py (original)
+++ lldb/trunk/examples/summaries/cocoa/NSBundle.py Tue Mar 13 16:52:00 2012
@@ -1,3 +1,10 @@
+"""
+LLDB AppKit formatters
+
+part of The LLVM Compiler Infrastructure
+This file is distributed under the University of Illinois Open Source
+License. See LICENSE.TXT for details.
+"""
 # summary provider for NSBundle
 import lldb
 import ctypes
@@ -65,27 +72,16 @@
 		self.valobj.GetExpressionPath(stream)
 		expr = "(NSString*)[" + stream.GetData() + " bundlePath]"
 		url_text_vo = self.valobj.CreateValueFromExpression("path",expr);
-		return url_text_vo.GetSummary()
+		if url_text_vo.IsValid():
+			return url_text_vo.GetSummary()
+		return '<variable is not NSBundle>'
 
 
 def GetSummary_Impl(valobj):
 	global statistics
-	class_data = objc_runtime.ObjCRuntime(valobj)
-	if class_data.is_valid() == False:
-		statistics.metric_hit('invalid_pointer',valobj)
-		wrapper = None
-		return
-	class_data = class_data.read_class_data()
-	if class_data.is_valid() == False:
-		statistics.metric_hit('invalid_isa',valobj)
-		wrapper = None
-		return
-	if class_data.is_kvo():
-		class_data = class_data.get_superclass()
-	if class_data.is_valid() == False:
-		statistics.metric_hit('invalid_isa',valobj)
-		wrapper = None
-		return
+	class_data,wrapper = objc_runtime.Utilities.prepare_class_detection(valobj,statistics)
+	if wrapper:
+		return wrapper
 	
 	name_string = class_data.class_name()
 	if name_string == 'NSBundle':
@@ -102,14 +98,16 @@
 def NSBundle_SummaryProvider (valobj,dict):
 	provider = GetSummary_Impl(valobj);
 	if provider != None:
-	    try:
-	        summary = provider.url_text();
-	    except:
-	        summary = None
-	    if summary == None or summary == '':
-	        summary = 'no valid NSBundle here'
-	    return summary
-	return ''
+		if isinstance(provider,objc_runtime.SpecialSituation_Description):
+			return provider.message()
+		try:
+			summary = provider.url_text();
+		except:
+			summary = None
+		if summary == None or summary == '':
+			summary = '<variable is not NSBundle>'
+		return summary
+	return 'Summary Unavailable'
 
 def __lldb_init_module(debugger,dict):
 	debugger.HandleCommand("type summary add -F NSBundle.NSBundle_SummaryProvider NSBundle")

Modified: lldb/trunk/examples/summaries/cocoa/NSData.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/summaries/cocoa/NSData.py?rev=152673&r1=152672&r2=152673&view=diff
==============================================================================
--- lldb/trunk/examples/summaries/cocoa/NSData.py (original)
+++ lldb/trunk/examples/summaries/cocoa/NSData.py Tue Mar 13 16:52:00 2012
@@ -1,3 +1,10 @@
+"""
+LLDB AppKit formatters
+
+part of The LLVM Compiler Infrastructure
+This file is distributed under the University of Illinois Open Source
+License. See LICENSE.TXT for details.
+"""
 # summary provider for NSData
 import lldb
 import ctypes
@@ -61,27 +68,16 @@
 		stream = lldb.SBStream()
 		self.valobj.GetExpressionPath(stream)
 		num_children_vo = self.valobj.CreateValueFromExpression("count","(int)[" + stream.GetData() + " length]");
-		return num_children_vo.GetValueAsUnsigned(0)
+		if num_children_vo.IsValid():
+			return num_children_vo.GetValueAsUnsigned(0)
+		return '<variable is not NSData>'
 
 
 def GetSummary_Impl(valobj):
 	global statistics
-	class_data = objc_runtime.ObjCRuntime(valobj)
-	if class_data.is_valid() == False:
-		statistics.metric_hit('invalid_pointer',valobj)
-		wrapper = None
-		return
-	class_data = class_data.read_class_data()
-	if class_data.is_valid() == False:
-		statistics.metric_hit('invalid_isa',valobj)
-		wrapper = None
-		return
-	if class_data.is_kvo():
-		class_data = class_data.get_superclass()
-	if class_data.is_valid() == False:
-		statistics.metric_hit('invalid_isa',valobj)
-		wrapper = None
-		return
+	class_data,wrapper = objc_runtime.Utilities.prepare_class_detection(valobj,statistics)
+	if wrapper:
+		return wrapper
 	
 	name_string = class_data.class_name()
 	if name_string == 'NSConcreteData' or \
@@ -97,36 +93,42 @@
 def NSData_SummaryProvider (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 ''
+		try:
+			summary = provider.length();
+		except:
+			summary = None
+		if summary == None:
+			summary = '<variable is not NSData>'
+		elif isinstance(summary,basestring):
+			pass
+		else:
+			if summary == 1:
+				summary = '1 byte'
+			else:
+				summary = str(summary) + ' bytes'
+		return summary
+	return 'Summary Unavailable'
 
 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 ''
+		if isinstance(provider,objc_runtime.SpecialSituation_Description):
+			return provider.message()
+		try:
+			summary = provider.length();
+		except:
+			summary = None
+		if summary == None:
+			summary = '<variable is not CFData>'
+		elif isinstance(summary,basestring):
+			pass
+		else:
+			if summary == 1:
+				summary = '@"1 byte"'
+			else:
+				summary = '@"' + str(summary) + ' bytes"'
+		return summary
+	return 'Summary Unavailable'
 
 def __lldb_init_module(debugger,dict):
 	debugger.HandleCommand("type summary add -F NSData.NSData_SummaryProvider NSData")

Modified: lldb/trunk/examples/summaries/cocoa/NSDate.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/summaries/cocoa/NSDate.py?rev=152673&r1=152672&r2=152673&view=diff
==============================================================================
--- lldb/trunk/examples/summaries/cocoa/NSDate.py (original)
+++ lldb/trunk/examples/summaries/cocoa/NSDate.py Tue Mar 13 16:52:00 2012
@@ -1,3 +1,10 @@
+"""
+LLDB AppKit formatters
+
+part of The LLVM Compiler Infrastructure
+This file is distributed under the University of Illinois Open Source
+License. See LICENSE.TXT for details.
+"""
 # summary provider for NSDate
 import lldb
 import ctypes
@@ -153,26 +160,15 @@
 		self.valobj.GetExpressionPath(stream)
 		expr = "(NSString*)[" + stream.GetData() + " description]"
 		num_children_vo = self.valobj.CreateValueFromExpression("str",expr);
-		return num_children_vo.GetSummary()
+		if num_children_vo.IsValid():
+			return num_children_vo.GetSummary()
+		return '<variable is not NSDate>'
 
 def GetSummary_Impl(valobj):
 	global statistics
-	class_data = objc_runtime.ObjCRuntime(valobj)
-	if class_data.is_valid() == False:
-		statistics.metric_hit('invalid_pointer',valobj)
-		wrapper = None
-		return
-	class_data = class_data.read_class_data()
-	if class_data.is_valid() == False:
-		statistics.metric_hit('invalid_isa',valobj)
-		wrapper = None
-		return
-	if class_data.is_kvo():
-		class_data = class_data.get_superclass()
-	if class_data.is_valid() == False:
-		statistics.metric_hit('invalid_isa',valobj)
-		wrapper = None
-		return
+	class_data,wrapper = objc_runtime.Utilities.prepare_class_detection(valobj,statistics)
+	if wrapper:
+		return wrapper
 	
 	name_string = class_data.class_name()
 	if name_string == 'NSDate' or name_string == '__NSDate' or name_string == '__NSTaggedDate':
@@ -197,26 +193,30 @@
 def NSDate_SummaryProvider (valobj,dict):
 	provider = GetSummary_Impl(valobj);
 	if provider != None:
-	    #try:
-	    summary = provider.value();
-	    #except:
-	    #    summary = None
-	    if summary == None:
-	        summary = 'no valid date here'
-	    return str(summary)
-	return ''
+		if isinstance(provider,objc_runtime.SpecialSituation_Description):
+			return provider.message()
+		try:
+			summary = provider.value();
+		except:
+			summary = None
+		if summary == None:
+			summary = '<variable is not NSDate>'
+		return str(summary)
+	return 'Summary Unavailable'
 
 def NSTimeZone_SummaryProvider (valobj,dict):
 	provider = GetSummary_Impl(valobj);
 	if provider != None:
-	    try:
-	        summary = provider.timezone();
-	    except:
-	        summary = None
-	    if summary == None:
-	        summary = 'no valid timezone here'
-	    return str(summary)
-	return ''
+		if isinstance(provider,objc_runtime.SpecialSituation_Description):
+			return provider.message()
+		try:
+			summary = provider.timezone();
+		except:
+			summary = None
+		if summary == None:
+			summary = '<variable is not NSTimeZone>'
+		return str(summary)
+	return 'Summary Unavailable'
 
 
 def CFAbsoluteTime_SummaryProvider (valobj,dict):
@@ -224,7 +224,7 @@
 		value_double = struct.unpack('d', struct.pack('Q', valobj.GetValueAsUnsigned(0)))[0]
 		return xcode_format_count(osx_to_python_time(value_double))
 	except:
-		return 'unable to provide a summary'
+		return 'Summary Unavailable'
 
 
 def __lldb_init_module(debugger,dict):

Modified: lldb/trunk/examples/summaries/cocoa/NSException.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/summaries/cocoa/NSException.py?rev=152673&r1=152672&r2=152673&view=diff
==============================================================================
--- lldb/trunk/examples/summaries/cocoa/NSException.py (original)
+++ lldb/trunk/examples/summaries/cocoa/NSException.py Tue Mar 13 16:52:00 2012
@@ -1,3 +1,10 @@
+"""
+LLDB AppKit formatters
+
+part of The LLVM Compiler Infrastructure
+This file is distributed under the University of Illinois Open Source
+License. See LICENSE.TXT for details.
+"""
 # summary provider for class NSException
 import objc_runtime
 import metrics
@@ -55,27 +62,16 @@
 		self.valobj.GetExpressionPath(stream)
 		name_vo = self.valobj.CreateValueFromExpression("name","(NSString*)[" + stream.GetData() + " name]");
 		reason_vo = self.valobj.CreateValueFromExpression("reason","(NSString*)[" + stream.GetData() + " reason]");
-		return CFString.CFString_SummaryProvider(name_vo,None) + ' ' + CFString.CFString_SummaryProvider(reason_vo,None)
+		if name_vo.IsValid() and reason_vo.IsValid():
+			return CFString.CFString_SummaryProvider(name_vo,None) + ' ' + CFString.CFString_SummaryProvider(reason_vo,None)
+		return '<variable is not NSException>'
 
 
 def GetSummary_Impl(valobj):
 	global statistics
-	class_data = objc_runtime.ObjCRuntime(valobj)
-	if class_data.is_valid() == False:
-		statistics.metric_hit('invalid_pointer',valobj)
-		wrapper = None
-		return
-	class_data = class_data.read_class_data()
-	if class_data.is_valid() == False:
-		statistics.metric_hit('invalid_isa',valobj)
-		wrapper = None
-		return
-	if class_data.is_kvo():
-		class_data = class_data.get_superclass()
-	if class_data.is_valid() == False:
-		statistics.metric_hit('invalid_isa',valobj)
-		wrapper = None
-		return
+	class_data,wrapper = objc_runtime.Utilities.prepare_class_detection(valobj,statistics)
+	if wrapper:
+		return wrapper
 	
 	name_string = class_data.class_name()
 	if name_string == 'NSException':
@@ -89,14 +85,16 @@
 def NSException_SummaryProvider (valobj,dict):
 	provider = GetSummary_Impl(valobj);
 	if provider != None:
-	    try:
-	        summary = provider.description();
-	    except:
-	        summary = None
-	    if summary == None:
-	        summary = 'no valid exception here'
-	    return str(summary)
-	return ''
+		if isinstance(provider,objc_runtime.SpecialSituation_Description):
+			return provider.message()
+		try:
+			summary = provider.description();
+		except:
+			summary = None
+		if summary == None:
+			summary = '<variable is not NSException>'
+		return str(summary)
+	return 'Summary Unavailable'
 
 def __lldb_init_module(debugger,dict):
 	debugger.HandleCommand("type summary add -F NSException.NSException_SummaryProvider NSException")

Modified: lldb/trunk/examples/summaries/cocoa/NSIndexSet.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/summaries/cocoa/NSIndexSet.py?rev=152673&r1=152672&r2=152673&view=diff
==============================================================================
--- lldb/trunk/examples/summaries/cocoa/NSIndexSet.py (original)
+++ lldb/trunk/examples/summaries/cocoa/NSIndexSet.py Tue Mar 13 16:52:00 2012
@@ -1,3 +1,10 @@
+"""
+LLDB AppKit formatters
+
+part of The LLVM Compiler Infrastructure
+This file is distributed under the University of Illinois Open Source
+License. See LICENSE.TXT for details.
+"""
 # summary provider for NS(Mutable)IndexSet
 import lldb
 import ctypes
@@ -78,28 +85,17 @@
 		stream = lldb.SBStream()
 		self.valobj.GetExpressionPath(stream)
 		expr = "(int)[" + stream.GetData() + " count]"
-		num_children_vo = self.valobj.CreateValueFromExpression("count",expr);
-		return num_children_vo.GetValueAsUnsigned(0)
+		num_children_vo = self.valobj.CreateValueFromExpression("count",expr)
+		if num_children_vo.IsValid():
+			return num_children_vo.GetValueAsUnsigned(0)
+		return '<variable is not NSIndexSet>'
 
 
 def GetSummary_Impl(valobj):
 	global statistics
-	class_data = objc_runtime.ObjCRuntime(valobj)
-	if class_data.is_valid() == False:
-		statistics.metric_hit('invalid_pointer',valobj)
-		wrapper = None
-		return
-	class_data = class_data.read_class_data()
-	if class_data.is_valid() == False:
-		statistics.metric_hit('invalid_isa',valobj)
-		wrapper = None
-		return
-	if class_data.is_kvo():
-		class_data = class_data.get_superclass()
-	if class_data.is_valid() == False:
-		statistics.metric_hit('invalid_isa',valobj)
-		wrapper = None
-		return
+	class_data,wrapper = objc_runtime.Utilities.prepare_class_detection(valobj,statistics)
+	if wrapper:
+		return wrapper
 	
 	name_string = class_data.class_name()
 	if name_string == 'NSIndexSet' or name_string == 'NSMutableIndexSet':
@@ -114,16 +110,20 @@
 def NSIndexSet_SummaryProvider (valobj,dict):
 	provider = GetSummary_Impl(valobj);
 	if provider != None:
+		if isinstance(provider,objc_runtime.SpecialSituation_Description):
+			return provider.message()
 		try:
 			summary = provider.count();
 		except:
 			summary = None
 		if summary == None:
-			summary = 'no valid set here'
+			summary = '<variable is not NSIndexSet>'
+		if isinstance(summary, basestring):
+			return summary
 		else:
-			summary = str(summary) + (' objects' if summary > 1 else ' object')
+			summary = str(summary) + (' objects' if summary != 1 else ' object')
 		return summary
-	return ''
+	return 'Summary Unavailable'
 
 
 def __lldb_init_module(debugger,dict):

Modified: lldb/trunk/examples/summaries/cocoa/NSMachPort.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/summaries/cocoa/NSMachPort.py?rev=152673&r1=152672&r2=152673&view=diff
==============================================================================
--- lldb/trunk/examples/summaries/cocoa/NSMachPort.py (original)
+++ lldb/trunk/examples/summaries/cocoa/NSMachPort.py Tue Mar 13 16:52:00 2012
@@ -1,3 +1,10 @@
+"""
+LLDB AppKit formatters
+
+part of The LLVM Compiler Infrastructure
+This file is distributed under the University of Illinois Open Source
+License. See LICENSE.TXT for details.
+"""
 # summary provider for NSData
 import lldb
 import ctypes
@@ -61,28 +68,17 @@
 	def port(self):
 		stream = lldb.SBStream()
 		self.valobj.GetExpressionPath(stream)
-		num_children_vo = self.valobj.CreateValueFromExpression("port","(int)[" + stream.GetData() + " machPort]");
-		return num_children_vo.GetValueAsUnsigned(0)
+		num_children_vo = self.valobj.CreateValueFromExpression("port","(int)[" + stream.GetData() + " machPort]")
+		if num_children_vo.IsValid():
+			return num_children_vo.GetValueAsUnsigned(0)
+		return '<variable is not NSMachPort>'
 
 
 def GetSummary_Impl(valobj):
 	global statistics
-	class_data = objc_runtime.ObjCRuntime(valobj)
-	if class_data.is_valid() == False:
-		statistics.metric_hit('invalid_pointer',valobj)
-		wrapper = None
-		return
-	class_data = class_data.read_class_data()
-	if class_data.is_valid() == False:
-		statistics.metric_hit('invalid_isa',valobj)
-		wrapper = None
-		return
-	if class_data.is_kvo():
-		class_data = class_data.get_superclass()
-	if class_data.is_valid() == False:
-		statistics.metric_hit('invalid_isa',valobj)
-		wrapper = None
-		return
+	class_data,wrapper = objc_runtime.Utilities.prepare_class_detection(valobj,statistics)
+	if wrapper:
+		return wrapper
 	
 	name_string = class_data.class_name()
 	if name_string == 'NSMachPort':
@@ -96,14 +92,18 @@
 def NSMachPort_SummaryProvider (valobj,dict):
 	provider = GetSummary_Impl(valobj);
 	if provider != None:
-	    try:
-	        summary = provider.port();
-	    except:
-	        summary = None
-	    if summary == None:
-	        summary = 'no valid mach port here'
-	    return 'mach port: ' + str(summary)
-	return ''
+		if isinstance(provider,objc_runtime.SpecialSituation_Description):
+			return provider.message()
+		try:
+			summary = provider.port();
+		except:
+			summary = None
+		if summary == None:
+			summary = '<variable is not NSMachPort>'
+		if isinstance(summary, basestring):
+			return summay
+		return 'mach port: ' + str(summary)
+	return 'Summary Unavailable'
 
 def __lldb_init_module(debugger,dict):
 	debugger.HandleCommand("type summary add -F NSMachPort.NSMachPort_SummaryProvider NSMachPort")

Modified: lldb/trunk/examples/summaries/cocoa/NSNotification.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/summaries/cocoa/NSNotification.py?rev=152673&r1=152672&r2=152673&view=diff
==============================================================================
--- lldb/trunk/examples/summaries/cocoa/NSNotification.py (original)
+++ lldb/trunk/examples/summaries/cocoa/NSNotification.py Tue Mar 13 16:52:00 2012
@@ -1,3 +1,10 @@
+"""
+LLDB AppKit formatters
+
+part of The LLVM Compiler Infrastructure
+This file is distributed under the University of Illinois Open Source
+License. See LICENSE.TXT for details.
+"""
 # summary provider for class NSNotification
 import objc_runtime
 import metrics
@@ -50,28 +57,17 @@
 	def name(self):
 		stream = lldb.SBStream()
 		self.valobj.GetExpressionPath(stream)
-		name_vo = self.valobj.CreateValueFromExpression("name","(NSString*)[" + stream.GetData() + " name]");
-		return CFString.CFString_SummaryProvider(name_vo,None)
+		name_vo = self.valobj.CreateValueFromExpression("name","(NSString*)[" + stream.GetData() + " name]")
+		if name_vo.IsValid():
+			return CFString.CFString_SummaryProvider(name_vo,None)
+		return '<variable is not NSNotification>'
 
 
 def GetSummary_Impl(valobj):
 	global statistics
-	class_data = objc_runtime.ObjCRuntime(valobj)
-	if class_data.is_valid() == False:
-		statistics.metric_hit('invalid_pointer',valobj)
-		wrapper = None
-		return
-	class_data = class_data.read_class_data()
-	if class_data.is_valid() == False:
-		statistics.metric_hit('invalid_isa',valobj)
-		wrapper = None
-		return
-	if class_data.is_kvo():
-		class_data = class_data.get_superclass()
-	if class_data.is_valid() == False:
-		statistics.metric_hit('invalid_isa',valobj)
-		wrapper = None
-		return
+	class_data,wrapper = objc_runtime.Utilities.prepare_class_detection(valobj,statistics)
+	if wrapper:
+		return wrapper
 	
 	name_string = class_data.class_name()
 	if name_string == 'NSConcreteNotification':
@@ -85,14 +81,16 @@
 def NSNotification_SummaryProvider (valobj,dict):
 	provider = GetSummary_Impl(valobj);
 	if provider != None:
-	    try:
-	        summary = provider.name();
-	    except:
-	        summary = None
-	    if summary == None:
-	        summary = 'no valid notification here'
-	    return str(summary)
-	return ''
+		if isinstance(provider,objc_runtime.SpecialSituation_Description):
+			return provider.message()
+		try:
+			summary = provider.name();
+		except:
+			summary = None
+		if summary == None:
+			summary = '<variable is not NSNotification>'
+		return str(summary)
+	return 'Summary Unavailable'
 
 def __lldb_init_module(debugger,dict):
 	debugger.HandleCommand("type summary add -F NSNotification.NSNotification_SummaryProvider NSNotification")

Modified: lldb/trunk/examples/summaries/cocoa/NSNumber.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/summaries/cocoa/NSNumber.py?rev=152673&r1=152672&r2=152673&view=diff
==============================================================================
--- lldb/trunk/examples/summaries/cocoa/NSNumber.py (original)
+++ lldb/trunk/examples/summaries/cocoa/NSNumber.py Tue Mar 13 16:52:00 2012
@@ -1,3 +1,10 @@
+"""
+LLDB AppKit formatters
+
+part of The LLVM Compiler Infrastructure
+This file is distributed under the University of Illinois Open Source
+License. See LICENSE.TXT for details.
+"""
 # summary provider for NSNumber
 import lldb
 import ctypes
@@ -162,27 +169,16 @@
 		stream = lldb.SBStream()
 		self.valobj.GetExpressionPath(stream)
 		expr = "(NSString*)[" + stream.GetData() + " stringValue]"
-		num_children_vo = self.valobj.CreateValueFromExpression("str",expr);
-		return num_children_vo.GetSummary()
+		num_children_vo = self.valobj.CreateValueFromExpression("str",expr)
+		if num_children_vo.IsValid():
+			return num_children_vo.GetSummary()
+		return '<variable is not NSNumber>'
 
 def GetSummary_Impl(valobj):
 	global statistics
-	class_data = objc_runtime.ObjCRuntime(valobj)
-	if class_data.is_valid() == False:
-		statistics.metric_hit('invalid_pointer',valobj)
-		wrapper = None
-		return
-	class_data = class_data.read_class_data()
-	if class_data.is_valid() == False:
-		statistics.metric_hit('invalid_isa',valobj)
-		wrapper = None
-		return
-	if class_data.is_kvo():
-		class_data = class_data.get_superclass()
-	if class_data.is_valid() == False:
-		statistics.metric_hit('invalid_isa',valobj)
-		wrapper = None
-		return
+	class_data,wrapper = objc_runtime.Utilities.prepare_class_detection(valobj,statistics)
+	if wrapper:
+		return wrapper
 	
 	name_string = class_data.class_name()
 	if name_string == 'NSNumber' or name_string == '__NSCFNumber':
@@ -202,16 +198,20 @@
 def NSNumber_SummaryProvider (valobj,dict):
 	provider = GetSummary_Impl(valobj);
 	if provider != None:
-	    #try:
-	    summary = provider.value();
-	    #except:
-	    #    summary = None
-	    if summary == None:
-	        summary = 'no valid number here'
-	    return str(summary)
-	return ''
+		if isinstance(provider,objc_runtime.SpecialSituation_Description):
+			return provider.message()
+		try:
+			summary = provider.value();
+		except:
+			summary = None
+		if summary == None:
+			summary = '<variable is not NSNumber>'
+		return str(summary)
+	return 'Summary Unavailable'
 
 
 def __lldb_init_module(debugger,dict):
 	debugger.HandleCommand("type summary add -F NSNumber.NSNumber_SummaryProvider NSNumber")
+	debugger.HandleCommand("type summary add -F NSNumber.NSNumber_SummaryProvider __NSCFBoolean")
+	debugger.HandleCommand("type summary add -F NSNumber.NSNumber_SummaryProvider __NSCFNumber")
 

Modified: lldb/trunk/examples/summaries/cocoa/NSSet.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/summaries/cocoa/NSSet.py?rev=152673&r1=152672&r2=152673&view=diff
==============================================================================
--- lldb/trunk/examples/summaries/cocoa/NSSet.py (original)
+++ lldb/trunk/examples/summaries/cocoa/NSSet.py Tue Mar 13 16:52:00 2012
@@ -1,3 +1,10 @@
+"""
+LLDB AppKit formatters
+
+part of The LLVM Compiler Infrastructure
+This file is distributed under the University of Illinois Open Source
+License. See LICENSE.TXT for details.
+"""
 # summary provider for NSSet
 import lldb
 import ctypes
@@ -63,8 +70,10 @@
 		stream = lldb.SBStream()
 		self.valobj.GetExpressionPath(stream)
 		expr = "(int)[" + stream.GetData() + " count]"
-		num_children_vo = self.valobj.CreateValueFromExpression("count",expr);
-		return num_children_vo.GetValueAsUnsigned(0)
+		num_children_vo = self.valobj.CreateValueFromExpression("count",expr)
+		if num_children_vo.IsValid():
+			return num_children_vo.GetValueAsUnsigned(0)
+		return '<variable is not NSSet>'
 
 class NSSetI_SummaryProvider:
 	def adjust_for_architecture(self):
@@ -158,22 +167,9 @@
 
 def GetSummary_Impl(valobj):
 	global statistics
-	class_data = objc_runtime.ObjCRuntime(valobj)
-	if class_data.is_valid() == False:
-		statistics.metric_hit('invalid_pointer',valobj)
-		wrapper = None
-		return
-	class_data = class_data.read_class_data()
-	if class_data.is_valid() == False:
-		statistics.metric_hit('invalid_isa',valobj)
-		wrapper = None
-		return
-	if class_data.is_kvo():
-		class_data = class_data.get_superclass()
-	if class_data.is_valid() == False:
-		statistics.metric_hit('invalid_isa',valobj)
-		wrapper = None
-		return
+	class_data,wrapper = objc_runtime.Utilities.prepare_class_detection(valobj,statistics)
+	if wrapper:
+		return wrapper
 	
 	name_string = class_data.class_name()
 	if name_string == '__NSCFSet':
@@ -197,20 +193,24 @@
 def NSSet_SummaryProvider (valobj,dict):
 	provider = GetSummary_Impl(valobj);
 	if provider != None:
-	    #try:
-	    summary = provider.count();
-	    #except:
-	    #    summary = None
-	    if summary == None:
-	        summary = 'no valid set here'
-	    else:
-	        summary = str(summary) + (' objects' if summary > 1 else ' object')
-	    return summary
-	return ''
+		try:
+			summary = provider.count();
+		except:
+			summary = None
+		if summary == None:
+			summary = '<variable is not NSSet>'
+		if isinstance(summary, basestring):
+			return summary
+		else:
+			summary = str(summary) + (' objects' if summary != 1 else ' object')
+		return summary
+	return 'Summary Unavailable'
 
 def NSSet_SummaryProvider2 (valobj,dict):
 	provider = GetSummary_Impl(valobj);
 	if provider != None:
+		if isinstance(provider,objc_runtime.SpecialSituation_Description):
+			return provider.message()
 		try:
 			summary = provider.count();
 		except:
@@ -221,13 +221,15 @@
 		# experimentation (if counts start looking weird, then most probably
 		#                  the mask needs to be changed)
 		if summary == None:
-			summary = 'no valid set here'
+			summary = '<variable is not CFSet>'
+		if isinstance(summary, basestring):
+			return summary
 		else:
 			if provider.sys_params.is_64_bit:
 				summary = summary & ~0x1fff000000000000
-		 	summary = '@"' + str(summary) + (' values"' if summary > 1 else ' value"')
+		 	summary = '@"' + str(summary) + (' values"' if summary != 1 else ' value"')
 		return summary
-	return ''
+	return 'Summary Unavailable'
 
 
 def __lldb_init_module(debugger,dict):

Modified: lldb/trunk/examples/summaries/cocoa/NSURL.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/summaries/cocoa/NSURL.py?rev=152673&r1=152672&r2=152673&view=diff
==============================================================================
--- lldb/trunk/examples/summaries/cocoa/NSURL.py (original)
+++ lldb/trunk/examples/summaries/cocoa/NSURL.py Tue Mar 13 16:52:00 2012
@@ -1,3 +1,10 @@
+"""
+LLDB AppKit formatters
+
+part of The LLVM Compiler Infrastructure
+This file is distributed under the University of Illinois Open Source
+License. See LICENSE.TXT for details.
+"""
 # summary provider for NSURL
 import lldb
 import ctypes
@@ -74,28 +81,17 @@
 	def url_text(self):
 		stream = lldb.SBStream()
 		self.valobj.GetExpressionPath(stream)
-		url_text_vo = self.valobj.CreateValueFromExpression("url","(NSString*)[" + stream.GetData() + " description]");
-		return CFString.CFString_SummaryProvider(url_text_vo,None)
+		url_text_vo = self.valobj.CreateValueFromExpression("url","(NSString*)[" + stream.GetData() + " description]")
+		if url_text_vo.IsValid():
+			return CFString.CFString_SummaryProvider(url_text_vo,None)
+		return '<variable is not NSURL>'
 
 
 def GetSummary_Impl(valobj):
 	global statistics
-	class_data = objc_runtime.ObjCRuntime(valobj)
-	if class_data.is_valid() == False:
-		statistics.metric_hit('invalid_pointer',valobj)
-		wrapper = None
-		return
-	class_data = class_data.read_class_data()
-	if class_data.is_valid() == False:
-		statistics.metric_hit('invalid_isa',valobj)
-		wrapper = None
-		return
-	if class_data.is_kvo():
-		class_data = class_data.get_superclass()
-	if class_data.is_valid() == False:
-		statistics.metric_hit('invalid_isa',valobj)
-		wrapper = None
-		return
+	class_data,wrapper = objc_runtime.Utilities.prepare_class_detection(valobj,statistics)
+	if wrapper:
+		return wrapper
 	
 	name_string = class_data.class_name()
 	if name_string == 'NSURL':
@@ -109,14 +105,16 @@
 def NSURL_SummaryProvider (valobj,dict):
 	provider = GetSummary_Impl(valobj);
 	if provider != None:
-	    try:
-	        summary = provider.url_text();
-	    except:
-	        summary = None
-	    if summary == None or summary == '':
-	        summary = 'no valid NSURL here'
-	    return summary
-	return ''
+		if isinstance(provider,objc_runtime.SpecialSituation_Description):
+			return provider.message()
+		try:
+			summary = provider.url_text();
+		except:
+			summary = None
+		if summary == None or summary == '':
+			summary = '<variable is not NSURL>'
+		return summary
+	return 'Summary Unavailable'
 
 def __lldb_init_module(debugger,dict):
 	debugger.HandleCommand("type summary add -F NSURL.NSURL_SummaryProvider NSURL CFURLRef")

Modified: lldb/trunk/examples/summaries/cocoa/Selector.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/summaries/cocoa/Selector.py?rev=152673&r1=152672&r2=152673&view=diff
==============================================================================
--- lldb/trunk/examples/summaries/cocoa/Selector.py (original)
+++ lldb/trunk/examples/summaries/cocoa/Selector.py Tue Mar 13 16:52:00 2012
@@ -1,3 +1,10 @@
+"""
+LLDB AppKit formatters
+
+part of The LLVM Compiler Infrastructure
+This file is distributed under the University of Illinois Open Source
+License. See LICENSE.TXT for details.
+"""
 import lldb
 
 def SEL_Summary(valobj,dict):

Modified: lldb/trunk/examples/summaries/cocoa/attrib_fromdict.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/summaries/cocoa/attrib_fromdict.py?rev=152673&r1=152672&r2=152673&view=diff
==============================================================================
--- lldb/trunk/examples/summaries/cocoa/attrib_fromdict.py (original)
+++ lldb/trunk/examples/summaries/cocoa/attrib_fromdict.py Tue Mar 13 16:52:00 2012
@@ -1,3 +1,10 @@
+"""
+Objective-C runtime wrapper for use by LLDB Python formatters
+
+part of The LLVM Compiler Infrastructure
+This file is distributed under the University of Illinois Open Source
+License. See LICENSE.TXT for details.
+"""
 class AttributesDictionary:
 	def __init__(self, allow_reset = True):
 		self.__dict__['_dictionary'] = {} # need to do it this way to prevent endless recursion

Modified: lldb/trunk/examples/summaries/cocoa/cache.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/summaries/cocoa/cache.py?rev=152673&r1=152672&r2=152673&view=diff
==============================================================================
--- lldb/trunk/examples/summaries/cocoa/cache.py (original)
+++ lldb/trunk/examples/summaries/cocoa/cache.py Tue Mar 13 16:52:00 2012
@@ -1,3 +1,10 @@
+"""
+Objective-C runtime wrapper for use by LLDB Python formatters
+
+part of The LLVM Compiler Infrastructure
+This file is distributed under the University of Illinois Open Source
+License. See LICENSE.TXT for details.
+"""
 import metrics
 
 class Cache:

Modified: lldb/trunk/examples/summaries/cocoa/metrics.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/summaries/cocoa/metrics.py?rev=152673&r1=152672&r2=152673&view=diff
==============================================================================
--- lldb/trunk/examples/summaries/cocoa/metrics.py (original)
+++ lldb/trunk/examples/summaries/cocoa/metrics.py Tue Mar 13 16:52:00 2012
@@ -1,3 +1,10 @@
+"""
+Objective-C runtime wrapper for use by LLDB Python formatters
+
+part of The LLVM Compiler Infrastructure
+This file is distributed under the University of Illinois Open Source
+License. See LICENSE.TXT for details.
+"""
 import lldb
 
 class Counter:

Modified: lldb/trunk/examples/summaries/cocoa/objc_runtime.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/summaries/cocoa/objc_runtime.py?rev=152673&r1=152672&r2=152673&view=diff
==============================================================================
--- lldb/trunk/examples/summaries/cocoa/objc_runtime.py (original)
+++ lldb/trunk/examples/summaries/cocoa/objc_runtime.py Tue Mar 13 16:52:00 2012
@@ -74,6 +74,30 @@
 			return None
 		return (ver[0] < 900)
 
+	# a utility method that factors out code common to almost all the formatters
+	# takes in an SBValue and a metrics object
+	# returns a class_data and a wrapper (or None, if the runtime alone can't decide on a wrapper)
+	@staticmethod
+	def prepare_class_detection(valobj,statistics):
+		class_data = ObjCRuntime(valobj)
+		if class_data.is_valid() == False:
+			statistics.metric_hit('invalid_pointer',valobj)
+			wrapper = InvalidPointer_Description(valobj.GetValueAsUnsigned(0) == 0)
+			return class_data,wrapper
+		class_data = class_data.read_class_data()
+		if class_data.is_valid() == False:
+			statistics.metric_hit('invalid_isa',valobj)
+			wrapper = InvalidISA_Description()
+			return class_data,wrapper
+		if class_data.is_kvo():
+			class_data = class_data.get_superclass()
+		if class_data.is_valid() == False:
+			statistics.metric_hit('invalid_isa',valobj)
+			wrapper = InvalidISA_Description()
+			return class_data,wrapper
+		return class_data,None
+
+
 class RoT_Data:
 	def __init__(self,rot_pointer,params):
 		if (Utilities.is_valid_pointer(rot_pointer.GetValueAsUnsigned(),params.pointer_size, allow_tagged=False)):
@@ -227,7 +251,7 @@
 	#                      just to be on the safe side)
 	def is_cftype(self):
 		if self.is_valid():
-			return self.name == '__NSCFType' or self.name == 'NSCFType'
+			return self.class_name() == '__NSCFType' or self.class_name() == 'NSCFType'
 
 	def get_superclass(self):
 		if self.is_valid():
@@ -314,7 +338,7 @@
 	#                      just to be on the safe side)
 	def is_cftype(self):
 		if self.is_valid():
-			return self.name == '__NSCFType' or self.name == 'NSCFType'
+			return self.class_name() == '__NSCFType' or self.class_name() == 'NSCFType'
 
 	def get_superclass(self):
 		if self.is_valid():
@@ -593,6 +617,9 @@
 			return False
 		return Utilities.is_valid_pointer(self.unsigned_value,self.sys_params.pointer_size, allow_tagged=True)
 
+	def is_nil(self):
+		return self.unsigned_value == 0
+
 	def read_isa(self):
 		if self.isa_value != None:
 			return self.isa_value
@@ -639,3 +666,27 @@
 			self.sys_params.isa_cache.add_item(isa_value,data,ok_to_replace=True)
 		return data
 
+# these classes below can be used by the data formatters to provide a consistent message that describes a given runtime-generated situation
+class SpecialSituation_Description:
+	def message(self):
+		return ''
+
+class InvalidPointer_Description(SpecialSituation_Description):
+
+	def __init__(self,nil):
+		self.is_nil = nil
+
+	def message(self):
+		if self.is_nil:
+			return '@"<nil>"'
+		else:
+			return '<invalid pointer>'
+
+class InvalidISA_Description(SpecialSituation_Description):
+
+	def __init__(self):
+		pass
+
+	def message(self):
+		return '<not an Objective-C object>'
+

Modified: lldb/trunk/source/Core/FormatManager.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/FormatManager.cpp?rev=152673&r1=152672&r2=152673&view=diff
==============================================================================
--- lldb/trunk/source/Core/FormatManager.cpp (original)
+++ lldb/trunk/source/Core/FormatManager.cpp Tue Mar 13 16:52:00 2012
@@ -914,6 +914,8 @@
     AddScriptSummary(appkit_category_sp, "NSNotification.NSNotification_SummaryProvider", ConstString("NSNotification"), appkit_flags);
     
     AddScriptSummary(appkit_category_sp, "NSNumber.NSNumber_SummaryProvider", ConstString("NSNumber"), appkit_flags);
+    AddScriptSummary(appkit_category_sp, "NSNumber.NSNumber_SummaryProvider", ConstString("__NSCFBoolean"), appkit_flags);
+    AddScriptSummary(appkit_category_sp, "NSNumber.NSNumber_SummaryProvider", ConstString("__NSCFNumber"), appkit_flags);
 
     AddScriptSummary(appkit_category_sp, "NSSet.NSSet_SummaryProvider", ConstString("NSSet"), appkit_flags);
     AddScriptSummary(appkit_category_sp, "NSSet.NSSet_SummaryProvider2", ConstString("CFSetRef"), appkit_flags);





More information about the lldb-commits mailing list