blob: 05313aeffc9565d4de32a39fdeb5ecda0dcb44ba [file] [log] [blame]
Enrico Granata579a2962012-03-13 21:52:00 +00001"""
2LLDB AppKit formatters
3
4part of The LLVM Compiler Infrastructure
5This file is distributed under the University of Illinois Open Source
6License. See LICENSE.TXT for details.
7"""
Enrico Granatab370df22012-02-23 23:10:27 +00008# summary provider for NSData
9import lldb
10import ctypes
11import objc_runtime
12import metrics
Enrico Granata8f182402012-04-02 16:39:29 +000013import Logger
Enrico Granatab370df22012-02-23 23:10:27 +000014
15statistics = metrics.Metrics()
16statistics.add_metric('invalid_isa')
17statistics.add_metric('invalid_pointer')
18statistics.add_metric('unknown_class')
19statistics.add_metric('code_notrun')
20
21# despite the similary to synthetic children providers, these classes are not
22# trying to provide anything but the port number of an NSMachPort, so they need not
23# obey the interface specification for synthetic children providers
24class NSMachPortKnown_SummaryProvider:
25 def adjust_for_architecture(self):
Enrico Granataf2a84672012-03-05 19:56:33 +000026 pass
Enrico Granatab370df22012-02-23 23:10:27 +000027
Enrico Granataf2a84672012-03-05 19:56:33 +000028 def __init__(self, valobj, params):
Enrico Granata8f182402012-04-02 16:39:29 +000029 logger = Logger.Logger()
Enrico Granatab370df22012-02-23 23:10:27 +000030 self.valobj = valobj;
Enrico Granataf2a84672012-03-05 19:56:33 +000031 self.sys_params = params
32 if not(self.sys_params.types_cache.NSUInteger):
33 if self.sys_params.is_64_bit:
34 self.sys_params.types_cache.NSUInteger = self.valobj.GetType().GetBasicType(lldb.eBasicTypeUnsignedLong)
35 else:
36 self.sys_params.types_cache.NSUInteger = self.valobj.GetType().GetBasicType(lldb.eBasicTypeUnsignedInt)
Enrico Granatab370df22012-02-23 23:10:27 +000037 self.update();
38
39 def update(self):
Enrico Granata8f182402012-04-02 16:39:29 +000040 logger = Logger.Logger()
Enrico Granatab370df22012-02-23 23:10:27 +000041 self.adjust_for_architecture();
Enrico Granatab370df22012-02-23 23:10:27 +000042
43 # one pointer is the ISA
44 # then we have one other internal pointer, plus
45 # 4 bytes worth of flags. hence, these values
46 def offset(self):
Enrico Granata8f182402012-04-02 16:39:29 +000047 logger = Logger.Logger()
Enrico Granataf2a84672012-03-05 19:56:33 +000048 if self.sys_params.is_64_bit:
Enrico Granatab370df22012-02-23 23:10:27 +000049 return 20
50 else:
51 return 12
52
53 def port(self):
Enrico Granata8f182402012-04-02 16:39:29 +000054 logger = Logger.Logger()
Enrico Granatab370df22012-02-23 23:10:27 +000055 vport = self.valobj.CreateChildAtOffset("port",
56 self.offset(),
Enrico Granataf2a84672012-03-05 19:56:33 +000057 self.sys_params.types_cache.NSUInteger)
Enrico Granatab370df22012-02-23 23:10:27 +000058 return vport.GetValueAsUnsigned(0)
59
60
61class NSMachPortUnknown_SummaryProvider:
62 def adjust_for_architecture(self):
Enrico Granataf2a84672012-03-05 19:56:33 +000063 pass
Enrico Granatab370df22012-02-23 23:10:27 +000064
Enrico Granataf2a84672012-03-05 19:56:33 +000065 def __init__(self, valobj, params):
Enrico Granata8f182402012-04-02 16:39:29 +000066 logger = Logger.Logger()
Enrico Granatab370df22012-02-23 23:10:27 +000067 self.valobj = valobj;
Enrico Granataf2a84672012-03-05 19:56:33 +000068 self.sys_params = params
69 self.update();
Enrico Granatab370df22012-02-23 23:10:27 +000070
71 def update(self):
Enrico Granata8f182402012-04-02 16:39:29 +000072 logger = Logger.Logger()
Enrico Granatab370df22012-02-23 23:10:27 +000073 self.adjust_for_architecture();
Enrico Granatab370df22012-02-23 23:10:27 +000074
75 def port(self):
Enrico Granata8f182402012-04-02 16:39:29 +000076 logger = Logger.Logger()
Enrico Granatab370df22012-02-23 23:10:27 +000077 stream = lldb.SBStream()
78 self.valobj.GetExpressionPath(stream)
Enrico Granata579a2962012-03-13 21:52:00 +000079 num_children_vo = self.valobj.CreateValueFromExpression("port","(int)[" + stream.GetData() + " machPort]")
80 if num_children_vo.IsValid():
81 return num_children_vo.GetValueAsUnsigned(0)
82 return '<variable is not NSMachPort>'
Enrico Granatab370df22012-02-23 23:10:27 +000083
84
85def GetSummary_Impl(valobj):
Enrico Granata8f182402012-04-02 16:39:29 +000086 logger = Logger.Logger()
Enrico Granatab370df22012-02-23 23:10:27 +000087 global statistics
Enrico Granata579a2962012-03-13 21:52:00 +000088 class_data,wrapper = objc_runtime.Utilities.prepare_class_detection(valobj,statistics)
89 if wrapper:
90 return wrapper
Enrico Granatab370df22012-02-23 23:10:27 +000091
92 name_string = class_data.class_name()
Enrico Granata8f182402012-04-02 16:39:29 +000093 logger >> "class name is: " + str(name_string)
94
Enrico Granatab370df22012-02-23 23:10:27 +000095 if name_string == 'NSMachPort':
Enrico Granataf2a84672012-03-05 19:56:33 +000096 wrapper = NSMachPortKnown_SummaryProvider(valobj, class_data.sys_params)
Enrico Granatab370df22012-02-23 23:10:27 +000097 statistics.metric_hit('code_notrun',valobj)
98 else:
Enrico Granataf2a84672012-03-05 19:56:33 +000099 wrapper = NSMachPortUnknown_SummaryProvider(valobj, class_data.sys_params)
Enrico Granata805f79b2012-03-30 00:51:12 +0000100 statistics.metric_hit('unknown_class',valobj.GetName() + " seen as " + name_string)
Enrico Granatab370df22012-02-23 23:10:27 +0000101 return wrapper;
102
103def NSMachPort_SummaryProvider (valobj,dict):
Enrico Granata8f182402012-04-02 16:39:29 +0000104 logger = Logger.Logger()
Enrico Granatab370df22012-02-23 23:10:27 +0000105 provider = GetSummary_Impl(valobj);
106 if provider != None:
Enrico Granata579a2962012-03-13 21:52:00 +0000107 if isinstance(provider,objc_runtime.SpecialSituation_Description):
108 return provider.message()
109 try:
110 summary = provider.port();
111 except:
112 summary = None
Enrico Granata8f182402012-04-02 16:39:29 +0000113 logger >> "got summary " + str(summary)
Enrico Granata579a2962012-03-13 21:52:00 +0000114 if summary == None:
115 summary = '<variable is not NSMachPort>'
116 if isinstance(summary, basestring):
117 return summay
118 return 'mach port: ' + str(summary)
119 return 'Summary Unavailable'
Enrico Granatab370df22012-02-23 23:10:27 +0000120
121def __lldb_init_module(debugger,dict):
122 debugger.HandleCommand("type summary add -F NSMachPort.NSMachPort_SummaryProvider NSMachPort")