summaryrefslogtreecommitdiff
path: root/examples/summaries/cocoa/NSDate.py
diff options
context:
space:
mode:
authorEnrico Granata <egranata@apple.com>2012-03-01 19:32:33 +0000
committerEnrico Granata <egranata@apple.com>2012-03-01 19:32:33 +0000
commit83410e5e9e040ea5c6691f933aa9a6c4dcea4d8b (patch)
treed3d4383d2848ccec3f441bfe3c7d05b62ddad750 /examples/summaries/cocoa/NSDate.py
parent77ce90bc96f26ee707ae3ef3ba62099a7c3dc8fd (diff)
(a) adding an introspection formatter for NS(Mutable)IndexSet
(b) fixes and improvements to the formatters for NSDate and NSString (c) adding an introspection formatter for NSCountedSet (d) making the Objective-C formatters test cases pass on both 64 and 32 bit one of the test cases is marked as expected failure on i386 - support needs to be added to the LLDB core for it to pass git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@151826 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'examples/summaries/cocoa/NSDate.py')
-rw-r--r--examples/summaries/cocoa/NSDate.py60
1 files changed, 53 insertions, 7 deletions
diff --git a/examples/summaries/cocoa/NSDate.py b/examples/summaries/cocoa/NSDate.py
index aa059e2e7..df493cbc0 100644
--- a/examples/summaries/cocoa/NSDate.py
+++ b/examples/summaries/cocoa/NSDate.py
@@ -25,14 +25,14 @@ def mkgmtime(t):
osx_epoch = mkgmtime(osx_epoch)
def osx_to_python_time(osx):
- if python_epoch <= 2011:
+ if python_epoch <= 2001:
return osx + osx_epoch
else:
return osx - osx_epoch
# despite the similary to synthetic children providers, these classes are not
-# trying to provide anything but the port number of an NSDate, so they need not
+# trying to provide anything but the summary for NSDate, so they need not
# obey the interface specification for synthetic children providers
class NSTaggedDate_SummaryProvider:
def adjust_for_architecture(self):
@@ -43,8 +43,9 @@ class NSTaggedDate_SummaryProvider:
def __init__(self, valobj, info_bits, data):
self.valobj = valobj;
self.update();
- self.info_bits = info_bits
- self.data = data
+ # NSDate is not using its info_bits for info like NSNumber is
+ # so we need to regroup info_bits and data
+ self.data = ((data << 8) | (info_bits << 4))
def update(self):
self.adjust_for_architecture();
@@ -63,10 +64,12 @@ class NSTaggedDate_SummaryProvider:
def value(self):
# the value of the date-time object is wrapped into the pointer value
- # unfortunately, it is made as a time-delta after Jan 1 2011 midnight GMT
+ # unfortunately, it is made as a time-delta after Jan 1 2001 midnight GMT
# 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
- return time.ctime(osx_to_python_time(self.data))
+ print hex(self.data)
+ value_double = struct.unpack('d', struct.pack('Q', self.data))[0]
+ return time.ctime(osx_to_python_time(value_double))
class NSUntaggedDate_SummaryProvider:
@@ -99,6 +102,37 @@ class NSUntaggedDate_SummaryProvider:
value_double = struct.unpack('d', struct.pack('Q', value.GetValueAsUnsigned(0)))[0]
return time.ctime(osx_to_python_time(value_double))
+class NSCalendarDate_SummaryProvider:
+ def adjust_for_architecture(self):
+ self.is_64_bit = (self.valobj.GetTarget().GetProcess().GetAddressByteSize() == 8)
+ self.is_little = (self.valobj.GetTarget().GetProcess().GetByteOrder() == lldb.eByteOrderLittle)
+ self.pointer_size = self.valobj.GetTarget().GetProcess().GetAddressByteSize()
+
+ def __init__(self, valobj):
+ self.valobj = valobj;
+ self.update()
+
+ def update(self):
+ self.adjust_for_architecture();
+ self.id_type = self.valobj.GetType().GetBasicType(lldb.eBasicTypeObjCID)
+ self.NSUInteger = self.valobj.GetType().GetBasicType(lldb.eBasicTypeUnsignedLong)
+ self.double = self.valobj.GetType().GetBasicType(lldb.eBasicTypeDouble)
+
+ def offset(self):
+ if self.is_64_bit:
+ return 16
+ else:
+ return 8
+
+
+ def value(self):
+ value = self.valobj.CreateChildAtOffset("value",
+ self.offset(),
+ self.double)
+ value_double = struct.unpack('d', struct.pack('Q', value.GetValueAsUnsigned(0)))[0]
+ return time.ctime(osx_to_python_time(value_double))
+
+
class NSUnknownDate_SummaryProvider:
def adjust_for_architecture(self):
self.is_64_bit = (self.valobj.GetTarget().GetProcess().GetAddressByteSize() == 8)
@@ -147,7 +181,11 @@ def GetSummary_Impl(valobj):
else:
wrapper = NSUntaggedDate_SummaryProvider(valobj)
statistics.metric_hit('code_notrun',valobj)
+ elif name_string == 'NSCalendarDate':
+ wrapper = NSCalendarDate_SummaryProvider(valobj)
+ statistics.metric_hit('code_notrun',valobj)
else:
+ print name_string # comment this out in release mode
wrapper = NSUnknownDate_SummaryProvider(valobj)
statistics.metric_hit('unknown_class',str(valobj) + " seen as " + name_string)
return wrapper;
@@ -161,11 +199,19 @@ def NSDate_SummaryProvider (valobj,dict):
#except:
# summary = None
if summary == None:
- summary = 'no valid number here'
+ summary = 'no valid date here'
return str(summary)
return ''
+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))
+ except:
+ return 'unable to provide a summary'
+
def __lldb_init_module(debugger,dict):
debugger.HandleCommand("type summary add -F NSDate.NSDate_SummaryProvider NSDate")
+ debugger.HandleCommand("type summary add -F NSDate.CFAbsoluteTime_SummaryProvider CFAbsoluteTime")