diff options
Diffstat (limited to 'examples/python/sbvalue.py')
| -rwxr-xr-x | examples/python/sbvalue.py | 165 | 
1 files changed, 89 insertions, 76 deletions
| diff --git a/examples/python/sbvalue.py b/examples/python/sbvalue.py index 59c0b61e5528..6e512998da2f 100755 --- a/examples/python/sbvalue.py +++ b/examples/python/sbvalue.py @@ -2,6 +2,7 @@  import lldb +  class value(object):      '''A class that wraps an lldb.SBValue object and returns an object that      can be used as an object with attribytes:\n @@ -24,6 +25,7 @@ class value(object):      argv.num_children - return the number of children this value has      argv.children - return a list of sbvalue objects that represents all of the children of this value      ''' +      def __init__(self, sbvalue):          self.sbvalue = sbvalue @@ -37,10 +39,12 @@ class value(object):          return self.sbvalue.__str__()      def __getitem__(self, key): -        if type(key) is int: -            return value(self.sbvalue.GetChildAtIndex(key, lldb.eNoDynamicValues, True)) +        if isinstance(key, int): +            return value( +                self.sbvalue.GetChildAtIndex( +                    key, lldb.eNoDynamicValues, True))          raise TypeError -     +      def __getattr__(self, name):          if name == 'name':              return self.sbvalue.GetName() @@ -55,15 +59,15 @@ class value(object):          if name == 'is_pointer':              return self.sbvalue.TypeIsPointerType()          if name == 'format': -            return self.sbvalue.GetFormat () +            return self.sbvalue.GetFormat()          if name == 'value': -            return self.sbvalue.GetValue () +            return self.sbvalue.GetValue()          if name == 'summary': -            return self.sbvalue.GetSummary () +            return self.sbvalue.GetSummary()          if name == 'description': -            return self.sbvalue.GetObjectDescription () +            return self.sbvalue.GetObjectDescription()          if name == 'location': -            return self.sbvalue.GetLocation () +            return self.sbvalue.GetLocation()          if name == 'target':              return self.sbvalue.GetTarget()          if name == 'process': @@ -75,18 +79,25 @@ class value(object):          if name == 'num_children':              return self.sbvalue.GetNumChildren()          if name == 'children': -            # Returns an array of sbvalue objects, one for each child of  +            # Returns an array of sbvalue objects, one for each child of              # the value for the lldb.SBValue              children = [] -            for i in range (self.sbvalue.GetNumChildren()): -                children.append(value(self.sbvalue.GetChildAtIndex(i, lldb.eNoDynamicValues, True))) +            for i in range(self.sbvalue.GetNumChildren()): +                children.append( +                    value( +                        self.sbvalue.GetChildAtIndex( +                            i, +                            lldb.eNoDynamicValues, +                            True)))              return children          raise AttributeError -     + +  class variable(object):      '''A class that treats a lldb.SBValue and allows it to be used just as -    a variable would be in code. So if you have a Point structure variable  +    a variable would be in code. So if you have a Point structure variable      in your code, you would be able to do: "pt.x + pt.y"''' +      def __init__(self, sbvalue):          self.sbvalue = sbvalue @@ -101,155 +112,157 @@ class variable(object):      def __getitem__(self, key):          # Allow array access if this value has children... -        if type(key) is int: -            return variable(self.sbvalue.GetValueForExpressionPath("[%i]" % key)) +        if isinstance(key, int): +            return variable( +                self.sbvalue.GetValueForExpressionPath( +                    "[%i]" % +                    key))          raise TypeError      def __getattr__(self, name): -        child_sbvalue = self.sbvalue.GetChildMemberWithName (name) +        child_sbvalue = self.sbvalue.GetChildMemberWithName(name)          if child_sbvalue:              return variable(child_sbvalue)          raise AttributeError      def __add__(self, other):          return int(self) + int(other) -         +      def __sub__(self, other):          return int(self) - int(other) -         +      def __mul__(self, other):          return int(self) * int(other) -         +      def __floordiv__(self, other):          return int(self) // int(other) -         +      def __mod__(self, other):          return int(self) % int(other) -         +      def __divmod__(self, other):          return int(self) % int(other) -         +      def __pow__(self, other):          return int(self) ** int(other) -         +      def __lshift__(self, other):          return int(self) << int(other) -         +      def __rshift__(self, other):          return int(self) >> int(other) -         +      def __and__(self, other):          return int(self) & int(other) -         +      def __xor__(self, other):          return int(self) ^ int(other) -         +      def __or__(self, other):          return int(self) | int(other) -         +      def __div__(self, other):          return int(self) / int(other) -         +      def __truediv__(self, other):          return int(self) / int(other) -         +      def __iadd__(self, other):          result = self.__add__(other) -        self.sbvalue.SetValueFromCString (str(result)) +        self.sbvalue.SetValueFromCString(str(result))          return result -         +      def __isub__(self, other):          result = self.__sub__(other) -        self.sbvalue.SetValueFromCString (str(result)) +        self.sbvalue.SetValueFromCString(str(result))          return result -         +      def __imul__(self, other):          result = self.__mul__(other) -        self.sbvalue.SetValueFromCString (str(result)) +        self.sbvalue.SetValueFromCString(str(result))          return result -         +      def __idiv__(self, other):          result = self.__div__(other) -        self.sbvalue.SetValueFromCString (str(result)) +        self.sbvalue.SetValueFromCString(str(result))          return result -         +      def __itruediv__(self, other):          result = self.__truediv__(other) -        self.sbvalue.SetValueFromCString (str(result)) +        self.sbvalue.SetValueFromCString(str(result))          return result -         +      def __ifloordiv__(self, other): -        result =  self.__floordiv__(self, other) -        self.sbvalue.SetValueFromCString (str(result)) +        result = self.__floordiv__(self, other) +        self.sbvalue.SetValueFromCString(str(result))          return result -         +      def __imod__(self, other): -        result =  self.__and__(self, other) -        self.sbvalue.SetValueFromCString (str(result)) +        result = self.__and__(self, other) +        self.sbvalue.SetValueFromCString(str(result))          return result -         +      def __ipow__(self, other):          result = self.__pow__(self, other) -        self.sbvalue.SetValueFromCString (str(result)) +        self.sbvalue.SetValueFromCString(str(result))          return result -         +      def __ipow__(self, other, modulo):          result = self.__pow__(self, other, modulo) -        self.sbvalue.SetValueFromCString (str(result)) +        self.sbvalue.SetValueFromCString(str(result))          return result -         +      def __ilshift__(self, other):          result = self.__lshift__(self, other) -        self.sbvalue.SetValueFromCString (str(result)) +        self.sbvalue.SetValueFromCString(str(result))          return result -         +      def __irshift__(self, other): -        result =  self.__rshift__(self, other) -        self.sbvalue.SetValueFromCString (str(result)) +        result = self.__rshift__(self, other) +        self.sbvalue.SetValueFromCString(str(result))          return result -         +      def __iand__(self, other): -        result =  self.__and__(self, other) -        self.sbvalue.SetValueFromCString (str(result)) +        result = self.__and__(self, other) +        self.sbvalue.SetValueFromCString(str(result))          return result -         +      def __ixor__(self, other): -        result =  self.__xor__(self, other) -        self.sbvalue.SetValueFromCString (str(result)) +        result = self.__xor__(self, other) +        self.sbvalue.SetValueFromCString(str(result))          return result -         +      def __ior__(self, other): -        result =  self.__ior__(self, other) -        self.sbvalue.SetValueFromCString (str(result)) +        result = self.__ior__(self, other) +        self.sbvalue.SetValueFromCString(str(result))          return result -         +      def __neg__(self):          return -int(self) -         +      def __pos__(self):          return +int(self) -         +      def __abs__(self):          return abs(int(self)) -         +      def __invert__(self):          return ~int(self) -         +      def __complex__(self): -        return complex (int(self)) -         +        return complex(int(self)) +      def __int__(self):          return self.sbvalue.GetValueAsSigned() -         +      def __long__(self):          return self.sbvalue.GetValueAsSigned() -         +      def __float__(self): -        return float (self.sbvalue.GetValueAsSigned()) -         +        return float(self.sbvalue.GetValueAsSigned()) +      def __oct__(self):          return '0%o' % self.sbvalue.GetValueAsSigned() -         +      def __hex__(self):          return '0x%x' % self.sbvalue.GetValueAsSigned() -    
\ No newline at end of file | 
