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
|
|
|
# synthetic children provider for NSArray
|
|
|
|
import lldb
|
|
|
|
import ctypes
|
|
|
|
import objc_runtime
|
|
|
|
import metrics
|
2012-04-03 00:39:29 +08:00
|
|
|
import Logger
|
2012-02-24 07:10:27 +08:00
|
|
|
|
|
|
|
statistics = metrics.Metrics()
|
|
|
|
statistics.add_metric('invalid_isa')
|
|
|
|
statistics.add_metric('invalid_pointer')
|
|
|
|
statistics.add_metric('unknown_class')
|
|
|
|
statistics.add_metric('code_notrun')
|
|
|
|
|
|
|
|
# much less functional than the other two cases below
|
|
|
|
# just runs code to get to the count and then returns
|
|
|
|
# no children
|
|
|
|
class NSArrayKVC_SynthProvider:
|
|
|
|
|
|
|
|
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, dict, params):
|
2012-04-03 00:39:29 +08:00
|
|
|
logger = Logger.Logger()
|
2012-02-24 07:10:27 +08:00
|
|
|
self.valobj = valobj;
|
|
|
|
self.update()
|
|
|
|
|
|
|
|
def update(self):
|
2012-04-03 00:39:29 +08:00
|
|
|
logger = Logger.Logger()
|
2012-02-24 07:10:27 +08:00
|
|
|
self.adjust_for_architecture();
|
|
|
|
|
|
|
|
def num_children(self):
|
2012-04-03 00:39:29 +08:00
|
|
|
logger = Logger.Logger()
|
2012-02-24 07:10:27 +08:00
|
|
|
stream = lldb.SBStream()
|
|
|
|
self.valobj.GetExpressionPath(stream)
|
|
|
|
num_children_vo = self.valobj.CreateValueFromExpression("count","(int)[" + stream.GetData() + " count]");
|
2012-03-14 05:52:00 +08:00
|
|
|
if num_children_vo.IsValid():
|
|
|
|
return num_children_vo.GetValueAsUnsigned(0)
|
|
|
|
return "<variable is not NSArray>"
|
2012-02-24 07:10:27 +08:00
|
|
|
|
|
|
|
# much less functional than the other two cases below
|
|
|
|
# just runs code to get to the count and then returns
|
|
|
|
# no children
|
|
|
|
class NSArrayCF_SynthProvider:
|
|
|
|
|
|
|
|
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, dict, params):
|
2012-04-03 00:39:29 +08:00
|
|
|
logger = 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.ulong):
|
|
|
|
self.sys_params.types_cache.ulong = self.valobj.GetType().GetBasicType(lldb.eBasicTypeUnsignedLong)
|
2012-02-24 07:10:27 +08:00
|
|
|
self.update()
|
|
|
|
|
|
|
|
def update(self):
|
2012-04-03 00:39:29 +08:00
|
|
|
logger = Logger.Logger()
|
2012-02-24 07:10:27 +08:00
|
|
|
self.adjust_for_architecture();
|
|
|
|
|
|
|
|
def num_children(self):
|
2012-04-03 00:39:29 +08:00
|
|
|
logger = Logger.Logger()
|
2012-02-24 07:10:27 +08:00
|
|
|
num_children_vo = self.valobj.CreateChildAtOffset("count",
|
2012-03-06 03:56:33 +08:00
|
|
|
self.sys_params.cfruntime_size,
|
|
|
|
self.sys_params.types_cache.ulong)
|
2012-02-24 07:10:27 +08:00
|
|
|
return num_children_vo.GetValueAsUnsigned(0)
|
|
|
|
|
|
|
|
class NSArrayI_SynthProvider:
|
|
|
|
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, dict, params):
|
2012-04-03 00:39:29 +08:00
|
|
|
logger = 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.long):
|
|
|
|
self.sys_params.types_cache.long = self.valobj.GetType().GetBasicType(lldb.eBasicTypeLong)
|
2012-02-24 07:10:27 +08:00
|
|
|
self.update()
|
|
|
|
|
|
|
|
def update(self):
|
2012-04-03 00:39:29 +08:00
|
|
|
logger = Logger.Logger()
|
2012-02-24 07:10:27 +08:00
|
|
|
self.adjust_for_architecture();
|
|
|
|
|
|
|
|
# skip the isa pointer and get at the size
|
|
|
|
def num_children(self):
|
2012-04-03 00:39:29 +08:00
|
|
|
logger = Logger.Logger()
|
2012-02-24 07:10:27 +08:00
|
|
|
count = self.valobj.CreateChildAtOffset("count",
|
2012-03-06 03:56:33 +08:00
|
|
|
self.sys_params.pointer_size,
|
|
|
|
self.sys_params.types_cache.long);
|
|
|
|
return count.GetValueAsUnsigned(0)
|
2012-02-24 07:10:27 +08:00
|
|
|
|
|
|
|
class NSArrayM_SynthProvider:
|
|
|
|
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, dict, params):
|
2012-04-03 00:39:29 +08:00
|
|
|
logger = 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.long):
|
|
|
|
self.sys_params.types_cache.long = self.valobj.GetType().GetBasicType(lldb.eBasicTypeLong)
|
|
|
|
self.update()
|
2012-02-24 07:10:27 +08:00
|
|
|
|
|
|
|
def update(self):
|
2012-04-03 00:39:29 +08:00
|
|
|
logger = Logger.Logger()
|
2012-02-24 07:10:27 +08:00
|
|
|
self.adjust_for_architecture();
|
|
|
|
|
|
|
|
# skip the isa pointer and get at the size
|
|
|
|
def num_children(self):
|
2012-04-03 00:39:29 +08:00
|
|
|
logger = Logger.Logger()
|
2012-02-24 07:10:27 +08:00
|
|
|
count = self.valobj.CreateChildAtOffset("count",
|
2012-03-06 03:56:33 +08:00
|
|
|
self.sys_params.pointer_size,
|
|
|
|
self.sys_params.types_cache.long);
|
|
|
|
return count.GetValueAsUnsigned(0)
|
2012-02-24 07:10:27 +08:00
|
|
|
|
|
|
|
# this is the actual synth provider, but is just a wrapper that checks
|
|
|
|
# whether valobj is an instance of __NSArrayI or __NSArrayM and sets up an
|
|
|
|
# appropriate backend layer to do the computations
|
|
|
|
class NSArray_SynthProvider:
|
|
|
|
def adjust_for_architecture(self):
|
2012-03-06 03:56:33 +08:00
|
|
|
pass
|
2012-02-24 07:10:27 +08:00
|
|
|
|
|
|
|
def __init__(self, valobj, dict):
|
2012-04-03 00:39:29 +08:00
|
|
|
logger = Logger.Logger()
|
2012-02-24 07:10:27 +08:00
|
|
|
self.valobj = valobj;
|
|
|
|
self.adjust_for_architecture()
|
2012-03-14 05:52:00 +08:00
|
|
|
self.error = False
|
|
|
|
self.wrapper = self.make_wrapper()
|
2012-02-24 07:10:27 +08:00
|
|
|
self.invalid = (self.wrapper == None)
|
|
|
|
|
|
|
|
def num_children(self):
|
2012-04-03 00:39:29 +08:00
|
|
|
logger = Logger.Logger()
|
2012-02-24 07:10:27 +08:00
|
|
|
if self.wrapper == None:
|
|
|
|
return 0;
|
|
|
|
return self.wrapper.num_children()
|
|
|
|
|
|
|
|
def update(self):
|
2012-04-03 00:39:29 +08:00
|
|
|
logger = Logger.Logger()
|
2012-02-24 07:10:27 +08:00
|
|
|
if self.wrapper == None:
|
2012-03-06 03:56:33 +08:00
|
|
|
return
|
|
|
|
self.wrapper.update()
|
2012-02-24 07:10:27 +08:00
|
|
|
|
|
|
|
# this code acts as our defense against NULL and unitialized
|
|
|
|
# NSArray pointers, which makes it much longer than it would be otherwise
|
2012-03-14 05:52:00 +08:00
|
|
|
def make_wrapper(self):
|
2012-04-03 00:39:29 +08:00
|
|
|
logger = Logger.Logger()
|
2012-03-14 05:52:00 +08:00
|
|
|
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
|
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 == '__NSArrayI':
|
2012-03-14 05:52:00 +08:00
|
|
|
wrapper = NSArrayI_SynthProvider(self.valobj, dict, class_data.sys_params)
|
2012-04-03 05:37:02 +08:00
|
|
|
statistics.metric_hit('code_notrun',valobj.GetName())
|
2012-02-24 07:10:27 +08:00
|
|
|
elif name_string == '__NSArrayM':
|
2012-03-14 05:52:00 +08:00
|
|
|
wrapper = NSArrayM_SynthProvider(self.valobj, dict, class_data.sys_params)
|
2012-04-03 05:37:02 +08:00
|
|
|
statistics.metric_hit('code_notrun',valobj.GetName()))
|
2012-02-24 07:10:27 +08:00
|
|
|
elif name_string == '__NSCFArray':
|
2012-03-14 05:52:00 +08:00
|
|
|
wrapper = NSArrayCF_SynthProvider(self.valobj, dict, class_data.sys_params)
|
2012-04-03 05:37:02 +08:00
|
|
|
statistics.metric_hit('code_notrun',valobj.GetName()))
|
2012-02-24 07:10:27 +08:00
|
|
|
else:
|
2012-03-14 05:52:00 +08:00
|
|
|
wrapper = NSArrayKVC_SynthProvider(self.valobj, dict, class_data.sys_params)
|
2012-04-03 05:37:02 +08:00
|
|
|
statistics.metric_hit('unknown_class',str(valobj.GetName())) + " seen as " + name_string)
|
2012-02-24 07:10:27 +08:00
|
|
|
return wrapper;
|
|
|
|
|
|
|
|
def CFArray_SummaryProvider (valobj,dict):
|
2012-04-03 00:39:29 +08:00
|
|
|
logger = Logger.Logger()
|
2012-02-24 07:10:27 +08:00
|
|
|
provider = NSArray_SynthProvider(valobj,dict);
|
|
|
|
if provider.invalid == False:
|
2012-03-14 05:52:00 +08:00
|
|
|
if provider.error == True:
|
|
|
|
return provider.wrapper.message()
|
|
|
|
try:
|
|
|
|
summary = int(provider.num_children());
|
|
|
|
except:
|
|
|
|
summary = None
|
2012-04-03 00:39:29 +08:00
|
|
|
logger >> "provider gave me " + str(summary)
|
2012-03-14 05:52:00 +08:00
|
|
|
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'
|
2012-02-24 07:10:27 +08:00
|
|
|
|
|
|
|
def __lldb_init_module(debugger,dict):
|
|
|
|
debugger.HandleCommand("type summary add -F CFArray.CFArray_SummaryProvider NSArray CFArrayRef CFMutableArrayRef")
|