blob: b60f6c837a49b89b77fd7e061debf61523b0d07c [file] [log] [blame]
Enrico Granataeb4a4792012-02-23 23:10:27 +00001# a wrapper for the Objective-C runtime for use by LLDB
2import lldb
3import cache
4
5class Utilities:
6 @staticmethod
Enrico Granata7bc0ec32012-02-29 03:28:49 +00007 def read_ascii(process, pointer,max_len=128):
Enrico Granataeb4a4792012-02-23 23:10:27 +00008 error = lldb.SBError()
Enrico Granata7bc0ec32012-02-29 03:28:49 +00009 content = None
10 try:
11 content = process.ReadCStringFromMemory(pointer,max_len,error)
12 except:
13 pass
14 if content == None or len(content) == 0 or error.fail == True:
15 return None
16 return content
Enrico Granataeb4a4792012-02-23 23:10:27 +000017
18 @staticmethod
Enrico Granata7bc0ec32012-02-29 03:28:49 +000019 def is_valid_pointer(pointer, pointer_size, allow_tagged=False, allow_NULL=False):
Enrico Granataeb4a4792012-02-23 23:10:27 +000020 if pointer == None:
21 return False
22 if pointer == 0:
Enrico Granata7bc0ec32012-02-29 03:28:49 +000023 return allow_NULL
24 if allow_tagged and (pointer % 2) == 1:
25 return True
Enrico Granataeb4a4792012-02-23 23:10:27 +000026 return ((pointer % pointer_size) == 0)
27
28 # Objective-C runtime has a rule that pointers in a class_t will only have bits 0 thru 46 set
29 # so if any pointer has bits 47 thru 63 high we know that this is not a valid isa
30 @staticmethod
31 def is_allowed_pointer(pointer):
32 if pointer == None:
33 return False
Enrico Granata7bc0ec32012-02-29 03:28:49 +000034 return ((pointer & 0xFFFF800000000000) == 0)
Enrico Granataeb4a4792012-02-23 23:10:27 +000035
36 @staticmethod
37 def read_child_of(valobj,offset,type):
38 child = valobj.CreateChildAtOffset("childUNK",offset,type)
39 if child == None or child.IsValid() == False:
40 return None;
41 return child.GetValueAsUnsigned()
42
43 @staticmethod
44 def is_valid_identifier(name):
45 if name is None:
46 return None
47 if len(name) == 0:
48 return None
Enrico Granata7bc0ec32012-02-29 03:28:49 +000049 # technically, the ObjC runtime does not enforce any rules about what name a class can have
50 # in practice, the commonly used byte values for a class name are the letters, digits and some
51 # symbols: $, %, -, _, .
52 # WARNING: this means that you cannot use this runtime implementation if you need to deal
53 # with class names that use anything but what is allowed here
54 ok_values = dict.fromkeys("$%_.-ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890")
55 return all(c in ok_values for c in name)
56
57 @staticmethod
58 def check_is_osx_lion(target):
59 # assume the only thing that has a Foundation.framework is a Mac
60 # assume anything < Lion does not even exist
61 mod = target.module['Foundation']
62 if mod == None or mod.IsValid() == False:
63 return None
64 ver = mod.GetVersion()
65 if ver == None or ver == []:
66 return None
67 return (ver[0] < 900)
Enrico Granataeb4a4792012-02-23 23:10:27 +000068
69class RoT_Data:
70 def __init__(self,rot_pointer,params):
71 if (Utilities.is_valid_pointer(rot_pointer.GetValueAsUnsigned(),params.pointer_size, allow_tagged=False)):
72 self.sys_params = params
73 self.valobj = rot_pointer
Enrico Granata7bc0ec32012-02-29 03:28:49 +000074 #self.flags = Utilities.read_child_of(self.valobj,0,self.sys_params.uint32_t)
Enrico Granataeb4a4792012-02-23 23:10:27 +000075 self.instanceStart = Utilities.read_child_of(self.valobj,4,self.sys_params.uint32_t)
76 self.instanceSize = Utilities.read_child_of(self.valobj,8,self.sys_params.uint32_t)
Enrico Granata7bc0ec32012-02-29 03:28:49 +000077 offset = 24 if self.sys_params.is_64_bit else 16
78 #self.ivarLayoutPtr = Utilities.read_child_of(self.valobj,offset,self.sys_params.addr_ptr_type)
Enrico Granataeb4a4792012-02-23 23:10:27 +000079 self.namePointer = Utilities.read_child_of(self.valobj,offset,self.sys_params.addr_ptr_type)
80 self.check_valid()
81 else:
82 self.valid = False
83 if self.valid:
84 self.name = Utilities.read_ascii(self.valobj.GetTarget().GetProcess(),self.namePointer)
85 if not(Utilities.is_valid_identifier(self.name)):
86 self.valid = False
87
88 # perform sanity checks on the contents of this class_rw_t
89 def check_valid(self):
90 self.valid = True
91 # misaligned pointers seem to be possible for this field
92 #if not(Utilities.is_valid_pointer(self.namePointer,self.sys_params.pointer_size,allow_tagged=False)):
93 # self.valid = False
94 # pass
95
96 def __str__(self):
Enrico Granata7bc0ec32012-02-29 03:28:49 +000097 return \
Enrico Granataeb4a4792012-02-23 23:10:27 +000098 "instanceStart = " + hex(self.instanceStart) + "\n" + \
99 "instanceSize = " + hex(self.instanceSize) + "\n" + \
Enrico Granataeb4a4792012-02-23 23:10:27 +0000100 "namePointer = " + hex(self.namePointer) + " --> " + self.name
101
102 def is_valid(self):
103 return self.valid
104
105
106class RwT_Data:
107 def __init__(self,rwt_pointer,params):
108 if (Utilities.is_valid_pointer(rwt_pointer.GetValueAsUnsigned(),params.pointer_size, allow_tagged=False)):
109 self.sys_params = params
110 self.valobj = rwt_pointer
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000111 #self.flags = Utilities.read_child_of(self.valobj,0,self.sys_params.uint32_t)
112 #self.version = Utilities.read_child_of(self.valobj,4,self.sys_params.uint32_t)
Enrico Granataeb4a4792012-02-23 23:10:27 +0000113 self.roPointer = Utilities.read_child_of(self.valobj,8,self.sys_params.addr_ptr_type)
114 self.check_valid()
115 else:
116 self.valid = False
117 if self.valid:
118 self.rot = self.valobj.CreateValueFromAddress("rot",self.roPointer,self.sys_params.addr_ptr_type).AddressOf()
119 self.data = RoT_Data(self.rot,self.sys_params)
120
121 # perform sanity checks on the contents of this class_rw_t
122 def check_valid(self):
123 self.valid = True
124 if not(Utilities.is_valid_pointer(self.roPointer,self.sys_params.pointer_size,allow_tagged=False)):
125 self.valid = False
126
127 def __str__(self):
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000128 return \
Enrico Granataeb4a4792012-02-23 23:10:27 +0000129 "roPointer = " + hex(self.roPointer)
130
131 def is_valid(self):
132 if self.valid:
133 return self.data.is_valid()
134 return False
135
136class Class_Data_V2:
137 def __init__(self,isa_pointer,params):
138 if (isa_pointer != None) and (Utilities.is_valid_pointer(isa_pointer.GetValueAsUnsigned(),params.pointer_size, allow_tagged=False)):
139 self.sys_params = params
140 self.valobj = isa_pointer
141 self.isaPointer = Utilities.read_child_of(self.valobj,0,self.sys_params.addr_ptr_type)
142 self.superclassIsaPointer = Utilities.read_child_of(self.valobj,1*self.sys_params.pointer_size,self.sys_params.addr_ptr_type)
143 self.cachePointer = Utilities.read_child_of(self.valobj,2*self.sys_params.pointer_size,self.sys_params.addr_ptr_type)
144 self.vtablePointer = Utilities.read_child_of(self.valobj,3*self.sys_params.pointer_size,self.sys_params.addr_ptr_type)
145 self.dataPointer = Utilities.read_child_of(self.valobj,4*self.sys_params.pointer_size,self.sys_params.addr_ptr_type)
146 self.check_valid()
147 else:
148 self.valid = False
149 if self.valid:
150 self.rwt = self.valobj.CreateValueFromAddress("rwt",self.dataPointer,self.sys_params.addr_ptr_type).AddressOf()
151 self.data = RwT_Data(self.rwt,self.sys_params)
152
153 # perform sanity checks on the contents of this class_t
154 def check_valid(self):
155 self.valid = True
156 if not(Utilities.is_valid_pointer(self.isaPointer,self.sys_params.pointer_size,allow_tagged=False)):
157 self.valid = False
158 return
159 if not(Utilities.is_valid_pointer(self.superclassIsaPointer,self.sys_params.pointer_size,allow_tagged=False)):
160 # NULL is a valid value for superclass (it means we have reached NSObject)
161 if self.superclassIsaPointer != 0:
162 self.valid = False
163 return
164 if not(Utilities.is_valid_pointer(self.cachePointer,self.sys_params.pointer_size,allow_tagged=False)):
165 self.valid = False
166 return
167 if not(Utilities.is_valid_pointer(self.vtablePointer,self.sys_params.pointer_size,allow_tagged=False)):
168 self.valid = False
169 return
170 if not(Utilities.is_valid_pointer(self.dataPointer,self.sys_params.pointer_size,allow_tagged=False)):
171 self.valid = False
172 return
173 if not(Utilities.is_allowed_pointer(self.isaPointer)):
174 self.valid = False
175 return
176 if not(Utilities.is_allowed_pointer(self.superclassIsaPointer)):
177 # NULL is a valid value for superclass (it means we have reached NSObject)
178 if self.superclassIsaPointer != 0:
179 self.valid = False
180 return
181 if not(Utilities.is_allowed_pointer(self.cachePointer)):
182 self.valid = False
183 return
184 if not(Utilities.is_allowed_pointer(self.vtablePointer)):
185 self.valid = False
186 return
187 if not(Utilities.is_allowed_pointer(self.dataPointer)):
188 self.valid = False
189 return
190
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000191 # in general, KVO is implemented by transparently subclassing
192 # however, there could be exceptions where a class does something else
193 # internally to implement the feature - this method will have no clue that a class
194 # has been KVO'ed unless the standard implementation technique is used
Enrico Granataeb4a4792012-02-23 23:10:27 +0000195 def is_kvo(self):
196 if self.is_valid():
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000197 if self.class_name().startswith("NSKVONotifying_"):
Enrico Granataeb4a4792012-02-23 23:10:27 +0000198 return True
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000199 return False
Enrico Granataeb4a4792012-02-23 23:10:27 +0000200
201 def get_superclass(self):
202 if self.is_valid():
203 parent_isa_pointer = self.valobj.CreateChildAtOffset("parent_isa",
204 self.sys_params.pointer_size,
205 self.sys_params.addr_ptr_type)
206 return Class_Data_V2(parent_isa_pointer,self.sys_params)
207 else:
208 return None
209
210 def class_name(self):
211 if self.is_valid():
212 return self.data.data.name
213 else:
214 return None
215
216 def is_valid(self):
217 if self.valid:
218 return self.data.is_valid()
219 return False
220
221 def __str__(self):
222 return 'isaPointer = ' + hex(self.isaPointer) + "\n" + \
223 "superclassIsaPointer = " + hex(self.superclassIsaPointer) + "\n" + \
224 "cachePointer = " + hex(self.cachePointer) + "\n" + \
225 "vtablePointer = " + hex(self.vtablePointer) + "\n" + \
226 "data = " + hex(self.dataPointer)
227
228 def is_tagged(self):
229 return False
230
Enrico Granatab8cbe9c2012-02-23 23:26:48 +0000231 def instance_size(self,align=False):
232 if self.is_valid() == False:
233 return None
234 if align:
235 unalign = self.instance_size(False)
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000236 if self.sys_params.is_64_bit:
Enrico Granatab8cbe9c2012-02-23 23:26:48 +0000237 return ((unalign + 7) & ~7) % 0x100000000
238 else:
239 return ((unalign + 3) & ~3) % 0x100000000
240 else:
241 return self.rwt.rot.instanceSize
242
Enrico Granataeb4a4792012-02-23 23:10:27 +0000243# 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 +0000244class Class_Data_V1:
245 def __init__(self,isa_pointer,params):
246 if (isa_pointer != None) and (Utilities.is_valid_pointer(isa_pointer.GetValueAsUnsigned(),params.pointer_size, allow_tagged=False)):
247 self.sys_params = params
248 self.valobj = isa_pointer
249 self.isaPointer = Utilities.read_child_of(self.valobj,0,self.sys_params.addr_ptr_type)
250 self.superclassIsaPointer = Utilities.read_child_of(self.valobj,1*self.sys_params.pointer_size,self.sys_params.addr_ptr_type)
251 self.namePointer = Utilities.read_child_of(self.valobj,2*self.sys_params.pointer_size,self.sys_params.addr_ptr_type)
Enrico Granatab8cbe9c2012-02-23 23:26:48 +0000252 self.version = Utilities.read_child_of(self.valobj,3*self.sys_params.pointer_size,self.sys_params.addr_ptr_type)
253 self.info = Utilities.read_child_of(self.valobj,4*self.sys_params.pointer_size,self.sys_params.addr_ptr_type)
254 self.instanceSize = Utilities.read_child_of(self.valobj,5*self.sys_params.pointer_size,self.sys_params.addr_ptr_type)
Enrico Granataeb4a4792012-02-23 23:10:27 +0000255 else:
256 self.valid = False
257 if self.valid:
258 self.name = Utilities.read_ascii(self.valobj.GetTarget().GetProcess(),self.namePointer)
259 if not(Utilities.is_valid_identifier(self.name)):
260 self.valid = False
261
262 # perform sanity checks on the contents of this class_t
263 def check_valid(self):
264 self.valid = True
265 if not(Utilities.is_valid_pointer(self.isaPointer,self.sys_params.pointer_size,allow_tagged=False)):
266 self.valid = False
267 return
268 if not(Utilities.is_valid_pointer(self.superclassIsaPointer,self.sys_params.pointer_size,allow_tagged=False)):
269 # NULL is a valid value for superclass (it means we have reached NSObject)
270 if self.superclassIsaPointer != 0:
271 self.valid = False
272 return
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000273 if not(Utilities.is_valid_pointer(self.namePointer,self.sys_params.pointer_size,allow_tagged=False,allow_NULL=True)):
274 self.valid = False
275 return
Enrico Granataeb4a4792012-02-23 23:10:27 +0000276
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000277 # in general, KVO is implemented by transparently subclassing
278 # however, there could be exceptions where a class does something else
279 # internally to implement the feature - this method will have no clue that a class
280 # has been KVO'ed unless the standard implementation technique is used
Enrico Granataeb4a4792012-02-23 23:10:27 +0000281 def is_kvo(self):
282 if self.is_valid():
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000283 if self.class_name().startswith("NSKVONotifying_"):
Enrico Granataeb4a4792012-02-23 23:10:27 +0000284 return True
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000285 return False
Enrico Granataeb4a4792012-02-23 23:10:27 +0000286
287 def get_superclass(self):
288 if self.is_valid():
289 parent_isa_pointer = self.valobj.CreateChildAtOffset("parent_isa",
290 self.sys_params.pointer_size,
291 self.sys_params.addr_ptr_type)
292 return Class_Data_V1(parent_isa_pointer,self.sys_params)
293 else:
294 return None
295
296 def class_name(self):
297 if self.is_valid():
298 return self.name
299 else:
300 return None
301
302 def is_valid(self):
303 return self.valid
304
305 def __str__(self):
306 return 'isaPointer = ' + hex(self.isaPointer) + "\n" + \
307 "superclassIsaPointer = " + hex(self.superclassIsaPointer) + "\n" + \
Enrico Granatab8cbe9c2012-02-23 23:26:48 +0000308 "namePointer = " + hex(self.namePointer) + " --> " + self.name + \
309 "version = " + hex(self.version) + "\n" + \
310 "info = " + hex(self.info) + "\n" + \
311 "instanceSize = " + hex(self.instanceSize) + "\n"
Enrico Granataeb4a4792012-02-23 23:10:27 +0000312
313 def is_tagged(self):
314 return False
315
Enrico Granatab8cbe9c2012-02-23 23:26:48 +0000316 def instance_size(self,align=False):
317 if self.is_valid() == False:
318 return None
319 if align:
320 unalign = self.instance_size(False)
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000321 if self.sys_params.is_64_bit:
Enrico Granatab8cbe9c2012-02-23 23:26:48 +0000322 return ((unalign + 7) & ~7) % 0x100000000
323 else:
324 return ((unalign + 3) & ~3) % 0x100000000
325 else:
326 return self.instanceSize
327
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000328TaggedClass_Values_Lion = {3 : 'NSNumber', 6: 'NSDate'}; # double check NSDate
329TaggedClass_Values_NMOS = {3 : 'NSNumber', 6: 'NSDate'}; # double check NSNumber
330
Enrico Granataeb4a4792012-02-23 23:10:27 +0000331class TaggedClass_Data:
332 def __init__(self,pointer,params):
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000333 global TaggedClass_Values_Lion, TaggedClass_Values_NMOS
Enrico Granataeb4a4792012-02-23 23:10:27 +0000334 self.valid = True
335 self.name = None
336 self.sys_params = params
337 self.valobj = pointer
338 self.val = (pointer & ~0x0000000000000000FF) >> 8
339 self.class_bits = (pointer & 0xE) >> 1
340 self.i_bits = (pointer & 0xF0) >> 4
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000341
342 if self.sys_params.is_lion:
343 if self.class_bits in TaggedClass_Values_Lion:
344 self.name = TaggedClass_Values_Lion[self.class_bits]
345 else:
346 self.valid = False
Enrico Granataeb4a4792012-02-23 23:10:27 +0000347 else:
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000348 if self.class_bits in TaggedClass_Values_NMOS:
349 self.name = TaggedClass_Values_NMOS[self.class_bits]
350 else:
351 self.valid = False
352
Enrico Granataeb4a4792012-02-23 23:10:27 +0000353
354 def is_valid(self):
355 return self.valid
356
357 def class_name(self):
358 if self.is_valid():
359 return self.name
360 else:
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000361 return False
Enrico Granataeb4a4792012-02-23 23:10:27 +0000362
363 def value(self):
364 return self.val if self.is_valid() else None
365
366 def info_bits(self):
367 return self.i_bits if self.is_valid() else None
368
369 def is_kvo(self):
370 return False
371
372 # we would need to go around looking for the superclass or ask the runtime
373 # for now, we seem not to require support for this operation so we will merrily
374 # pretend to be at a root point in the hierarchy
375 def get_superclass(self):
376 return None
377
378 # anything that is handled here is tagged
379 def is_tagged(self):
380 return True
381
Enrico Granatab8cbe9c2012-02-23 23:26:48 +0000382 # it seems reasonable to say that a tagged pointer is the size of a pointer
383 def instance_size(self,align=False):
384 if self.is_valid() == False:
385 return None
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000386 return 8 if self.sys_params.is_64_bit else 4
Enrico Granatab8cbe9c2012-02-23 23:26:48 +0000387
388
Enrico Granataeb4a4792012-02-23 23:10:27 +0000389class InvalidClass_Data:
390 def __init__(self):
391 pass
392 def is_valid(self):
393 return False
394
395runtime_version = cache.Cache()
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000396os_version = cache.Cache()
Enrico Granataeb4a4792012-02-23 23:10:27 +0000397
398class SystemParameters:
399 def __init__(self,valobj):
400 self.adjust_for_architecture(valobj)
401
402 def adjust_for_architecture(self,valobj):
403 self.process = valobj.GetTarget().GetProcess()
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000404 self.is_64_bit = (self.process.GetAddressByteSize() == 8)
Enrico Granataeb4a4792012-02-23 23:10:27 +0000405 self.is_little = (self.process.GetByteOrder() == lldb.eByteOrderLittle)
406 self.pointer_size = self.process.GetAddressByteSize()
407 self.addr_type = valobj.GetType().GetBasicType(lldb.eBasicTypeUnsignedLong)
408 self.addr_ptr_type = self.addr_type.GetPointerType()
409 self.uint32_t = valobj.GetType().GetBasicType(lldb.eBasicTypeUnsignedInt)
410 global runtime_version
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000411 global os_version
Enrico Granataeb4a4792012-02-23 23:10:27 +0000412 pid = self.process.GetProcessID()
Enrico Granata21b22362012-02-24 19:46:04 +0000413 if runtime_version.look_for_key(pid):
Enrico Granataeb4a4792012-02-23 23:10:27 +0000414 self.runtime_version = runtime_version.get_value(pid)
415 else:
416 self.runtime_version = ObjCRuntime.runtime_version(self.process)
417 runtime_version.add_item(pid,self.runtime_version)
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000418 if os_version.look_for_key(pid):
419 self.is_lion = os_version.get_value(pid)
420 else:
421 self.is_lion = Utilities.check_is_osx_lion(valobj.GetTarget())
422 os_version.add_item(pid,self.is_lion)
Enrico Granataeb4a4792012-02-23 23:10:27 +0000423
424isa_cache = cache.Cache()
425
426class ObjCRuntime:
427
428 # the ObjC runtime has no explicit "version" field that we can use
429 # instead, we discriminate v1 from v2 by looking for the presence
430 # of a well-known section only present in v1
431 @staticmethod
432 def runtime_version(process):
433 if process.IsValid() == False:
434 return None
435 target = process.GetTarget()
436 num_modules = target.GetNumModules()
437 module_objc = None
438 for idx in range(num_modules):
439 module = target.GetModuleAtIndex(idx)
440 if module.GetFileSpec().GetFilename() == 'libobjc.A.dylib':
441 module_objc = module
442 break
443 if module_objc == None or module_objc.IsValid() == False:
444 return None
445 num_sections = module.GetNumSections()
446 section_objc = None
447 for idx in range(num_sections):
448 section = module.GetSectionAtIndex(idx)
449 if section.GetName() == '__OBJC':
450 section_objc = section
451 break
452 if section_objc != None and section_objc.IsValid():
453 return 1
454 return 2
455
456 def __init__(self,valobj):
457 self.valobj = valobj
458 self.adjust_for_architecture()
459 self.sys_params = SystemParameters(self.valobj)
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000460 self.unsigned_value = self.valobj.GetValueAsUnsigned()
461 self.isa_value = None
Enrico Granataeb4a4792012-02-23 23:10:27 +0000462
463 def adjust_for_architecture(self):
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000464 self.is_64_bit = (self.valobj.GetTarget().GetProcess().GetAddressByteSize() == 8)
Enrico Granataeb4a4792012-02-23 23:10:27 +0000465 self.is_little = (self.valobj.GetTarget().GetProcess().GetByteOrder() == lldb.eByteOrderLittle)
466 self.pointer_size = self.valobj.GetTarget().GetProcess().GetAddressByteSize()
467 self.addr_type = self.valobj.GetType().GetBasicType(lldb.eBasicTypeUnsignedLong)
468 self.addr_ptr_type = self.addr_type.GetPointerType()
469
470# an ObjC pointer can either be tagged or must be aligned
471 def is_tagged(self):
472 if self.valobj is None:
473 return False
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000474 return (Utilities.is_valid_pointer(self.unsigned_value,self.pointer_size, allow_tagged=True) and \
475 not(Utilities.is_valid_pointer(self.unsigned_value,self.pointer_size, allow_tagged=False)))
Enrico Granataeb4a4792012-02-23 23:10:27 +0000476
477 def is_valid(self):
478 if self.valobj is None:
479 return False
480 if self.valobj.IsInScope() == False:
481 return False
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000482 return Utilities.is_valid_pointer(self.unsigned_value,self.pointer_size, allow_tagged=True)
Enrico Granataeb4a4792012-02-23 23:10:27 +0000483
484 def read_isa(self):
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000485 if self.isa_value != None:
486 return self.isa_value
Enrico Granataeb4a4792012-02-23 23:10:27 +0000487 isa_pointer = self.valobj.CreateChildAtOffset("cfisa",
488 0,
489 self.addr_ptr_type)
490 if isa_pointer == None or isa_pointer.IsValid() == False:
491 return None;
492 if isa_pointer.GetValueAsUnsigned(1) == 1:
493 return None;
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000494 self.isa_value = isa_pointer
Enrico Granataeb4a4792012-02-23 23:10:27 +0000495 return isa_pointer
496
497 def read_class_data(self):
498 global isa_cache
499 if self.is_tagged():
500 # tagged pointers only exist in ObjC v2
501 if self.sys_params.runtime_version == 2:
502 # not every odd-valued pointer is actually tagged. most are just plain wrong
503 # we could try and predetect this before even creating a TaggedClass_Data object
504 # but unless performance requires it, this seems a cleaner way to tackle the task
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000505 tentative_tagged = TaggedClass_Data(self.unsigned_value,self.sys_params)
Enrico Granataeb4a4792012-02-23 23:10:27 +0000506 return tentative_tagged if tentative_tagged.is_valid() else InvalidClass_Data()
507 else:
508 return InvalidClass_Data()
509 if self.is_valid() == False:
510 return InvalidClass_Data()
511 isa = self.read_isa()
512 if isa == None:
513 return InvalidClass_Data()
514 isa_value = isa.GetValueAsUnsigned(1)
515 if isa_value == 1:
516 return InvalidClass_Data()
517 data = isa_cache.get_value(isa_value,default=None)
518 if data != None:
519 return data
520 if self.sys_params.runtime_version == 2:
521 data = Class_Data_V2(isa,self.sys_params)
522 else:
523 data = Class_Data_V1(isa,self.sys_params)
524 if data == None:
525 return InvalidClass_Data()
526 if data.is_valid():
527 isa_cache.add_item(isa_value,data,ok_to_replace=True)
528 return data
Enrico Granatab8cbe9c2012-02-23 23:26:48 +0000529