7 """A class that wraps an lldb.SBValue object and returns an object that
8 can be used as an object with attribytes:\n
9 argv = a.value(lldb.frame.FindVariable('argv'))\n
10 argv.name - return the name of the value that this object contains\n
11 argv.type - return the lldb.SBType for this value
12 argv.type_name - return the name of the type
13 argv.size - return the byte size of this value
14 argv.is_in_scope - return true if this value is currently in scope
15 argv.is_pointer - return true if this value is a pointer
16 argv.format - return the current format for this value
17 argv.value - return the value's value as a string
18 argv.summary - return a summary of this value's value
19 argv.description - return the runtime description for this value
20 argv.location - return a string that represents the values location (address, register, etc)
21 argv.target - return the lldb.SBTarget for this value
22 argv.process - return the lldb.SBProcess for this value
23 argv.thread - return the lldb.SBThread for this value
24 argv.frame - return the lldb.SBFrame for this value
25 argv.num_children - return the number of children this value has
26 argv.children - return a list of sbvalue objects that represents all of the children of this value
29 def __init__(self
, sbvalue
):
30 self
.sbvalue
= sbvalue
32 def __nonzero__(self
):
33 return self
.sbvalue
.__nonzero
__()
36 return self
.sbvalue
.__repr
__()
39 return self
.sbvalue
.__str
__()
41 def __getitem__(self
, key
):
42 if isinstance(key
, int):
43 return value(self
.sbvalue
.GetChildAtIndex(key
, lldb
.eNoDynamicValues
, True))
46 def __getattr__(self
, name
):
48 return self
.sbvalue
.GetName()
50 return self
.sbvalue
.GetType()
51 if name
== "type_name":
52 return self
.sbvalue
.GetTypeName()
54 return self
.sbvalue
.GetByteSize()
55 if name
== "is_in_scope":
56 return self
.sbvalue
.IsInScope()
57 if name
== "is_pointer":
58 return self
.sbvalue
.TypeIsPointerType()
60 return self
.sbvalue
.GetFormat()
62 return self
.sbvalue
.GetValue()
64 return self
.sbvalue
.GetSummary()
65 if name
== "description":
66 return self
.sbvalue
.GetObjectDescription()
67 if name
== "location":
68 return self
.sbvalue
.GetLocation()
70 return self
.sbvalue
.GetTarget()
72 return self
.sbvalue
.GetProcess()
74 return self
.sbvalue
.GetThread()
76 return self
.sbvalue
.GetFrame()
77 if name
== "num_children":
78 return self
.sbvalue
.GetNumChildren()
79 if name
== "children":
80 # Returns an array of sbvalue objects, one for each child of
81 # the value for the lldb.SBValue
83 for i
in range(self
.sbvalue
.GetNumChildren()):
85 value(self
.sbvalue
.GetChildAtIndex(i
, lldb
.eNoDynamicValues
, True))
91 class variable(object):
92 '''A class that treats a lldb.SBValue and allows it to be used just as
93 a variable would be in code. So if you have a Point structure variable
94 in your code, you would be able to do: "pt.x + pt.y"'''
96 def __init__(self
, sbvalue
):
97 self
.sbvalue
= sbvalue
99 def __nonzero__(self
):
100 return self
.sbvalue
.__nonzero
__()
103 return self
.sbvalue
.__repr
__()
106 return self
.sbvalue
.__str
__()
108 def __getitem__(self
, key
):
109 # Allow array access if this value has children...
110 if isinstance(key
, int):
111 return variable(self
.sbvalue
.GetValueForExpressionPath("[%i]" % key
))
114 def __getattr__(self
, name
):
115 child_sbvalue
= self
.sbvalue
.GetChildMemberWithName(name
)
117 return variable(child_sbvalue
)
120 def __add__(self
, other
):
121 return int(self
) + int(other
)
123 def __sub__(self
, other
):
124 return int(self
) - int(other
)
126 def __mul__(self
, other
):
127 return int(self
) * int(other
)
129 def __floordiv__(self
, other
):
130 return int(self
) // int(other
)
132 def __mod__(self
, other
):
133 return int(self
) % int(other
)
135 def __divmod__(self
, other
):
136 return int(self
) % int(other
)
138 def __pow__(self
, other
):
139 return int(self
) ** int(other
)
141 def __lshift__(self
, other
):
142 return int(self
) << int(other
)
144 def __rshift__(self
, other
):
145 return int(self
) >> int(other
)
147 def __and__(self
, other
):
148 return int(self
) & int(other
)
150 def __xor__(self
, other
):
151 return int(self
) ^
int(other
)
153 def __or__(self
, other
):
154 return int(self
) |
int(other
)
156 def __div__(self
, other
):
157 return int(self
) / int(other
)
159 def __truediv__(self
, other
):
160 return int(self
) / int(other
)
162 def __iadd__(self
, other
):
163 result
= self
.__add
__(other
)
164 self
.sbvalue
.SetValueFromCString(str(result
))
167 def __isub__(self
, other
):
168 result
= self
.__sub
__(other
)
169 self
.sbvalue
.SetValueFromCString(str(result
))
172 def __imul__(self
, other
):
173 result
= self
.__mul
__(other
)
174 self
.sbvalue
.SetValueFromCString(str(result
))
177 def __idiv__(self
, other
):
178 result
= self
.__div
__(other
)
179 self
.sbvalue
.SetValueFromCString(str(result
))
182 def __itruediv__(self
, other
):
183 result
= self
.__truediv
__(other
)
184 self
.sbvalue
.SetValueFromCString(str(result
))
187 def __ifloordiv__(self
, other
):
188 result
= self
.__floordiv
__(self
, other
)
189 self
.sbvalue
.SetValueFromCString(str(result
))
192 def __imod__(self
, other
):
193 result
= self
.__and
__(self
, other
)
194 self
.sbvalue
.SetValueFromCString(str(result
))
197 def __ipow__(self
, other
):
198 result
= self
.__pow
__(self
, other
)
199 self
.sbvalue
.SetValueFromCString(str(result
))
202 def __ipow__(self
, other
, modulo
):
203 result
= self
.__pow
__(self
, other
, modulo
)
204 self
.sbvalue
.SetValueFromCString(str(result
))
207 def __ilshift__(self
, other
):
208 result
= self
.__lshift
__(self
, other
)
209 self
.sbvalue
.SetValueFromCString(str(result
))
212 def __irshift__(self
, other
):
213 result
= self
.__rshift
__(self
, other
)
214 self
.sbvalue
.SetValueFromCString(str(result
))
217 def __iand__(self
, other
):
218 result
= self
.__and
__(self
, other
)
219 self
.sbvalue
.SetValueFromCString(str(result
))
222 def __ixor__(self
, other
):
223 result
= self
.__xor
__(self
, other
)
224 self
.sbvalue
.SetValueFromCString(str(result
))
227 def __ior__(self
, other
):
228 result
= self
.__ior
__(self
, other
)
229 self
.sbvalue
.SetValueFromCString(str(result
))
239 return abs(int(self
))
241 def __invert__(self
):
244 def __complex__(self
):
245 return complex(int(self
))
248 return self
.sbvalue
.GetValueAsSigned()
251 return self
.sbvalue
.GetValueAsSigned()
254 return float(self
.sbvalue
.GetValueAsSigned())
257 return "0%o" % self
.sbvalue
.GetValueAsSigned()
260 return "0x%x" % self
.sbvalue
.GetValueAsSigned()