blob: 33ba1d45a1f9ab654daa37405bde3cc0884c168a [file] [log] [blame]
Enrico Granatacfdafa32012-03-05 19:56:33 +00001"""
2Objective-C runtime wrapper for use by LLDB Python 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 Granataeb4a4792012-02-23 23:10:27 +00008import lldb
9import cache
Enrico Granatacfdafa32012-03-05 19:56:33 +000010import attrib_fromdict
11import functools
Enrico Granata247bd412012-04-02 16:39:29 +000012import Logger
Enrico Granataeb4a4792012-02-23 23:10:27 +000013
14class Utilities:
15 @staticmethod
Enrico Granata7bc0ec32012-02-29 03:28:49 +000016 def read_ascii(process, pointer,max_len=128):
Enrico Granata247bd412012-04-02 16:39:29 +000017 logger = Logger.Logger()
Enrico Granataeb4a4792012-02-23 23:10:27 +000018 error = lldb.SBError()
Enrico Granata7bc0ec32012-02-29 03:28:49 +000019 content = None
20 try:
21 content = process.ReadCStringFromMemory(pointer,max_len,error)
22 except:
23 pass
24 if content == None or len(content) == 0 or error.fail == True:
25 return None
26 return content
Enrico Granataeb4a4792012-02-23 23:10:27 +000027
28 @staticmethod
Enrico Granata7bc0ec32012-02-29 03:28:49 +000029 def is_valid_pointer(pointer, pointer_size, allow_tagged=False, allow_NULL=False):
Enrico Granata247bd412012-04-02 16:39:29 +000030 logger = Logger.Logger()
Enrico Granataeb4a4792012-02-23 23:10:27 +000031 if pointer == None:
32 return False
33 if pointer == 0:
Enrico Granata7bc0ec32012-02-29 03:28:49 +000034 return allow_NULL
35 if allow_tagged and (pointer % 2) == 1:
36 return True
Enrico Granataeb4a4792012-02-23 23:10:27 +000037 return ((pointer % pointer_size) == 0)
38
39 # Objective-C runtime has a rule that pointers in a class_t will only have bits 0 thru 46 set
40 # so if any pointer has bits 47 thru 63 high we know that this is not a valid isa
41 @staticmethod
42 def is_allowed_pointer(pointer):
Enrico Granata247bd412012-04-02 16:39:29 +000043 logger = Logger.Logger()
Enrico Granataeb4a4792012-02-23 23:10:27 +000044 if pointer == None:
45 return False
Enrico Granata7bc0ec32012-02-29 03:28:49 +000046 return ((pointer & 0xFFFF800000000000) == 0)
Enrico Granataeb4a4792012-02-23 23:10:27 +000047
48 @staticmethod
49 def read_child_of(valobj,offset,type):
Enrico Granata247bd412012-04-02 16:39:29 +000050 logger = Logger.Logger()
Enrico Granataeb4a4792012-02-23 23:10:27 +000051 child = valobj.CreateChildAtOffset("childUNK",offset,type)
52 if child == None or child.IsValid() == False:
53 return None;
54 return child.GetValueAsUnsigned()
55
56 @staticmethod
57 def is_valid_identifier(name):
Enrico Granata247bd412012-04-02 16:39:29 +000058 logger = Logger.Logger()
Enrico Granataeb4a4792012-02-23 23:10:27 +000059 if name is None:
60 return None
61 if len(name) == 0:
62 return None
Enrico Granata7bc0ec32012-02-29 03:28:49 +000063 # technically, the ObjC runtime does not enforce any rules about what name a class can have
64 # in practice, the commonly used byte values for a class name are the letters, digits and some
65 # symbols: $, %, -, _, .
66 # WARNING: this means that you cannot use this runtime implementation if you need to deal
67 # with class names that use anything but what is allowed here
68 ok_values = dict.fromkeys("$%_.-ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890")
69 return all(c in ok_values for c in name)
70
71 @staticmethod
72 def check_is_osx_lion(target):
Enrico Granata247bd412012-04-02 16:39:29 +000073 logger = Logger.Logger()
Enrico Granata7bc0ec32012-02-29 03:28:49 +000074 # assume the only thing that has a Foundation.framework is a Mac
75 # assume anything < Lion does not even exist
76 mod = target.module['Foundation']
77 if mod == None or mod.IsValid() == False:
78 return None
79 ver = mod.GetVersion()
80 if ver == None or ver == []:
81 return None
82 return (ver[0] < 900)
Enrico Granataeb4a4792012-02-23 23:10:27 +000083
Enrico Granata3f1052b2012-03-13 21:52:00 +000084 # a utility method that factors out code common to almost all the formatters
85 # takes in an SBValue and a metrics object
86 # returns a class_data and a wrapper (or None, if the runtime alone can't decide on a wrapper)
87 @staticmethod
88 def prepare_class_detection(valobj,statistics):
Enrico Granata247bd412012-04-02 16:39:29 +000089 logger = Logger.Logger()
Enrico Granata3f1052b2012-03-13 21:52:00 +000090 class_data = ObjCRuntime(valobj)
91 if class_data.is_valid() == False:
92 statistics.metric_hit('invalid_pointer',valobj)
93 wrapper = InvalidPointer_Description(valobj.GetValueAsUnsigned(0) == 0)
94 return class_data,wrapper
95 class_data = class_data.read_class_data()
96 if class_data.is_valid() == False:
97 statistics.metric_hit('invalid_isa',valobj)
98 wrapper = InvalidISA_Description()
99 return class_data,wrapper
100 if class_data.is_kvo():
101 class_data = class_data.get_superclass()
102 if class_data.is_valid() == False:
103 statistics.metric_hit('invalid_isa',valobj)
104 wrapper = InvalidISA_Description()
105 return class_data,wrapper
106 return class_data,None
107
108
Enrico Granataeb4a4792012-02-23 23:10:27 +0000109class RoT_Data:
110 def __init__(self,rot_pointer,params):
Enrico Granata247bd412012-04-02 16:39:29 +0000111 logger = Logger.Logger()
Enrico Granataeb4a4792012-02-23 23:10:27 +0000112 if (Utilities.is_valid_pointer(rot_pointer.GetValueAsUnsigned(),params.pointer_size, allow_tagged=False)):
113 self.sys_params = params
114 self.valobj = rot_pointer
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000115 #self.flags = Utilities.read_child_of(self.valobj,0,self.sys_params.uint32_t)
Enrico Granatacfdafa32012-03-05 19:56:33 +0000116 #self.instanceStart = Utilities.read_child_of(self.valobj,4,self.sys_params.uint32_t)
117 self.instanceSize = None # lazy fetching
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000118 offset = 24 if self.sys_params.is_64_bit else 16
119 #self.ivarLayoutPtr = Utilities.read_child_of(self.valobj,offset,self.sys_params.addr_ptr_type)
Enrico Granatacfdafa32012-03-05 19:56:33 +0000120 self.namePointer = Utilities.read_child_of(self.valobj,offset,self.sys_params.types_cache.addr_ptr_type)
Enrico Granataeb4a4792012-02-23 23:10:27 +0000121 self.check_valid()
122 else:
Enrico Granata247bd412012-04-02 16:39:29 +0000123 logger >> "Marking as invalid - rot is invalid"
Enrico Granataeb4a4792012-02-23 23:10:27 +0000124 self.valid = False
125 if self.valid:
126 self.name = Utilities.read_ascii(self.valobj.GetTarget().GetProcess(),self.namePointer)
127 if not(Utilities.is_valid_identifier(self.name)):
Enrico Granata247bd412012-04-02 16:39:29 +0000128 logger >> "Marking as invalid - name is invalid"
Enrico Granataeb4a4792012-02-23 23:10:27 +0000129 self.valid = False
130
Enrico Granatacfdafa32012-03-05 19:56:33 +0000131 # perform sanity checks on the contents of this class_ro_t
Enrico Granataeb4a4792012-02-23 23:10:27 +0000132 def check_valid(self):
133 self.valid = True
134 # misaligned pointers seem to be possible for this field
135 #if not(Utilities.is_valid_pointer(self.namePointer,self.sys_params.pointer_size,allow_tagged=False)):
136 # self.valid = False
137 # pass
138
139 def __str__(self):
Enrico Granata247bd412012-04-02 16:39:29 +0000140 logger = Logger.Logger()
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000141 return \
Enrico Granatacfdafa32012-03-05 19:56:33 +0000142 "instanceSize = " + hex(self.instance_size()) + "\n" + \
Enrico Granataeb4a4792012-02-23 23:10:27 +0000143 "namePointer = " + hex(self.namePointer) + " --> " + self.name
144
145 def is_valid(self):
146 return self.valid
147
Enrico Granatacfdafa32012-03-05 19:56:33 +0000148 def instance_size(self,align=False):
Enrico Granata247bd412012-04-02 16:39:29 +0000149 logger = Logger.Logger()
Enrico Granatacfdafa32012-03-05 19:56:33 +0000150 if self.is_valid() == False:
151 return None
152 if self.instanceSize == None:
153 self.instanceSize = Utilities.read_child_of(self.valobj,8,self.sys_params.types_cache.uint32_t)
154 if align:
155 unalign = self.instance_size(False)
156 if self.sys_params.is_64_bit:
157 return ((unalign + 7) & ~7) % 0x100000000
158 else:
159 return ((unalign + 3) & ~3) % 0x100000000
160 else:
161 return self.instanceSize
Enrico Granataeb4a4792012-02-23 23:10:27 +0000162
163class RwT_Data:
164 def __init__(self,rwt_pointer,params):
Enrico Granata247bd412012-04-02 16:39:29 +0000165 logger = Logger.Logger()
Enrico Granataeb4a4792012-02-23 23:10:27 +0000166 if (Utilities.is_valid_pointer(rwt_pointer.GetValueAsUnsigned(),params.pointer_size, allow_tagged=False)):
167 self.sys_params = params
168 self.valobj = rwt_pointer
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000169 #self.flags = Utilities.read_child_of(self.valobj,0,self.sys_params.uint32_t)
170 #self.version = Utilities.read_child_of(self.valobj,4,self.sys_params.uint32_t)
Enrico Granatacfdafa32012-03-05 19:56:33 +0000171 self.roPointer = Utilities.read_child_of(self.valobj,8,self.sys_params.types_cache.addr_ptr_type)
Enrico Granataeb4a4792012-02-23 23:10:27 +0000172 self.check_valid()
173 else:
Enrico Granata247bd412012-04-02 16:39:29 +0000174 logger >> "Marking as invalid - rwt is invald"
Enrico Granataeb4a4792012-02-23 23:10:27 +0000175 self.valid = False
176 if self.valid:
Enrico Granatacfdafa32012-03-05 19:56:33 +0000177 self.rot = self.valobj.CreateValueFromAddress("rot",self.roPointer,self.sys_params.types_cache.addr_ptr_type).AddressOf()
Enrico Granataeb4a4792012-02-23 23:10:27 +0000178 self.data = RoT_Data(self.rot,self.sys_params)
179
180 # perform sanity checks on the contents of this class_rw_t
181 def check_valid(self):
Enrico Granata247bd412012-04-02 16:39:29 +0000182 logger = Logger.Logger()
Enrico Granataeb4a4792012-02-23 23:10:27 +0000183 self.valid = True
184 if not(Utilities.is_valid_pointer(self.roPointer,self.sys_params.pointer_size,allow_tagged=False)):
Enrico Granata247bd412012-04-02 16:39:29 +0000185 logger >> "Marking as invalid - ropointer is invalid"
Enrico Granataeb4a4792012-02-23 23:10:27 +0000186 self.valid = False
187
188 def __str__(self):
Enrico Granata247bd412012-04-02 16:39:29 +0000189 logger = Logger.Logger()
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000190 return \
Enrico Granataeb4a4792012-02-23 23:10:27 +0000191 "roPointer = " + hex(self.roPointer)
192
193 def is_valid(self):
Enrico Granata247bd412012-04-02 16:39:29 +0000194 logger = Logger.Logger()
Enrico Granataeb4a4792012-02-23 23:10:27 +0000195 if self.valid:
196 return self.data.is_valid()
197 return False
198
199class Class_Data_V2:
200 def __init__(self,isa_pointer,params):
Enrico Granata247bd412012-04-02 16:39:29 +0000201 logger = Logger.Logger()
Enrico Granataeb4a4792012-02-23 23:10:27 +0000202 if (isa_pointer != None) and (Utilities.is_valid_pointer(isa_pointer.GetValueAsUnsigned(),params.pointer_size, allow_tagged=False)):
203 self.sys_params = params
204 self.valobj = isa_pointer
Enrico Granataeb4a4792012-02-23 23:10:27 +0000205 self.check_valid()
206 else:
Enrico Granata247bd412012-04-02 16:39:29 +0000207 logger >> "Marking as invalid - isa is invalid or None"
Enrico Granataeb4a4792012-02-23 23:10:27 +0000208 self.valid = False
209 if self.valid:
Enrico Granatacfdafa32012-03-05 19:56:33 +0000210 self.rwt = self.valobj.CreateValueFromAddress("rwt",self.dataPointer,self.sys_params.types_cache.addr_ptr_type).AddressOf()
Enrico Granataeb4a4792012-02-23 23:10:27 +0000211 self.data = RwT_Data(self.rwt,self.sys_params)
212
213 # perform sanity checks on the contents of this class_t
Enrico Granatacfdafa32012-03-05 19:56:33 +0000214 # this call tries to minimize the amount of data fetched- as soon as we have "proven"
215 # that we have an invalid object, we stop reading
Enrico Granataeb4a4792012-02-23 23:10:27 +0000216 def check_valid(self):
Enrico Granata247bd412012-04-02 16:39:29 +0000217 logger = Logger.Logger()
Enrico Granataeb4a4792012-02-23 23:10:27 +0000218 self.valid = True
Enrico Granatacfdafa32012-03-05 19:56:33 +0000219
220 self.isaPointer = Utilities.read_child_of(self.valobj,0,self.sys_params.types_cache.addr_ptr_type)
Enrico Granataeb4a4792012-02-23 23:10:27 +0000221 if not(Utilities.is_valid_pointer(self.isaPointer,self.sys_params.pointer_size,allow_tagged=False)):
Enrico Granata247bd412012-04-02 16:39:29 +0000222 logger >> "Marking as invalid - isaPointer is invalid"
Enrico Granataeb4a4792012-02-23 23:10:27 +0000223 self.valid = False
224 return
Enrico Granataeb4a4792012-02-23 23:10:27 +0000225 if not(Utilities.is_allowed_pointer(self.isaPointer)):
Enrico Granata247bd412012-04-02 16:39:29 +0000226 logger >> "Marking as invalid - isaPointer is not allowed"
Enrico Granataeb4a4792012-02-23 23:10:27 +0000227 self.valid = False
228 return
Enrico Granatacfdafa32012-03-05 19:56:33 +0000229
230 self.cachePointer = Utilities.read_child_of(self.valobj,2*self.sys_params.pointer_size,self.sys_params.types_cache.addr_ptr_type)
231 if not(Utilities.is_valid_pointer(self.cachePointer,self.sys_params.pointer_size,allow_tagged=False)):
Enrico Granata247bd412012-04-02 16:39:29 +0000232 logger >> "Marking as invalid - cachePointer is invalid"
Enrico Granatacfdafa32012-03-05 19:56:33 +0000233 self.valid = False
234 return
Enrico Granataeb4a4792012-02-23 23:10:27 +0000235 if not(Utilities.is_allowed_pointer(self.cachePointer)):
Enrico Granata247bd412012-04-02 16:39:29 +0000236 logger >> "Marking as invalid - cachePointer is not allowed"
Enrico Granataeb4a4792012-02-23 23:10:27 +0000237 self.valid = False
238 return
Enrico Granatacfdafa32012-03-05 19:56:33 +0000239
240 self.vtablePointer = Utilities.read_child_of(self.valobj,3*self.sys_params.pointer_size,self.sys_params.types_cache.addr_ptr_type)
241 if not(Utilities.is_valid_pointer(self.vtablePointer,self.sys_params.pointer_size,allow_tagged=False)):
Enrico Granata247bd412012-04-02 16:39:29 +0000242 logger >> "Marking as invalid - vtablePointer is invalid"
Enrico Granatacfdafa32012-03-05 19:56:33 +0000243 self.valid = False
244 return
Enrico Granataeb4a4792012-02-23 23:10:27 +0000245 if not(Utilities.is_allowed_pointer(self.vtablePointer)):
Enrico Granata247bd412012-04-02 16:39:29 +0000246 logger >> "Marking as invalid - vtablePointer is not allowed"
Enrico Granataeb4a4792012-02-23 23:10:27 +0000247 self.valid = False
248 return
Enrico Granatacfdafa32012-03-05 19:56:33 +0000249
250 self.dataPointer = Utilities.read_child_of(self.valobj,4*self.sys_params.pointer_size,self.sys_params.types_cache.addr_ptr_type)
251 if not(Utilities.is_valid_pointer(self.dataPointer,self.sys_params.pointer_size,allow_tagged=False)):
Enrico Granata247bd412012-04-02 16:39:29 +0000252 logger >> "Marking as invalid - dataPointer is invalid"
Enrico Granatacfdafa32012-03-05 19:56:33 +0000253 self.valid = False
254 return
Enrico Granataeb4a4792012-02-23 23:10:27 +0000255 if not(Utilities.is_allowed_pointer(self.dataPointer)):
Enrico Granata247bd412012-04-02 16:39:29 +0000256 logger >> "Marking as invalid - dataPointer is not allowed"
Enrico Granataeb4a4792012-02-23 23:10:27 +0000257 self.valid = False
258 return
259
Enrico Granatacfdafa32012-03-05 19:56:33 +0000260 self.superclassIsaPointer = Utilities.read_child_of(self.valobj,1*self.sys_params.pointer_size,self.sys_params.types_cache.addr_ptr_type)
261 if not(Utilities.is_valid_pointer(self.superclassIsaPointer,self.sys_params.pointer_size,allow_tagged=False, allow_NULL=True)):
Enrico Granata247bd412012-04-02 16:39:29 +0000262 logger >> "Marking as invalid - superclassIsa is invalid"
Enrico Granatacfdafa32012-03-05 19:56:33 +0000263 self.valid = False
264 return
265 if not(Utilities.is_allowed_pointer(self.superclassIsaPointer)):
Enrico Granata247bd412012-04-02 16:39:29 +0000266 logger >> "Marking as invalid - superclassIsa is not allowed"
Enrico Granatacfdafa32012-03-05 19:56:33 +0000267 self.valid = False
268 return
269
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000270 # in general, KVO is implemented by transparently subclassing
271 # however, there could be exceptions where a class does something else
272 # internally to implement the feature - this method will have no clue that a class
273 # has been KVO'ed unless the standard implementation technique is used
Enrico Granataeb4a4792012-02-23 23:10:27 +0000274 def is_kvo(self):
Enrico Granata247bd412012-04-02 16:39:29 +0000275 logger = Logger.Logger()
Enrico Granataeb4a4792012-02-23 23:10:27 +0000276 if self.is_valid():
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000277 if self.class_name().startswith("NSKVONotifying_"):
Enrico Granataeb4a4792012-02-23 23:10:27 +0000278 return True
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000279 return False
Enrico Granataeb4a4792012-02-23 23:10:27 +0000280
Enrico Granatacfdafa32012-03-05 19:56:33 +0000281 # some CF classes have a valid ObjC isa in their CFRuntimeBase
282 # but instead of being class-specific this isa points to a match-'em-all class
283 # which is __NSCFType (the versions without __ also exists and we are matching to it
284 # just to be on the safe side)
285 def is_cftype(self):
Enrico Granata247bd412012-04-02 16:39:29 +0000286 logger = Logger.Logger()
Enrico Granatacfdafa32012-03-05 19:56:33 +0000287 if self.is_valid():
Enrico Granata3f1052b2012-03-13 21:52:00 +0000288 return self.class_name() == '__NSCFType' or self.class_name() == 'NSCFType'
Enrico Granatacfdafa32012-03-05 19:56:33 +0000289
Enrico Granataeb4a4792012-02-23 23:10:27 +0000290 def get_superclass(self):
Enrico Granata247bd412012-04-02 16:39:29 +0000291 logger = Logger.Logger()
Enrico Granataeb4a4792012-02-23 23:10:27 +0000292 if self.is_valid():
293 parent_isa_pointer = self.valobj.CreateChildAtOffset("parent_isa",
294 self.sys_params.pointer_size,
295 self.sys_params.addr_ptr_type)
296 return Class_Data_V2(parent_isa_pointer,self.sys_params)
297 else:
298 return None
299
300 def class_name(self):
Enrico Granata247bd412012-04-02 16:39:29 +0000301 logger = Logger.Logger()
Enrico Granataeb4a4792012-02-23 23:10:27 +0000302 if self.is_valid():
303 return self.data.data.name
304 else:
305 return None
306
307 def is_valid(self):
Enrico Granata247bd412012-04-02 16:39:29 +0000308 logger = Logger.Logger()
Enrico Granataeb4a4792012-02-23 23:10:27 +0000309 if self.valid:
310 return self.data.is_valid()
311 return False
312
313 def __str__(self):
Enrico Granata247bd412012-04-02 16:39:29 +0000314 logger = Logger.Logger()
Enrico Granataeb4a4792012-02-23 23:10:27 +0000315 return 'isaPointer = ' + hex(self.isaPointer) + "\n" + \
316 "superclassIsaPointer = " + hex(self.superclassIsaPointer) + "\n" + \
317 "cachePointer = " + hex(self.cachePointer) + "\n" + \
318 "vtablePointer = " + hex(self.vtablePointer) + "\n" + \
319 "data = " + hex(self.dataPointer)
320
321 def is_tagged(self):
322 return False
323
Enrico Granatab8cbe9c2012-02-23 23:26:48 +0000324 def instance_size(self,align=False):
Enrico Granata247bd412012-04-02 16:39:29 +0000325 logger = Logger.Logger()
Enrico Granatab8cbe9c2012-02-23 23:26:48 +0000326 if self.is_valid() == False:
327 return None
Enrico Granatacfdafa32012-03-05 19:56:33 +0000328 return self.rwt.rot.instance_size(align)
Enrico Granatab8cbe9c2012-02-23 23:26:48 +0000329
Enrico Granataeb4a4792012-02-23 23:10:27 +0000330# runtime v1 is much less intricate than v2 and stores relevant information directly in the class_t object
Enrico Granataeb4a4792012-02-23 23:10:27 +0000331class Class_Data_V1:
332 def __init__(self,isa_pointer,params):
Enrico Granata247bd412012-04-02 16:39:29 +0000333 logger = Logger.Logger()
Enrico Granataeb4a4792012-02-23 23:10:27 +0000334 if (isa_pointer != None) and (Utilities.is_valid_pointer(isa_pointer.GetValueAsUnsigned(),params.pointer_size, allow_tagged=False)):
Enrico Granata0448d9f2012-02-29 20:46:00 +0000335 self.valid = True
Enrico Granataeb4a4792012-02-23 23:10:27 +0000336 self.sys_params = params
337 self.valobj = isa_pointer
Enrico Granatacfdafa32012-03-05 19:56:33 +0000338 self.check_valid()
Enrico Granataeb4a4792012-02-23 23:10:27 +0000339 else:
Enrico Granata247bd412012-04-02 16:39:29 +0000340 logger >> "Marking as invalid - isaPointer is invalid or None"
Enrico Granataeb4a4792012-02-23 23:10:27 +0000341 self.valid = False
342 if self.valid:
343 self.name = Utilities.read_ascii(self.valobj.GetTarget().GetProcess(),self.namePointer)
344 if not(Utilities.is_valid_identifier(self.name)):
Enrico Granata247bd412012-04-02 16:39:29 +0000345 logger >> "Marking as invalid - name is not valid"
Enrico Granataeb4a4792012-02-23 23:10:27 +0000346 self.valid = False
347
348 # perform sanity checks on the contents of this class_t
349 def check_valid(self):
Enrico Granata247bd412012-04-02 16:39:29 +0000350 logger = Logger.Logger()
Enrico Granataeb4a4792012-02-23 23:10:27 +0000351 self.valid = True
Enrico Granatacfdafa32012-03-05 19:56:33 +0000352
353 self.isaPointer = Utilities.read_child_of(self.valobj,0,self.sys_params.types_cache.addr_ptr_type)
Enrico Granataeb4a4792012-02-23 23:10:27 +0000354 if not(Utilities.is_valid_pointer(self.isaPointer,self.sys_params.pointer_size,allow_tagged=False)):
Enrico Granata247bd412012-04-02 16:39:29 +0000355 logger >> "Marking as invalid - isaPointer is invalid"
Enrico Granataeb4a4792012-02-23 23:10:27 +0000356 self.valid = False
357 return
Enrico Granatacfdafa32012-03-05 19:56:33 +0000358
359 self.superclassIsaPointer = Utilities.read_child_of(self.valobj,1*self.sys_params.pointer_size,self.sys_params.types_cache.addr_ptr_type)
360 if not(Utilities.is_valid_pointer(self.superclassIsaPointer,self.sys_params.pointer_size,allow_tagged=False,allow_NULL=True)):
Enrico Granata247bd412012-04-02 16:39:29 +0000361 logger >> "Marking as invalid - superclassIsa is invalid"
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000362 self.valid = False
363 return
Enrico Granataeb4a4792012-02-23 23:10:27 +0000364
Enrico Granatacfdafa32012-03-05 19:56:33 +0000365 self.namePointer = Utilities.read_child_of(self.valobj,2*self.sys_params.pointer_size,self.sys_params.types_cache.addr_ptr_type)
366 #if not(Utilities.is_valid_pointer(self.namePointer,self.sys_params.pointer_size,allow_tagged=False,allow_NULL=False)):
367 # self.valid = False
368 # return
369
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000370 # in general, KVO is implemented by transparently subclassing
371 # however, there could be exceptions where a class does something else
372 # internally to implement the feature - this method will have no clue that a class
373 # has been KVO'ed unless the standard implementation technique is used
Enrico Granataeb4a4792012-02-23 23:10:27 +0000374 def is_kvo(self):
Enrico Granata247bd412012-04-02 16:39:29 +0000375 logger = Logger.Logger()
Enrico Granataeb4a4792012-02-23 23:10:27 +0000376 if self.is_valid():
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000377 if self.class_name().startswith("NSKVONotifying_"):
Enrico Granataeb4a4792012-02-23 23:10:27 +0000378 return True
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000379 return False
Enrico Granataeb4a4792012-02-23 23:10:27 +0000380
Enrico Granatacfdafa32012-03-05 19:56:33 +0000381 # some CF classes have a valid ObjC isa in their CFRuntimeBase
382 # but instead of being class-specific this isa points to a match-'em-all class
383 # which is __NSCFType (the versions without __ also exists and we are matching to it
384 # just to be on the safe side)
385 def is_cftype(self):
Enrico Granata247bd412012-04-02 16:39:29 +0000386 logger = Logger.Logger()
Enrico Granatacfdafa32012-03-05 19:56:33 +0000387 if self.is_valid():
Enrico Granata3f1052b2012-03-13 21:52:00 +0000388 return self.class_name() == '__NSCFType' or self.class_name() == 'NSCFType'
Enrico Granatacfdafa32012-03-05 19:56:33 +0000389
Enrico Granataeb4a4792012-02-23 23:10:27 +0000390 def get_superclass(self):
Enrico Granata247bd412012-04-02 16:39:29 +0000391 logger = Logger.Logger()
Enrico Granataeb4a4792012-02-23 23:10:27 +0000392 if self.is_valid():
393 parent_isa_pointer = self.valobj.CreateChildAtOffset("parent_isa",
394 self.sys_params.pointer_size,
395 self.sys_params.addr_ptr_type)
396 return Class_Data_V1(parent_isa_pointer,self.sys_params)
397 else:
398 return None
399
400 def class_name(self):
Enrico Granata247bd412012-04-02 16:39:29 +0000401 logger = Logger.Logger()
Enrico Granataeb4a4792012-02-23 23:10:27 +0000402 if self.is_valid():
403 return self.name
404 else:
405 return None
406
407 def is_valid(self):
408 return self.valid
409
410 def __str__(self):
Enrico Granata247bd412012-04-02 16:39:29 +0000411 logger = Logger.Logger()
Enrico Granataeb4a4792012-02-23 23:10:27 +0000412 return 'isaPointer = ' + hex(self.isaPointer) + "\n" + \
413 "superclassIsaPointer = " + hex(self.superclassIsaPointer) + "\n" + \
Enrico Granatab8cbe9c2012-02-23 23:26:48 +0000414 "namePointer = " + hex(self.namePointer) + " --> " + self.name + \
Enrico Granatacfdafa32012-03-05 19:56:33 +0000415 "instanceSize = " + hex(self.instanceSize()) + "\n"
Enrico Granataeb4a4792012-02-23 23:10:27 +0000416
417 def is_tagged(self):
418 return False
419
Enrico Granatab8cbe9c2012-02-23 23:26:48 +0000420 def instance_size(self,align=False):
Enrico Granata247bd412012-04-02 16:39:29 +0000421 logger = Logger.Logger()
Enrico Granatab8cbe9c2012-02-23 23:26:48 +0000422 if self.is_valid() == False:
423 return None
Enrico Granatacfdafa32012-03-05 19:56:33 +0000424 if self.instanceSize == None:
425 self.instanceSize = Utilities.read_child_of(self.valobj,5*self.sys_params.pointer_size,self.sys_params.types_cache.addr_ptr_type)
Enrico Granatab8cbe9c2012-02-23 23:26:48 +0000426 if align:
427 unalign = self.instance_size(False)
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000428 if self.sys_params.is_64_bit:
Enrico Granatab8cbe9c2012-02-23 23:26:48 +0000429 return ((unalign + 7) & ~7) % 0x100000000
430 else:
431 return ((unalign + 3) & ~3) % 0x100000000
432 else:
433 return self.instanceSize
434
Enrico Granata0448d9f2012-02-29 20:46:00 +0000435# these are the only tagged pointers values for current versions
Enrico Granata0c489f52012-03-01 04:24:26 +0000436# of OSX - they might change in future OS releases, and no-one is
Enrico Granata0448d9f2012-02-29 20:46:00 +0000437# advised to rely on these values, or any of the bitmasking formulas
438# in TaggedClass_Data. doing otherwise is at your own risk
Enrico Granata0c489f52012-03-01 04:24:26 +0000439TaggedClass_Values_Lion = {1 : 'NSNumber', \
440 5: 'NSManagedObject', \
441 6: 'NSDate', \
442 7: 'NSDateTS' };
443TaggedClass_Values_NMOS = {0: 'NSAtom', \
444 3 : 'NSNumber', \
445 4: 'NSDateTS', \
446 5: 'NSManagedObject', \
447 6: 'NSDate' };
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000448
Enrico Granataeb4a4792012-02-23 23:10:27 +0000449class TaggedClass_Data:
450 def __init__(self,pointer,params):
Enrico Granata247bd412012-04-02 16:39:29 +0000451 logger = Logger.Logger()
Enrico Granata0c489f52012-03-01 04:24:26 +0000452 global TaggedClass_Values_Lion,TaggedClass_Values_NMOS
Enrico Granataeb4a4792012-02-23 23:10:27 +0000453 self.valid = True
454 self.name = None
455 self.sys_params = params
456 self.valobj = pointer
457 self.val = (pointer & ~0x0000000000000000FF) >> 8
458 self.class_bits = (pointer & 0xE) >> 1
459 self.i_bits = (pointer & 0xF0) >> 4
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000460
Enrico Granata0c489f52012-03-01 04:24:26 +0000461 if self.sys_params.is_lion:
462 if self.class_bits in TaggedClass_Values_Lion:
463 self.name = TaggedClass_Values_Lion[self.class_bits]
464 else:
Enrico Granata247bd412012-04-02 16:39:29 +0000465 logger >> "Marking as invalid - not a good tagged pointer for Lion"
Enrico Granata0c489f52012-03-01 04:24:26 +0000466 self.valid = False
Enrico Granataeb4a4792012-02-23 23:10:27 +0000467 else:
Enrico Granata0c489f52012-03-01 04:24:26 +0000468 if self.class_bits in TaggedClass_Values_NMOS:
469 self.name = TaggedClass_Values_NMOS[self.class_bits]
470 else:
Enrico Granata247bd412012-04-02 16:39:29 +0000471 logger >> "Marking as invalid - not a good tagged pointer for NMOS"
Enrico Granata0c489f52012-03-01 04:24:26 +0000472 self.valid = False
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000473
Enrico Granataeb4a4792012-02-23 23:10:27 +0000474
475 def is_valid(self):
476 return self.valid
477
478 def class_name(self):
Enrico Granata247bd412012-04-02 16:39:29 +0000479 logger = Logger.Logger()
Enrico Granataeb4a4792012-02-23 23:10:27 +0000480 if self.is_valid():
481 return self.name
482 else:
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000483 return False
Enrico Granataeb4a4792012-02-23 23:10:27 +0000484
485 def value(self):
486 return self.val if self.is_valid() else None
487
488 def info_bits(self):
489 return self.i_bits if self.is_valid() else None
490
491 def is_kvo(self):
492 return False
493
Enrico Granatacfdafa32012-03-05 19:56:33 +0000494 def is_cftype(self):
495 return False
496
Enrico Granataeb4a4792012-02-23 23:10:27 +0000497 # we would need to go around looking for the superclass or ask the runtime
498 # for now, we seem not to require support for this operation so we will merrily
499 # pretend to be at a root point in the hierarchy
500 def get_superclass(self):
501 return None
502
503 # anything that is handled here is tagged
504 def is_tagged(self):
505 return True
506
Enrico Granatab8cbe9c2012-02-23 23:26:48 +0000507 # it seems reasonable to say that a tagged pointer is the size of a pointer
508 def instance_size(self,align=False):
Enrico Granata247bd412012-04-02 16:39:29 +0000509 logger = Logger.Logger()
Enrico Granatab8cbe9c2012-02-23 23:26:48 +0000510 if self.is_valid() == False:
511 return None
Enrico Granatacfdafa32012-03-05 19:56:33 +0000512 return self.sys_params.pointer_size
Enrico Granatab8cbe9c2012-02-23 23:26:48 +0000513
514
Enrico Granataeb4a4792012-02-23 23:10:27 +0000515class InvalidClass_Data:
516 def __init__(self):
517 pass
518 def is_valid(self):
519 return False
520
Enrico Granatacfdafa32012-03-05 19:56:33 +0000521@functools.total_ordering
522class Version:
523 def __init__(self, major, minor, release, build_string):
524 self._major = major
525 self._minor = minor
526 self._release = release
527 self._build_string = build_string
528
529 def get_major(self):
530 return self._major
531 def get_minor(self):
532 return self._minor
533 def get_release(self):
534 return self._release
535 def get_build_string(self):
536 return self._build_string
537
538 major = property(get_major,None)
539 minor = property(get_minor,None)
540 release = property(get_release,None)
541 build_string = property(get_build_string,None)
542
543 def __lt__(self,other):
544 if (self.major < other.major):
545 return True
546 if (self.minor < other.minor):
547 return True
548 if (self.release < other.release):
549 return True
550 # build strings are not compared since they are heavily platform-dependent and might not always
551 # be available
552 return False
553
554 def __eq__(self,other):
555 return (self.major == other.major) and \
556 (self.minor == other.minor) and \
557 (self.release == other.release) and \
558 (self.build_string == other.build_string)
559
Enrico Granataeb4a4792012-02-23 23:10:27 +0000560runtime_version = cache.Cache()
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000561os_version = cache.Cache()
Enrico Granatacfdafa32012-03-05 19:56:33 +0000562types_caches = cache.Cache()
563isa_caches = cache.Cache()
Enrico Granataeb4a4792012-02-23 23:10:27 +0000564
565class SystemParameters:
566 def __init__(self,valobj):
Enrico Granata247bd412012-04-02 16:39:29 +0000567 logger = Logger.Logger()
Enrico Granataeb4a4792012-02-23 23:10:27 +0000568 self.adjust_for_architecture(valobj)
Enrico Granatacfdafa32012-03-05 19:56:33 +0000569 self.adjust_for_process(valobj)
Enrico Granataeb4a4792012-02-23 23:10:27 +0000570
Enrico Granatacfdafa32012-03-05 19:56:33 +0000571 def adjust_for_process(self, valobj):
Enrico Granata247bd412012-04-02 16:39:29 +0000572 logger = Logger.Logger()
Enrico Granataeb4a4792012-02-23 23:10:27 +0000573 global runtime_version
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000574 global os_version
Enrico Granatacfdafa32012-03-05 19:56:33 +0000575 global types_caches
576 global isa_caches
577
578 process = valobj.GetTarget().GetProcess()
579 self.pid = process.GetProcessID()
580
581 if runtime_version.look_for_key(self.pid):
582 self.runtime_version = runtime_version.get_value(self.pid)
Enrico Granataeb4a4792012-02-23 23:10:27 +0000583 else:
Enrico Granatacfdafa32012-03-05 19:56:33 +0000584 self.runtime_version = ObjCRuntime.runtime_version(process)
585 runtime_version.add_item(self.pid,self.runtime_version)
586
587 if os_version.look_for_key(self.pid):
588 self.is_lion = os_version.get_value(self.pid)
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000589 else:
590 self.is_lion = Utilities.check_is_osx_lion(valobj.GetTarget())
Enrico Granatacfdafa32012-03-05 19:56:33 +0000591 os_version.add_item(self.pid,self.is_lion)
592
593 if types_caches.look_for_key(self.pid):
594 self.types_cache = types_caches.get_value(self.pid)
595 else:
596 self.types_cache = attrib_fromdict.AttributesDictionary(allow_reset=False)
597 self.types_cache.addr_type = valobj.GetType().GetBasicType(lldb.eBasicTypeUnsignedLong)
598 self.types_cache.addr_ptr_type = self.types_cache.addr_type.GetPointerType()
599 self.types_cache.uint32_t = valobj.GetType().GetBasicType(lldb.eBasicTypeUnsignedInt)
600 types_caches.add_item(self.pid,self.types_cache)
601
602 if isa_caches.look_for_key(self.pid):
603 self.isa_cache = isa_caches.get_value(self.pid)
604 else:
605 self.isa_cache = cache.Cache()
606 isa_caches.add_item(self.pid,self.isa_cache)
607
608 def adjust_for_architecture(self,valobj):
609 process = valobj.GetTarget().GetProcess()
610 self.pointer_size = process.GetAddressByteSize()
611 self.is_64_bit = (self.pointer_size == 8)
612 self.is_little = (process.GetByteOrder() == lldb.eByteOrderLittle)
Enrico Granata385ad4e2012-03-03 00:45:57 +0000613 self.cfruntime_size = 16 if self.is_64_bit else 8
Enrico Granataeb4a4792012-02-23 23:10:27 +0000614
Enrico Granatacfdafa32012-03-05 19:56:33 +0000615 # a simple helper function that makes it more explicit that one is calculating
616 # an offset that is made up of X pointers and Y bytes of additional data
617 # taking into account pointer size - if you know there is going to be some padding
618 # you can pass that in and it will be taken into account (since padding may be different between
619 # 32 and 64 bit versions, you can pass padding value for both, the right one will be used)
620 def calculate_offset(self, num_pointers = 0, bytes_count = 0, padding32 = 0, padding64 = 0):
621 value = bytes_count + num_pointers*self.pointer_size
622 return value + padding64 if self.is_64_bit else value + padding32
Enrico Granataeb4a4792012-02-23 23:10:27 +0000623
624class ObjCRuntime:
625
626 # the ObjC runtime has no explicit "version" field that we can use
627 # instead, we discriminate v1 from v2 by looking for the presence
628 # of a well-known section only present in v1
629 @staticmethod
630 def runtime_version(process):
Enrico Granata247bd412012-04-02 16:39:29 +0000631 logger = Logger.Logger()
Enrico Granataeb4a4792012-02-23 23:10:27 +0000632 if process.IsValid() == False:
Enrico Granata247bd412012-04-02 16:39:29 +0000633 logger >> "No process - bailing out"
Enrico Granataeb4a4792012-02-23 23:10:27 +0000634 return None
635 target = process.GetTarget()
636 num_modules = target.GetNumModules()
637 module_objc = None
638 for idx in range(num_modules):
639 module = target.GetModuleAtIndex(idx)
640 if module.GetFileSpec().GetFilename() == 'libobjc.A.dylib':
641 module_objc = module
642 break
643 if module_objc == None or module_objc.IsValid() == False:
Enrico Granata247bd412012-04-02 16:39:29 +0000644 logger >> "no libobjc - bailing out"
Enrico Granataeb4a4792012-02-23 23:10:27 +0000645 return None
646 num_sections = module.GetNumSections()
647 section_objc = None
648 for idx in range(num_sections):
649 section = module.GetSectionAtIndex(idx)
650 if section.GetName() == '__OBJC':
651 section_objc = section
652 break
653 if section_objc != None and section_objc.IsValid():
Enrico Granata247bd412012-04-02 16:39:29 +0000654 logger >> "found __OBJC: v1"
Enrico Granataeb4a4792012-02-23 23:10:27 +0000655 return 1
Enrico Granata247bd412012-04-02 16:39:29 +0000656 logger >> "no __OBJC: v2"
Enrico Granataeb4a4792012-02-23 23:10:27 +0000657 return 2
658
Enrico Granatabf70ee92012-03-27 21:49:20 +0000659 @staticmethod
660 def runtime_from_isa(isa):
Enrico Granata247bd412012-04-02 16:39:29 +0000661 logger = Logger.Logger()
Enrico Granatabf70ee92012-03-27 21:49:20 +0000662 runtime = ObjCRuntime(isa)
663 runtime.isa = isa
664 return runtime
665
Enrico Granataeb4a4792012-02-23 23:10:27 +0000666 def __init__(self,valobj):
Enrico Granata247bd412012-04-02 16:39:29 +0000667 logger = Logger.Logger()
Enrico Granataeb4a4792012-02-23 23:10:27 +0000668 self.valobj = valobj
669 self.adjust_for_architecture()
670 self.sys_params = SystemParameters(self.valobj)
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000671 self.unsigned_value = self.valobj.GetValueAsUnsigned()
672 self.isa_value = None
Enrico Granataeb4a4792012-02-23 23:10:27 +0000673
674 def adjust_for_architecture(self):
Enrico Granatacfdafa32012-03-05 19:56:33 +0000675 pass
Enrico Granataeb4a4792012-02-23 23:10:27 +0000676
677# an ObjC pointer can either be tagged or must be aligned
678 def is_tagged(self):
Enrico Granata247bd412012-04-02 16:39:29 +0000679 logger = Logger.Logger()
Enrico Granataeb4a4792012-02-23 23:10:27 +0000680 if self.valobj is None:
681 return False
Enrico Granatacfdafa32012-03-05 19:56:33 +0000682 return (Utilities.is_valid_pointer(self.unsigned_value,self.sys_params.pointer_size, allow_tagged=True) and \
683 not(Utilities.is_valid_pointer(self.unsigned_value,self.sys_params.pointer_size, allow_tagged=False)))
Enrico Granataeb4a4792012-02-23 23:10:27 +0000684
685 def is_valid(self):
Enrico Granata247bd412012-04-02 16:39:29 +0000686 logger = Logger.Logger()
Enrico Granataeb4a4792012-02-23 23:10:27 +0000687 if self.valobj is None:
688 return False
689 if self.valobj.IsInScope() == False:
690 return False
Enrico Granatacfdafa32012-03-05 19:56:33 +0000691 return Utilities.is_valid_pointer(self.unsigned_value,self.sys_params.pointer_size, allow_tagged=True)
Enrico Granataeb4a4792012-02-23 23:10:27 +0000692
Enrico Granata3f1052b2012-03-13 21:52:00 +0000693 def is_nil(self):
694 return self.unsigned_value == 0
695
Enrico Granataeb4a4792012-02-23 23:10:27 +0000696 def read_isa(self):
Enrico Granata247bd412012-04-02 16:39:29 +0000697 logger = Logger.Logger()
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000698 if self.isa_value != None:
Enrico Granata247bd412012-04-02 16:39:29 +0000699 logger >> "using cached isa"
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000700 return self.isa_value
Enrico Granataeb4a4792012-02-23 23:10:27 +0000701 isa_pointer = self.valobj.CreateChildAtOffset("cfisa",
702 0,
Enrico Granatacfdafa32012-03-05 19:56:33 +0000703 self.sys_params.types_cache.addr_ptr_type)
Enrico Granataeb4a4792012-02-23 23:10:27 +0000704 if isa_pointer == None or isa_pointer.IsValid() == False:
Enrico Granata247bd412012-04-02 16:39:29 +0000705 logger >> "invalid isa - bailing out"
Enrico Granataeb4a4792012-02-23 23:10:27 +0000706 return None;
707 if isa_pointer.GetValueAsUnsigned(1) == 1:
Enrico Granata247bd412012-04-02 16:39:29 +0000708 logger >> "invalid isa value - bailing out"
Enrico Granataeb4a4792012-02-23 23:10:27 +0000709 return None;
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000710 self.isa_value = isa_pointer
Enrico Granataeb4a4792012-02-23 23:10:27 +0000711 return isa_pointer
712
713 def read_class_data(self):
Enrico Granata247bd412012-04-02 16:39:29 +0000714 logger = Logger.Logger()
Enrico Granataeb4a4792012-02-23 23:10:27 +0000715 global isa_cache
716 if self.is_tagged():
717 # tagged pointers only exist in ObjC v2
718 if self.sys_params.runtime_version == 2:
Enrico Granata247bd412012-04-02 16:39:29 +0000719 logger >> "on v2 and tagged - maybe"
Enrico Granataeb4a4792012-02-23 23:10:27 +0000720 # not every odd-valued pointer is actually tagged. most are just plain wrong
721 # we could try and predetect this before even creating a TaggedClass_Data object
722 # but unless performance requires it, this seems a cleaner way to tackle the task
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000723 tentative_tagged = TaggedClass_Data(self.unsigned_value,self.sys_params)
Enrico Granata247bd412012-04-02 16:39:29 +0000724 if tentative_tagged.is_valid():
725 logger >> "truly tagged"
726 return tentative_tagged
727 else:
728 logger >> "not tagged - error"
729 return InvalidClass_Data()
Enrico Granataeb4a4792012-02-23 23:10:27 +0000730 else:
Enrico Granata247bd412012-04-02 16:39:29 +0000731 logger >> "on v1 and tagged - error"
Enrico Granataeb4a4792012-02-23 23:10:27 +0000732 return InvalidClass_Data()
733 if self.is_valid() == False:
734 return InvalidClass_Data()
735 isa = self.read_isa()
736 if isa == None:
737 return InvalidClass_Data()
738 isa_value = isa.GetValueAsUnsigned(1)
739 if isa_value == 1:
740 return InvalidClass_Data()
Enrico Granatacfdafa32012-03-05 19:56:33 +0000741 data = self.sys_params.isa_cache.get_value(isa_value,default=None)
Enrico Granataeb4a4792012-02-23 23:10:27 +0000742 if data != None:
743 return data
744 if self.sys_params.runtime_version == 2:
745 data = Class_Data_V2(isa,self.sys_params)
746 else:
747 data = Class_Data_V1(isa,self.sys_params)
748 if data == None:
749 return InvalidClass_Data()
750 if data.is_valid():
Enrico Granatacfdafa32012-03-05 19:56:33 +0000751 self.sys_params.isa_cache.add_item(isa_value,data,ok_to_replace=True)
Enrico Granataeb4a4792012-02-23 23:10:27 +0000752 return data
Enrico Granatab8cbe9c2012-02-23 23:26:48 +0000753
Enrico Granata3f1052b2012-03-13 21:52:00 +0000754# these classes below can be used by the data formatters to provide a consistent message that describes a given runtime-generated situation
755class SpecialSituation_Description:
756 def message(self):
757 return ''
758
759class InvalidPointer_Description(SpecialSituation_Description):
760
761 def __init__(self,nil):
762 self.is_nil = nil
763
764 def message(self):
765 if self.is_nil:
766 return '@"<nil>"'
767 else:
768 return '<invalid pointer>'
769
770class InvalidISA_Description(SpecialSituation_Description):
771
772 def __init__(self):
773 pass
774
775 def message(self):
776 return '<not an Objective-C object>'
777