1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
|
#!/usr/bin/python
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
argv = a.value(lldb.frame.FindVariable('argv'))\n
argv.name - return the name of the value that this object contains\n
argv.type - return the lldb.SBType for this value
argv.type_name - return the name of the type
argv.size - return the byte size of this value
argv.is_in_scope - return true if this value is currently in scope
argv.is_pointer - return true if this value is a pointer
argv.format - return the current format for this value
argv.value - return the value's value as a string
argv.summary - return a summary of this value's value
argv.description - return the runtime description for this value
argv.location - return a string that represents the values location (address, register, etc)
argv.target - return the lldb.SBTarget for this value
argv.process - return the lldb.SBProcess for this value
argv.thread - return the lldb.SBThread for this value
argv.frame - return the lldb.SBFrame for this value
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
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):
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()
if name == 'type':
return self.sbvalue.GetType()
if name == 'type_name':
return self.sbvalue.GetTypeName()
if name == 'size':
return self.sbvalue.GetByteSize()
if name == 'is_in_scope':
return self.sbvalue.IsInScope()
if name == 'is_pointer':
return self.sbvalue.TypeIsPointerType()
if name == 'format':
return self.sbvalue.GetFormat()
if name == 'value':
return self.sbvalue.GetValue()
if name == 'summary':
return self.sbvalue.GetSummary()
if name == 'description':
return self.sbvalue.GetObjectDescription()
if name == 'location':
return self.sbvalue.GetLocation()
if name == 'target':
return self.sbvalue.GetTarget()
if name == 'process':
return self.sbvalue.GetProcess()
if name == 'thread':
return self.sbvalue.GetThread()
if name == 'frame':
return self.sbvalue.GetFrame()
if name == 'num_children':
return self.sbvalue.GetNumChildren()
if name == 'children':
# 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)))
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
in your code, you would be able to do: "pt.x + pt.y"'''
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 isinstance(key, int):
return variable(
self.sbvalue.GetValueForExpressionPath(
"[%i]" %
key))
raise TypeError
def __getattr__(self, 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))
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__(self, other)
self.sbvalue.SetValueFromCString(str(result))
return result
def __irshift__(self, other):
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))
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()
|