blob: e0ddbebd2d6e5f6c3172b760c45265a3ff3c79c7 [file] [log] [blame]
Caroline Ticee49ec182010-09-22 23:01:29 +00001
2%extend lldb::SBAddress {
3 PyObject *lldb::SBAddress::__repr__ (){
4 lldb::SBStream description;
5 $self->GetDescription (description);
6 return PyString_FromString (description.GetData());
7 }
8}
9%extend lldb::SBBlock {
10 PyObject *lldb::SBBlock::__repr__ (){
11 lldb::SBStream description;
12 $self->GetDescription (description);
13 return PyString_FromString (description.GetData());
14 }
15}
16%extend lldb::SBBreakpoint {
17 PyObject *lldb::SBBreakpoint::__repr__ (){
18 lldb::SBStream description;
Greg Claytond8c62532010-10-07 04:19:01 +000019 $self->GetDescription (description);
Caroline Ticee49ec182010-09-22 23:01:29 +000020 return PyString_FromString (description.GetData());
21 }
22}
23%extend lldb::SBBreakpointLocation {
24 PyObject *lldb::SBBreakpointLocation::__repr__ (){
25 lldb::SBStream description;
Johnny Chenbdc36bd2011-04-25 20:23:05 +000026 $self->GetDescription (description, lldb::eDescriptionLevelFull);
Caroline Ticee49ec182010-09-22 23:01:29 +000027 return PyString_FromString (description.GetData());
28 }
29}
30%extend lldb::SBCommandReturnObject {
31 PyObject *lldb::SBCommandReturnObject::__repr__ (){
32 lldb::SBStream description;
33 $self->GetDescription (description);
34 return PyString_FromString (description.GetData());
35 }
36}
37%extend lldb::SBCompileUnit {
38 PyObject *lldb::SBCompileUnit::__repr__ (){
39 lldb::SBStream description;
40 $self->GetDescription (description);
41 return PyString_FromString (description.GetData());
42 }
43}
Enrico Granata91544802011-09-06 19:20:51 +000044%extend lldb::SBData {
45 PyObject *lldb::SBData::__repr__ (){
46 lldb::SBStream description;
47 $self->GetDescription (description);
48 return PyString_FromString (description.GetData());
49 }
50}
Caroline Ticee49ec182010-09-22 23:01:29 +000051%extend lldb::SBDebugger {
52 PyObject *lldb::SBDebugger::__repr__ (){
53 lldb::SBStream description;
54 $self->GetDescription (description);
55 return PyString_FromString (description.GetData());
56 }
57}
58%extend lldb::SBError {
59 PyObject *lldb::SBError::__repr__ (){
60 lldb::SBStream description;
61 $self->GetDescription (description);
62 return PyString_FromString (description.GetData());
63 }
64}
65%extend lldb::SBFileSpec {
66 PyObject *lldb::SBFileSpec::__repr__ (){
67 lldb::SBStream description;
68 $self->GetDescription (description);
69 return PyString_FromString (description.GetData());
70 }
71}
72%extend lldb::SBFrame {
73 PyObject *lldb::SBFrame::__repr__ (){
74 lldb::SBStream description;
75 $self->GetDescription (description);
76 return PyString_FromString (description.GetData());
77 }
78}
79%extend lldb::SBFunction {
80 PyObject *lldb::SBFunction::__repr__ (){
81 lldb::SBStream description;
82 $self->GetDescription (description);
83 return PyString_FromString (description.GetData());
84 }
85}
Greg Clayton5c4c7462010-10-06 03:09:58 +000086%extend lldb::SBInstruction {
87 PyObject *lldb::SBInstruction::__repr__ (){
88 lldb::SBStream description;
89 $self->GetDescription (description);
90 return PyString_FromString (description.GetData());
91 }
92}
93%extend lldb::SBInstructionList {
94 PyObject *lldb::SBInstructionList::__repr__ (){
95 lldb::SBStream description;
96 $self->GetDescription (description);
97 return PyString_FromString (description.GetData());
98 }
99}
Caroline Ticee49ec182010-09-22 23:01:29 +0000100%extend lldb::SBLineEntry {
101 PyObject *lldb::SBLineEntry::__repr__ (){
102 lldb::SBStream description;
103 $self->GetDescription (description);
104 return PyString_FromString (description.GetData());
105 }
106}
107%extend lldb::SBModule {
108 PyObject *lldb::SBModule::__repr__ (){
109 lldb::SBStream description;
110 $self->GetDescription (description);
111 return PyString_FromString (description.GetData());
112 }
113}
114%extend lldb::SBProcess {
115 PyObject *lldb::SBProcess::__repr__ (){
116 lldb::SBStream description;
117 $self->GetDescription (description);
118 return PyString_FromString (description.GetData());
119 }
120}
Greg Clayton15ef51e2011-09-24 05:04:40 +0000121%extend lldb::SBSection {
122 PyObject *lldb::SBSection::__repr__ (){
123 lldb::SBStream description;
124 $self->GetDescription (description);
125 return PyString_FromString (description.GetData());
126 }
127}
Caroline Ticee49ec182010-09-22 23:01:29 +0000128%extend lldb::SBSymbol {
129 PyObject *lldb::SBSymbol::__repr__ (){
130 lldb::SBStream description;
131 $self->GetDescription (description);
132 return PyString_FromString (description.GetData());
133 }
134}
135%extend lldb::SBSymbolContext {
136 PyObject *lldb::SBSymbolContext::__repr__ (){
137 lldb::SBStream description;
138 $self->GetDescription (description);
139 return PyString_FromString (description.GetData());
140 }
141}
142%extend lldb::SBTarget {
143 PyObject *lldb::SBTarget::__repr__ (){
144 lldb::SBStream description;
Caroline Tice7826c882010-10-26 03:11:13 +0000145 $self->GetDescription (description, lldb::eDescriptionLevelBrief);
Caroline Ticee49ec182010-09-22 23:01:29 +0000146 return PyString_FromString (description.GetData());
147 }
148}
Greg Clayton96154be2011-11-13 06:57:31 +0000149%extend lldb::SBType {
150 PyObject *lldb::SBType::__repr__ (){
151 lldb::SBStream description;
152 $self->GetDescription (description, lldb::eDescriptionLevelBrief);
153 return PyString_FromString (description.GetData());
154 }
155}
156%extend lldb::SBTypeMember {
157 PyObject *lldb::SBTypeMember::__repr__ (){
158 lldb::SBStream description;
159 $self->GetDescription (description, lldb::eDescriptionLevelBrief);
160 return PyString_FromString (description.GetData());
161 }
162}
Caroline Ticee49ec182010-09-22 23:01:29 +0000163%extend lldb::SBThread {
164 PyObject *lldb::SBThread::__repr__ (){
165 lldb::SBStream description;
166 $self->GetDescription (description);
167 return PyString_FromString (description.GetData());
168 }
169}
170%extend lldb::SBValue {
171 PyObject *lldb::SBValue::__repr__ (){
172 lldb::SBStream description;
173 $self->GetDescription (description);
174 return PyString_FromString (description.GetData());
175 }
176}
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000177%extend lldb::SBWatchpoint {
178 PyObject *lldb::SBWatchpoint::__repr__ (){
Johnny Chen092bd152011-09-27 01:19:20 +0000179 lldb::SBStream description;
180 $self->GetDescription (description, lldb::eDescriptionLevelVerbose);
181 return PyString_FromString (description.GetData());
182 }
183}
Caroline Ticee49ec182010-09-22 23:01:29 +0000184
Greg Clayton9b8ff512012-02-01 01:46:19 +0000185%pythoncode %{
186
187class value(object):
188 '''A class designed to wrap lldb.SBValue() objects so the resulting object
189 can be used as a variable would be in code. So if you have a Point structure
190 variable in your code in the current frame named "pt", you can initialize an instance
191 of this class with it:
192
193 pt = lldb.value(lldb.frame.FindVariable("pt"))
194 print pt
195 print pt.x
196 print pt.y
197
198 pt = lldb.value(lldb.frame.FindVariable("rectangle_array"))
199 print rectangle_array[12]
200 print rectangle_array[5].origin.x'''
201 def __init__(self, sbvalue):
202 self.sbvalue = sbvalue
203
204 def __nonzero__(self):
205 return self.sbvalue.__nonzero__()
206
207 def __repr__(self):
208 return self.sbvalue.__repr__()
209
210 def __str__(self):
211 return self.sbvalue.__str__()
212
213 def __getitem__(self, key):
214 # Allow array access if this value has children...
215 if type(key) is int:
216 return value(self.sbvalue.GetValueForExpressionPath("[%i]" % key))
217 raise TypeError
218
219 def __getattr__(self, name):
220 child_sbvalue = self.sbvalue.GetChildMemberWithName (name)
221 if child_sbvalue:
222 return value(child_sbvalue)
223 raise AttributeError
224
225 def __add__(self, other):
226 return int(self) + int(other)
227
228 def __sub__(self, other):
229 return int(self) - int(other)
230
231 def __mul__(self, other):
232 return int(self) * int(other)
233
234 def __floordiv__(self, other):
235 return int(self) // int(other)
236
237 def __mod__(self, other):
238 return int(self) % int(other)
239
240 def __divmod__(self, other):
241 return int(self) % int(other)
242
243 def __pow__(self, other):
244 return int(self) ** int(other)
245
246 def __lshift__(self, other):
247 return int(self) << int(other)
248
249 def __rshift__(self, other):
250 return int(self) >> int(other)
251
252 def __and__(self, other):
253 return int(self) & int(other)
254
255 def __xor__(self, other):
256 return int(self) ^ int(other)
257
258 def __or__(self, other):
259 return int(self) | int(other)
260
261 def __div__(self, other):
262 return int(self) / int(other)
263
264 def __truediv__(self, other):
265 return int(self) / int(other)
266
267 def __iadd__(self, other):
268 result = self.__add__(other)
269 self.sbvalue.SetValueFromCString (str(result))
270 return result
271
272 def __isub__(self, other):
273 result = self.__sub__(other)
274 self.sbvalue.SetValueFromCString (str(result))
275 return result
276
277 def __imul__(self, other):
278 result = self.__mul__(other)
279 self.sbvalue.SetValueFromCString (str(result))
280 return result
281
282 def __idiv__(self, other):
283 result = self.__div__(other)
284 self.sbvalue.SetValueFromCString (str(result))
285 return result
286
287 def __itruediv__(self, other):
288 result = self.__truediv__(other)
289 self.sbvalue.SetValueFromCString (str(result))
290 return result
291
292 def __ifloordiv__(self, other):
293 result = self.__floordiv__(self, other)
294 self.sbvalue.SetValueFromCString (str(result))
295 return result
296
297 def __imod__(self, other):
298 result = self.__and__(self, other)
299 self.sbvalue.SetValueFromCString (str(result))
300 return result
301
302 def __ipow__(self, other):
303 result = self.__pow__(self, other)
304 self.sbvalue.SetValueFromCString (str(result))
305 return result
306
307 def __ipow__(self, other, modulo):
308 result = self.__pow__(self, other, modulo)
309 self.sbvalue.SetValueFromCString (str(result))
310 return result
311
312 def __ilshift__(self, other):
313 result = self.__lshift__(other)
314 self.sbvalue.SetValueFromCString (str(result))
315 return result
316
317 def __irshift__(self, other):
318 result = self.__rshift__(other)
319 self.sbvalue.SetValueFromCString (str(result))
320 return result
321
322 def __iand__(self, other):
323 result = self.__and__(self, other)
324 self.sbvalue.SetValueFromCString (str(result))
325 return result
326
327 def __ixor__(self, other):
328 result = self.__xor__(self, other)
329 self.sbvalue.SetValueFromCString (str(result))
330 return result
331
332 def __ior__(self, other):
333 result = self.__ior__(self, other)
334 self.sbvalue.SetValueFromCString (str(result))
335 return result
336
337 def __neg__(self):
338 return -int(self)
339
340 def __pos__(self):
341 return +int(self)
342
343 def __abs__(self):
344 return abs(int(self))
345
346 def __invert__(self):
347 return ~int(self)
348
349 def __complex__(self):
350 return complex (int(self))
351
352 def __int__(self):
353 return self.sbvalue.GetValueAsSigned()
354
355 def __long__(self):
356 return self.sbvalue.GetValueAsSigned()
357
358 def __float__(self):
359 return float (self.sbvalue.GetValueAsSigned())
360
361 def __oct__(self):
362 return '0%o' % self.sbvalue.GetValueAsSigned()
363
364 def __hex__(self):
365 return '0x%x' % self.sbvalue.GetValueAsSigned()
366
367%}
368