summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2012-02-01 01:46:19 +0000
committerGreg Clayton <gclayton@apple.com>2012-02-01 01:46:19 +0000
commit05e8d1944678f1dc07667e60be5975c127db1ced (patch)
treeb9bb1beda66cd2b8280764a112ccbb4539de724f
parent7bb0067c06ef896092448f14de390b7b485c5c3d (diff)
downloadbcm5719-llvm-05e8d1944678f1dc07667e60be5975c127db1ced.tar.gz
bcm5719-llvm-05e8d1944678f1dc07667e60be5975c127db1ced.zip
Added a new class to the lldb python module:
lldb.value() It it designed to be given a lldb.SBValue object and it allows natural use of a variable value: pt = lldb.value(lldb.frame.FindVariable("pt")) print pt print pt.x print pt.y pt = lldb.frame.FindVariable("rectangle_array") print rectangle_array[12] print rectangle_array[5].origin.x Note that array access works just fine and works on arrays or pointers: pt = lldb.frame.FindVariable("point_ptr") print point_ptr[5].y Also note that pointer child accesses are done using a "." instead of "->": print point_ptr.x llvm-svn: 149464
-rw-r--r--lldb/scripts/Python/python-extensions.swig184
-rw-r--r--lldb/source/Target/ObjCLanguageRuntime.cpp2
2 files changed, 185 insertions, 1 deletions
diff --git a/lldb/scripts/Python/python-extensions.swig b/lldb/scripts/Python/python-extensions.swig
index c50e43db9f0..e0ddbebd2d6 100644
--- a/lldb/scripts/Python/python-extensions.swig
+++ b/lldb/scripts/Python/python-extensions.swig
@@ -182,3 +182,187 @@
}
}
+%pythoncode %{
+
+class value(object):
+ '''A class designed to wrap lldb.SBValue() objects so the resulting object
+ can be used as a variable would be in code. So if you have a Point structure
+ variable in your code in the current frame named "pt", you can initialize an instance
+ of this class with it:
+
+ pt = lldb.value(lldb.frame.FindVariable("pt"))
+ print pt
+ print pt.x
+ print pt.y
+
+ pt = lldb.value(lldb.frame.FindVariable("rectangle_array"))
+ print rectangle_array[12]
+ print rectangle_array[5].origin.x'''
+ def __init__(self, sbvalue):
+ self.sbvalue = sbvalue
+
+ def __nonzero__(self):
+ return self.sbvalue.__nonzero__()
+
+ def __repr__(self):
+ return self.sbvalue.__repr__()
+
+ def __str__(self):
+ return self.sbvalue.__str__()
+
+ def __getitem__(self, key):
+ # Allow array access if this value has children...
+ if type(key) is int:
+ return value(self.sbvalue.GetValueForExpressionPath("[%i]" % key))
+ raise TypeError
+
+ def __getattr__(self, name):
+ child_sbvalue = self.sbvalue.GetChildMemberWithName (name)
+ if child_sbvalue:
+ return value(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))
+ return result
+
+ def __isub__(self, other):
+ result = self.__sub__(other)
+ self.sbvalue.SetValueFromCString (str(result))
+ return result
+
+ def __imul__(self, other):
+ result = self.__mul__(other)
+ self.sbvalue.SetValueFromCString (str(result))
+ return result
+
+ def __idiv__(self, other):
+ result = self.__div__(other)
+ self.sbvalue.SetValueFromCString (str(result))
+ return result
+
+ def __itruediv__(self, other):
+ result = self.__truediv__(other)
+ self.sbvalue.SetValueFromCString (str(result))
+ return result
+
+ def __ifloordiv__(self, other):
+ 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))
+ return result
+
+ def __ipow__(self, other):
+ result = self.__pow__(self, other)
+ self.sbvalue.SetValueFromCString (str(result))
+ return result
+
+ def __ipow__(self, other, modulo):
+ result = self.__pow__(self, other, modulo)
+ self.sbvalue.SetValueFromCString (str(result))
+ return result
+
+ def __ilshift__(self, other):
+ result = self.__lshift__(other)
+ self.sbvalue.SetValueFromCString (str(result))
+ return result
+
+ def __irshift__(self, other):
+ result = self.__rshift__(other)
+ self.sbvalue.SetValueFromCString (str(result))
+ return result
+
+ def __iand__(self, other):
+ 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))
+ return result
+
+ def __ior__(self, other):
+ 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))
+
+ def __int__(self):
+ return self.sbvalue.GetValueAsSigned()
+
+ def __long__(self):
+ return self.sbvalue.GetValueAsSigned()
+
+ def __float__(self):
+ return float (self.sbvalue.GetValueAsSigned())
+
+ def __oct__(self):
+ return '0%o' % self.sbvalue.GetValueAsSigned()
+
+ def __hex__(self):
+ return '0x%x' % self.sbvalue.GetValueAsSigned()
+
+%}
+
diff --git a/lldb/source/Target/ObjCLanguageRuntime.cpp b/lldb/source/Target/ObjCLanguageRuntime.cpp
index bc9bee79768..00d3aa4f47f 100644
--- a/lldb/source/Target/ObjCLanguageRuntime.cpp
+++ b/lldb/source/Target/ObjCLanguageRuntime.cpp
@@ -1,4 +1,4 @@
-//===-- CPPLanguageRuntime.cpp -------------------------------------------------*- C++ -*-===//
+//===-- ObjCLanguageRuntime.cpp ---------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
OpenPOWER on IntegriCloud