2012-03-14 05:52:00 +08:00
|
|
|
"""
|
|
|
|
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.
|
|
|
|
"""
|
2012-02-24 07:10:27 +08:00
|
|
|
# summary provider for NSNumber
|
|
|
|
import lldb
|
|
|
|
import ctypes
|
2012-04-25 09:39:27 +08:00
|
|
|
import lldb.runtime.objc.objc_runtime
|
|
|
|
import lldb.formatters.metrics
|
2012-02-24 07:10:27 +08:00
|
|
|
import struct
|
2012-04-25 09:39:27 +08:00
|
|
|
import lldb.formatters.Logger
|
2012-02-24 07:10:27 +08:00
|
|
|
|
2012-04-25 09:39:27 +08:00
|
|
|
statistics = lldb.formatters.metrics.Metrics()
|
2012-02-24 07:10:27 +08:00
|
|
|
statistics.add_metric('invalid_isa')
|
|
|
|
statistics.add_metric('invalid_pointer')
|
|
|
|
statistics.add_metric('unknown_class')
|
|
|
|
statistics.add_metric('code_notrun')
|
|
|
|
|
|
|
|
# despite the similary to synthetic children providers, these classes are not
|
|
|
|
# trying to provide anything but the port number of an NSNumber, so they need not
|
|
|
|
# obey the interface specification for synthetic children providers
|
|
|
|
class NSTaggedNumber_SummaryProvider:
|
|
|
|
def adjust_for_architecture(self):
|
2012-03-06 03:56:33 +08:00
|
|
|
pass
|
2012-02-24 07:10:27 +08:00
|
|
|
|
2012-03-06 03:56:33 +08:00
|
|
|
def __init__(self, valobj, info_bits, data, params):
|
2012-04-25 09:39:27 +08:00
|
|
|
logger = lldb.formatters.Logger.Logger()
|
2012-02-24 07:10:27 +08:00
|
|
|
self.valobj = valobj;
|
2012-03-06 03:56:33 +08:00
|
|
|
self.sys_params = params
|
2012-02-24 07:10:27 +08:00
|
|
|
self.info_bits = info_bits
|
|
|
|
self.data = data
|
2012-03-06 03:56:33 +08:00
|
|
|
self.update();
|
2012-02-24 07:10:27 +08:00
|
|
|
|
|
|
|
def update(self):
|
2012-04-25 09:39:27 +08:00
|
|
|
logger = lldb.formatters.Logger.Logger()
|
2012-02-24 07:10:27 +08:00
|
|
|
self.adjust_for_architecture();
|
|
|
|
|
|
|
|
def value(self):
|
2012-04-25 09:39:27 +08:00
|
|
|
logger = lldb.formatters.Logger.Logger()
|
2012-02-24 07:10:27 +08:00
|
|
|
# in spite of the plenty of types made available by the public NSNumber API
|
|
|
|
# only a bunch of these are actually used in the internal implementation
|
|
|
|
# unfortunately, the original type information appears to be lost
|
|
|
|
# so we try to at least recover the proper magnitude of the data
|
|
|
|
if self.info_bits == 0:
|
|
|
|
return '(char)' + str(self.data % 256)
|
|
|
|
if self.info_bits == 4:
|
|
|
|
return '(short)' + str(self.data % (256*256))
|
|
|
|
if self.info_bits == 8:
|
|
|
|
return '(int)' + str(self.data % (256*256*256*256))
|
|
|
|
if self.info_bits == 12:
|
|
|
|
return '(long)' + str(self.data)
|
|
|
|
else:
|
|
|
|
return 'absurd value:(info=' + str(self.info_bits) + ", value = " + str(self.data) + ')'
|
|
|
|
|
|
|
|
|
|
|
|
class NSUntaggedNumber_SummaryProvider:
|
|
|
|
def adjust_for_architecture(self):
|
2012-03-06 03:56:33 +08:00
|
|
|
pass
|
2012-02-24 07:10:27 +08:00
|
|
|
|
2012-03-06 03:56:33 +08:00
|
|
|
def __init__(self, valobj, params):
|
2012-04-25 09:39:27 +08:00
|
|
|
logger = lldb.formatters.Logger.Logger()
|
2012-02-24 07:10:27 +08:00
|
|
|
self.valobj = valobj;
|
2012-03-06 03:56:33 +08:00
|
|
|
self.sys_params = params
|
|
|
|
if not(self.sys_params.types_cache.char):
|
|
|
|
self.sys_params.types_cache.char = self.valobj.GetType().GetBasicType(lldb.eBasicTypeChar)
|
|
|
|
if not(self.sys_params.types_cache.short):
|
|
|
|
self.sys_params.types_cache.short = self.valobj.GetType().GetBasicType(lldb.eBasicTypeShort)
|
|
|
|
if not(self.sys_params.types_cache.ushort):
|
|
|
|
self.sys_params.types_cache.ushort = self.valobj.GetType().GetBasicType(lldb.eBasicTypeUnsignedShort)
|
|
|
|
if not(self.sys_params.types_cache.int):
|
|
|
|
self.sys_params.types_cache.int = self.valobj.GetType().GetBasicType(lldb.eBasicTypeInt)
|
|
|
|
if not(self.sys_params.types_cache.long):
|
|
|
|
self.sys_params.types_cache.long = self.valobj.GetType().GetBasicType(lldb.eBasicTypeLong)
|
|
|
|
if not(self.sys_params.types_cache.ulong):
|
|
|
|
self.sys_params.types_cache.ulong = self.valobj.GetType().GetBasicType(lldb.eBasicTypeUnsignedLong)
|
|
|
|
if not(self.sys_params.types_cache.longlong):
|
|
|
|
self.sys_params.types_cache.longlong = self.valobj.GetType().GetBasicType(lldb.eBasicTypeLongLong)
|
|
|
|
if not(self.sys_params.types_cache.ulonglong):
|
|
|
|
self.sys_params.types_cache.ulonglong = self.valobj.GetType().GetBasicType(lldb.eBasicTypeUnsignedLongLong)
|
|
|
|
if not(self.sys_params.types_cache.float):
|
|
|
|
self.sys_params.types_cache.float = self.valobj.GetType().GetBasicType(lldb.eBasicTypeFloat)
|
|
|
|
if not(self.sys_params.types_cache.double):
|
|
|
|
self.sys_params.types_cache.double = self.valobj.GetType().GetBasicType(lldb.eBasicTypeDouble)
|
|
|
|
self.update();
|
2012-02-24 07:10:27 +08:00
|
|
|
|
|
|
|
def update(self):
|
2012-04-25 09:39:27 +08:00
|
|
|
logger = lldb.formatters.Logger.Logger()
|
2012-02-24 07:10:27 +08:00
|
|
|
self.adjust_for_architecture();
|
|
|
|
|
|
|
|
def value(self):
|
2012-04-25 09:39:27 +08:00
|
|
|
logger = lldb.formatters.Logger.Logger()
|
2012-02-24 07:10:27 +08:00
|
|
|
global statistics
|
|
|
|
# we need to skip the ISA, then the next byte tells us what to read
|
|
|
|
# we then skip one other full pointer worth of data and then fetch the contents
|
|
|
|
# if we are fetching an int64 value, one more pointer must be skipped to get at our data
|
|
|
|
data_type_vo = self.valobj.CreateChildAtOffset("dt",
|
2012-03-06 03:56:33 +08:00
|
|
|
self.sys_params.pointer_size,
|
|
|
|
self.sys_params.types_cache.char)
|
2012-02-24 07:10:27 +08:00
|
|
|
data_type = ((data_type_vo.GetValueAsUnsigned(0) % 256) & 0x1F)
|
2012-03-06 03:56:33 +08:00
|
|
|
data_offset = 2 * self.sys_params.pointer_size
|
2012-02-24 07:10:27 +08:00
|
|
|
if data_type == 0B00001:
|
|
|
|
data_vo = self.valobj.CreateChildAtOffset("data",
|
|
|
|
data_offset,
|
2012-03-06 03:56:33 +08:00
|
|
|
self.sys_params.types_cache.char)
|
2012-02-24 07:10:27 +08:00
|
|
|
statistics.metric_hit('code_notrun',self.valobj)
|
|
|
|
return '(char)' + str(data_vo.GetValueAsUnsigned(0))
|
|
|
|
elif data_type == 0B0010:
|
|
|
|
data_vo = self.valobj.CreateChildAtOffset("data",
|
|
|
|
data_offset,
|
2012-03-06 03:56:33 +08:00
|
|
|
self.sys_params.types_cache.short)
|
2012-02-24 07:10:27 +08:00
|
|
|
statistics.metric_hit('code_notrun',self.valobj)
|
|
|
|
return '(short)' + str(data_vo.GetValueAsUnsigned(0) % (256*256))
|
|
|
|
# IF tagged pointers are possible on 32bit+v2 runtime
|
|
|
|
# (of which the only existing instance should be iOS)
|
|
|
|
# then values of this type might be tagged
|
|
|
|
elif data_type == 0B0011:
|
|
|
|
data_vo = self.valobj.CreateChildAtOffset("data",
|
|
|
|
data_offset,
|
2012-03-06 03:56:33 +08:00
|
|
|
self.sys_params.types_cache.int)
|
2012-02-24 07:10:27 +08:00
|
|
|
statistics.metric_hit('code_notrun',self.valobj)
|
|
|
|
return '(int)' + str(data_vo.GetValueAsUnsigned(0) % (256*256*256*256))
|
2012-02-29 11:28:49 +08:00
|
|
|
# apparently, on is_64_bit architectures, these are the only values that will ever
|
2012-02-24 07:10:27 +08:00
|
|
|
# be represented by a non tagged pointers
|
2012-03-02 03:32:33 +08:00
|
|
|
elif data_type == 0B10001:
|
|
|
|
data_offset = data_offset + 8 # 8 is needed even if we are on 32bit
|
|
|
|
data_vo = self.valobj.CreateChildAtOffset("data",
|
|
|
|
data_offset,
|
2012-03-06 03:56:33 +08:00
|
|
|
self.sys_params.types_cache.longlong)
|
2012-03-02 03:32:33 +08:00
|
|
|
statistics.metric_hit('code_notrun',self.valobj)
|
|
|
|
return '(long)' + str(data_vo.GetValueAsUnsigned(0))
|
|
|
|
elif data_type == 0B0100:
|
2012-03-06 03:56:33 +08:00
|
|
|
if self.sys_params.is_64_bit:
|
|
|
|
data_offset = data_offset + self.sys_params.pointer_size
|
2012-02-24 07:10:27 +08:00
|
|
|
data_vo = self.valobj.CreateChildAtOffset("data",
|
|
|
|
data_offset,
|
2012-03-06 03:56:33 +08:00
|
|
|
self.sys_params.types_cache.longlong)
|
2012-02-24 07:10:27 +08:00
|
|
|
statistics.metric_hit('code_notrun',self.valobj)
|
|
|
|
return '(long)' + str(data_vo.GetValueAsUnsigned(0))
|
|
|
|
elif data_type == 0B0101:
|
|
|
|
data_vo = self.valobj.CreateChildAtOffset("data",
|
|
|
|
data_offset,
|
2012-03-06 03:56:33 +08:00
|
|
|
self.sys_params.types_cache.longlong)
|
2012-02-24 07:10:27 +08:00
|
|
|
data_plain = int(str(data_vo.GetValueAsUnsigned(0) & 0x00000000FFFFFFFF))
|
|
|
|
packed = struct.pack('I', data_plain)
|
|
|
|
data_float = struct.unpack('f', packed)[0]
|
|
|
|
statistics.metric_hit('code_notrun',self.valobj)
|
|
|
|
return '(float)' + str(data_float)
|
|
|
|
elif data_type == 0B0110:
|
|
|
|
data_vo = self.valobj.CreateChildAtOffset("data",
|
|
|
|
data_offset,
|
2012-03-06 03:56:33 +08:00
|
|
|
self.sys_params.types_cache.longlong)
|
2012-02-24 07:10:27 +08:00
|
|
|
data_plain = data_vo.GetValueAsUnsigned(0)
|
|
|
|
data_double = struct.unpack('d', struct.pack('Q', data_plain))[0]
|
|
|
|
statistics.metric_hit('code_notrun',self.valobj)
|
|
|
|
return '(double)' + str(data_double)
|
2012-04-03 07:43:22 +08:00
|
|
|
statistics.metric_hit('unknown_class',str(valobj.GetName()) + " had unknown data_type " + str(data_type))
|
2012-02-24 07:10:27 +08:00
|
|
|
return 'absurd: dt = ' + str(data_type)
|
|
|
|
|
|
|
|
|
|
|
|
class NSUnknownNumber_SummaryProvider:
|
|
|
|
def adjust_for_architecture(self):
|
2012-03-06 03:56:33 +08:00
|
|
|
pass
|
2012-02-24 07:10:27 +08:00
|
|
|
|
2012-03-06 03:56:33 +08:00
|
|
|
def __init__(self, valobj, params):
|
2012-04-25 09:39:27 +08:00
|
|
|
logger = lldb.formatters.Logger.Logger()
|
2012-02-24 07:10:27 +08:00
|
|
|
self.valobj = valobj;
|
2012-03-06 03:56:33 +08:00
|
|
|
self.sys_params = params
|
|
|
|
self.update();
|
2012-02-24 07:10:27 +08:00
|
|
|
|
|
|
|
def update(self):
|
2012-04-25 09:39:27 +08:00
|
|
|
logger = lldb.formatters.Logger.Logger()
|
2012-02-24 07:10:27 +08:00
|
|
|
self.adjust_for_architecture();
|
|
|
|
|
|
|
|
def value(self):
|
2012-04-25 09:39:27 +08:00
|
|
|
logger = lldb.formatters.Logger.Logger()
|
2012-02-24 07:10:27 +08:00
|
|
|
stream = lldb.SBStream()
|
|
|
|
self.valobj.GetExpressionPath(stream)
|
|
|
|
expr = "(NSString*)[" + stream.GetData() + " stringValue]"
|
2012-03-14 05:52:00 +08:00
|
|
|
num_children_vo = self.valobj.CreateValueFromExpression("str",expr)
|
|
|
|
if num_children_vo.IsValid():
|
|
|
|
return num_children_vo.GetSummary()
|
|
|
|
return '<variable is not NSNumber>'
|
2012-02-24 07:10:27 +08:00
|
|
|
|
|
|
|
def GetSummary_Impl(valobj):
|
2012-04-25 09:39:27 +08:00
|
|
|
logger = lldb.formatters.Logger.Logger()
|
2012-02-24 07:10:27 +08:00
|
|
|
global statistics
|
2012-04-26 01:53:41 +08:00
|
|
|
class_data,wrapper =lldb.runtime.objc.objc_runtime.Utilities.prepare_class_detection(valobj,statistics)
|
2012-03-14 05:52:00 +08:00
|
|
|
if wrapper:
|
|
|
|
return wrapper
|
2012-02-24 07:10:27 +08:00
|
|
|
|
|
|
|
name_string = class_data.class_name()
|
2012-04-03 00:39:29 +08:00
|
|
|
logger >> "class name is: " + str(name_string)
|
|
|
|
|
2012-02-24 07:10:27 +08:00
|
|
|
if name_string == 'NSNumber' or name_string == '__NSCFNumber':
|
|
|
|
if class_data.is_tagged():
|
2012-03-06 03:56:33 +08:00
|
|
|
wrapper = NSTaggedNumber_SummaryProvider(valobj,class_data.info_bits(),class_data.value(), class_data.sys_params)
|
2012-02-24 07:10:27 +08:00
|
|
|
statistics.metric_hit('code_notrun',valobj)
|
|
|
|
else:
|
|
|
|
# the wrapper might be unable to decipher what is into the NSNumber
|
|
|
|
# and then have to run code on it
|
2012-03-06 03:56:33 +08:00
|
|
|
wrapper = NSUntaggedNumber_SummaryProvider(valobj, class_data.sys_params)
|
2012-02-24 07:10:27 +08:00
|
|
|
else:
|
2012-03-06 03:56:33 +08:00
|
|
|
wrapper = NSUnknownNumber_SummaryProvider(valobj, class_data.sys_params)
|
2012-03-30 08:51:12 +08:00
|
|
|
statistics.metric_hit('unknown_class',valobj.GetName() + " seen as " + name_string)
|
2012-02-24 07:10:27 +08:00
|
|
|
return wrapper;
|
|
|
|
|
|
|
|
|
|
|
|
def NSNumber_SummaryProvider (valobj,dict):
|
2012-04-25 09:39:27 +08:00
|
|
|
logger = lldb.formatters.Logger.Logger()
|
2012-02-24 07:10:27 +08:00
|
|
|
provider = GetSummary_Impl(valobj);
|
|
|
|
if provider != None:
|
2012-04-26 01:53:41 +08:00
|
|
|
if isinstance(provider,lldb.runtime.objc.objc_runtime.SpecialSituation_Description):
|
2012-03-14 05:52:00 +08:00
|
|
|
return provider.message()
|
|
|
|
try:
|
|
|
|
summary = provider.value();
|
|
|
|
except:
|
|
|
|
summary = None
|
2012-04-03 00:39:29 +08:00
|
|
|
logger >> "got summary " + str(summary)
|
2012-03-14 05:52:00 +08:00
|
|
|
if summary == None:
|
|
|
|
summary = '<variable is not NSNumber>'
|
|
|
|
return str(summary)
|
|
|
|
return 'Summary Unavailable'
|
2012-02-24 07:10:27 +08:00
|
|
|
|
|
|
|
|
|
|
|
def __lldb_init_module(debugger,dict):
|
|
|
|
debugger.HandleCommand("type summary add -F NSNumber.NSNumber_SummaryProvider NSNumber")
|
2012-03-14 05:52:00 +08:00
|
|
|
debugger.HandleCommand("type summary add -F NSNumber.NSNumber_SummaryProvider __NSCFBoolean")
|
|
|
|
debugger.HandleCommand("type summary add -F NSNumber.NSNumber_SummaryProvider __NSCFNumber")
|
2012-02-24 07:10:27 +08:00
|
|
|
|