1 %extend lldb::SBBreakpoint {
4 if not isinstance(rhs, type(self)):
7 return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs)
10 if not isinstance(rhs, type(self)):
13 return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs)
17 %extend lldb::SBBroadcaster {
19 def __eq__(self, rhs):
20 if not isinstance(rhs, type(self)):
23 return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs)
25 def __ne__(self, rhs):
26 if not isinstance(rhs, type(self)):
29 return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs)
33 %extend lldb::SBCommandReturnObject {
34 /* the write() and flush() calls are not part of the SB API proper, and are solely for Python usage
35 they are meant to make an SBCommandReturnObject into a file-like object so that instructions of the sort
36 print >>sb_command_return_object, "something"
37 will work correctly */
39 void lldb::SBCommandReturnObject::write (const char* str)
42 $self->Printf("%s",str);
44 void lldb::SBCommandReturnObject::flush ()
48 %extend lldb::SBCompileUnit {
50 def __eq__(self, rhs):
51 if not isinstance(rhs, type(self)):
54 return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs)
56 def __ne__(self, rhs):
57 if not isinstance(rhs, type(self)):
60 return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs)
64 %extend lldb::SBDeclaration {
66 def __eq__(self, rhs):
67 if not isinstance(rhs, type(self)):
70 return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs)
72 def __ne__(self, rhs):
73 if not isinstance(rhs, type(self)):
76 return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs)
80 %extend lldb::SBFunction {
82 def __eq__(self, rhs):
83 if not isinstance(rhs, type(self)):
86 return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs)
88 def __ne__(self, rhs):
89 if not isinstance(rhs, type(self)):
92 return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs)
96 %extend lldb::SBLineEntry {
98 def __eq__(self, rhs):
99 if not isinstance(rhs, type(self)):
102 return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs)
104 def __ne__(self, rhs):
105 if not isinstance(rhs, type(self)):
108 return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs)
112 %extend lldb::SBModule {
114 def __eq__(self, rhs):
115 if not isinstance(rhs, type(self)):
118 return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs)
120 def __ne__(self, rhs):
121 if not isinstance(rhs, type(self)):
124 return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs)
128 %extend lldb::SBSection {
130 def __eq__(self, rhs):
131 if not isinstance(rhs, type(self)):
134 return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs)
136 def __ne__(self, rhs):
137 if not isinstance(rhs, type(self)):
140 return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs)
143 %extend lldb::SBStream {
144 /* the write() and flush() calls are not part of the SB API proper, and are solely for Python usage
145 they are meant to make an SBStream into a file-like object so that instructions of the sort
146 print >>sb_stream, "something"
147 will work correctly */
149 void lldb::SBStream::write (const char* str)
152 $self->Printf("%s",str);
154 void lldb::SBStream::flush ()
157 %extend lldb::SBSymbol {
159 def __eq__(self, rhs):
160 if not isinstance(rhs, type(self)):
163 return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs)
165 def __ne__(self, rhs):
166 if not isinstance(rhs, type(self)):
169 return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs)
173 %extend lldb::SBTarget {
175 def __eq__(self, rhs):
176 if not isinstance(rhs, type(self)):
179 return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs)
181 def __ne__(self, rhs):
182 if not isinstance(rhs, type(self)):
185 return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs)
189 %extend lldb::SBTypeFilter {
191 def __eq__(self, rhs):
192 if not isinstance(rhs, type(self)):
195 return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs)
197 def __ne__(self, rhs):
198 if not isinstance(rhs, type(self)):
201 return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs)
205 %extend lldb::SBTypeNameSpecifier {
207 def __eq__(self, rhs):
208 if not isinstance(rhs, type(self)):
211 return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs)
213 def __ne__(self, rhs):
214 if not isinstance(rhs, type(self)):
217 return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs)
221 %extend lldb::SBTypeSummary {
223 def __eq__(self, rhs):
224 if not isinstance(rhs, type(self)):
227 return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs)
229 def __ne__(self, rhs):
230 if not isinstance(rhs, type(self)):
233 return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs)
237 %extend lldb::SBTypeSynthetic {
239 def __eq__(self, rhs):
240 if not isinstance(rhs, type(self)):
243 return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs)
245 def __ne__(self, rhs):
246 if not isinstance(rhs, type(self)):
249 return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs)
253 %extend lldb::SBThread {
255 def __eq__(self, rhs):
256 if not isinstance(rhs, type(self)):
259 return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs)
261 def __ne__(self, rhs):
262 if not isinstance(rhs, type(self)):
265 return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs)
271 def command(command_name=None, doc=None):
273 """A decorator function that registers an LLDB command line
274 command that is bound to the function it is attached to."""
275 def callable(function):
276 """Registers an lldb command for the decorated function."""
277 command = "command script add -f %s.%s %s" % (function.__module__, function.__name__, command_name or function.__name__)
278 lldb.debugger.HandleCommand(command)
280 function.__doc__ = doc
285 class declaration(object):
286 '''A class that represents a source declaration location with file, line and column.'''
287 def __init__(self, file, line, col):
292 class value_iter(object):
297 if self.index >= self.length:
298 raise StopIteration()
299 child_sbvalue = self.sbvalue.GetChildAtIndex(self.index)
301 return value(child_sbvalue)
304 return self.__next__()
306 def __init__(self,value):
309 if type(self.sbvalue) is value:
310 self.sbvalue = self.sbvalue.sbvalue
311 self.length = self.sbvalue.GetNumChildren()
314 '''A class designed to wrap lldb.SBValue() objects so the resulting object
315 can be used as a variable would be in code. So if you have a Point structure
316 variable in your code in the current frame named "pt", you can initialize an instance
317 of this class with it:
319 pt = lldb.value(lldb.frame.FindVariable("pt"))
324 pt = lldb.value(lldb.frame.FindVariable("rectangle_array"))
325 print rectangle_array[12]
326 print rectangle_array[5].origin.x'''
327 def __init__(self, sbvalue):
328 self.sbvalue = sbvalue
330 def __nonzero__(self):
331 return self.sbvalue.__nonzero__()
334 return self.sbvalue.__bool__()
337 return self.sbvalue.__str__()
339 def __getitem__(self, key):
340 # Allow array access if this value has children...
341 if type(key) is value:
344 child_sbvalue = (self.sbvalue.GetValueForExpressionPath("[%i]" % key))
345 if child_sbvalue and child_sbvalue.IsValid():
346 return value(child_sbvalue)
347 raise IndexError("Index '%d' is out of range" % key)
348 raise TypeError("No array item of type %s" % str(type(key)))
351 return value_iter(self.sbvalue)
353 def __getattr__(self, name):
354 child_sbvalue = self.sbvalue.GetChildMemberWithName (name)
355 if child_sbvalue and child_sbvalue.IsValid():
356 return value(child_sbvalue)
357 raise AttributeError("Attribute '%s' is not defined" % name)
359 def __add__(self, other):
360 return int(self) + int(other)
362 def __sub__(self, other):
363 return int(self) - int(other)
365 def __mul__(self, other):
366 return int(self) * int(other)
368 def __floordiv__(self, other):
369 return int(self) // int(other)
371 def __mod__(self, other):
372 return int(self) % int(other)
374 def __divmod__(self, other):
375 return int(self) % int(other)
377 def __pow__(self, other):
378 return int(self) ** int(other)
380 def __lshift__(self, other):
381 return int(self) << int(other)
383 def __rshift__(self, other):
384 return int(self) >> int(other)
386 def __and__(self, other):
387 return int(self) & int(other)
389 def __xor__(self, other):
390 return int(self) ^ int(other)
392 def __or__(self, other):
393 return int(self) | int(other)
395 def __div__(self, other):
396 return int(self) / int(other)
398 def __truediv__(self, other):
399 return int(self) / int(other)
401 def __iadd__(self, other):
402 result = self.__add__(other)
403 self.sbvalue.SetValueFromCString (str(result))
406 def __isub__(self, other):
407 result = self.__sub__(other)
408 self.sbvalue.SetValueFromCString (str(result))
411 def __imul__(self, other):
412 result = self.__mul__(other)
413 self.sbvalue.SetValueFromCString (str(result))
416 def __idiv__(self, other):
417 result = self.__div__(other)
418 self.sbvalue.SetValueFromCString (str(result))
421 def __itruediv__(self, other):
422 result = self.__truediv__(other)
423 self.sbvalue.SetValueFromCString (str(result))
426 def __ifloordiv__(self, other):
427 result = self.__floordiv__(self, other)
428 self.sbvalue.SetValueFromCString (str(result))
431 def __imod__(self, other):
432 result = self.__and__(self, other)
433 self.sbvalue.SetValueFromCString (str(result))
436 def __ipow__(self, other):
437 result = self.__pow__(self, other)
438 self.sbvalue.SetValueFromCString (str(result))
441 def __ipow__(self, other, modulo):
442 result = self.__pow__(self, other, modulo)
443 self.sbvalue.SetValueFromCString (str(result))
446 def __ilshift__(self, other):
447 result = self.__lshift__(other)
448 self.sbvalue.SetValueFromCString (str(result))
451 def __irshift__(self, other):
452 result = self.__rshift__(other)
453 self.sbvalue.SetValueFromCString (str(result))
456 def __iand__(self, other):
457 result = self.__and__(self, other)
458 self.sbvalue.SetValueFromCString (str(result))
461 def __ixor__(self, other):
462 result = self.__xor__(self, other)
463 self.sbvalue.SetValueFromCString (str(result))
466 def __ior__(self, other):
467 result = self.__ior__(self, other)
468 self.sbvalue.SetValueFromCString (str(result))
478 return abs(int(self))
480 def __invert__(self):
483 def __complex__(self):
484 return complex (int(self))
487 is_num,is_sign = is_numeric_type(self.sbvalue.GetType().GetCanonicalType().GetBasicType())
488 if is_num and not is_sign: return self.sbvalue.GetValueAsUnsigned()
489 return self.sbvalue.GetValueAsSigned()
492 return self.__int__()
495 return float (self.sbvalue.GetValueAsSigned())
498 return '0%o' % self.sbvalue.GetValueAsUnsigned()
501 return '0x%x' % self.sbvalue.GetValueAsUnsigned()
504 return self.sbvalue.GetNumChildren()
506 def __eq__(self, other):
507 if type(other) is int:
508 return int(self) == other
509 elif type(other) is str:
510 return str(self) == other
511 elif type(other) is value:
513 other_err = SBError()
514 self_val = self.sbvalue.GetValueAsUnsigned(self_err)
516 raise ValueError("unable to extract value of self")
517 other_val = other.sbvalue.GetValueAsUnsigned(other_err)
519 raise ValueError("unable to extract value of other")
520 return self_val == other_val
521 raise TypeError("Unknown type %s, No equality operation defined." % str(type(other)))
523 def __ne__(self, other):
524 return not self.__eq__(other)
529 class SBSyntheticValueProvider(object):
530 def __init__(self,valobj):
533 def num_children(self):
536 def get_child_index(self,name):
539 def get_child_at_index(self,idx):
545 def has_children(self):
553 # given an lldb.SBBasicType it returns a tuple
554 # (is_numeric, is_signed)
555 # the value of is_signed is undefined if is_numeric == false
556 def is_numeric_type(basic_type):
557 if basic_type == eBasicTypeInvalid: return (False,False)
558 if basic_type == eBasicTypeVoid: return (False,False)
559 if basic_type == eBasicTypeChar: return (True,False)
560 if basic_type == eBasicTypeSignedChar: return (True,True)
561 if basic_type == eBasicTypeUnsignedChar: return (True,False)
562 if basic_type == eBasicTypeWChar: return (True,False)
563 if basic_type == eBasicTypeSignedWChar: return (True,True)
564 if basic_type == eBasicTypeUnsignedWChar: return (True,False)
565 if basic_type == eBasicTypeChar16: return (True,False)
566 if basic_type == eBasicTypeChar32: return (True,False)
567 if basic_type == eBasicTypeShort: return (True,True)
568 if basic_type == eBasicTypeUnsignedShort: return (True,False)
569 if basic_type == eBasicTypeInt: return (True,True)
570 if basic_type == eBasicTypeUnsignedInt: return (True,False)
571 if basic_type == eBasicTypeLong: return (True,True)
572 if basic_type == eBasicTypeUnsignedLong: return (True,False)
573 if basic_type == eBasicTypeLongLong: return (True,True)
574 if basic_type == eBasicTypeUnsignedLongLong: return (True,False)
575 if basic_type == eBasicTypeInt128: return (True,True)
576 if basic_type == eBasicTypeUnsignedInt128: return (True,False)
577 if basic_type == eBasicTypeBool: return (False,False)
578 if basic_type == eBasicTypeHalf: return (True,True)
579 if basic_type == eBasicTypeFloat: return (True,True)
580 if basic_type == eBasicTypeDouble: return (True,True)
581 if basic_type == eBasicTypeLongDouble: return (True,True)
582 if basic_type == eBasicTypeFloatComplex: return (True,True)
583 if basic_type == eBasicTypeDoubleComplex: return (True,True)
584 if basic_type == eBasicTypeLongDoubleComplex: return (True,True)
585 if basic_type == eBasicTypeObjCID: return (False,False)
586 if basic_type == eBasicTypeObjCClass: return (False,False)
587 if basic_type == eBasicTypeObjCSel: return (False,False)
588 if basic_type == eBasicTypeNullPtr: return (False,False)
589 #if basic_type == eBasicTypeOther: