blob: d61c7aa7752e5f0b85987a7c5137cbb6547345ae [file] [log] [blame]
Johnny Chen7be5a4f2011-07-18 19:15:22 +00001//===-- SWIG Interface for SBValue ------------------------------*- C++ -*-===//
Johnny Chen854a1ba2011-07-18 19:08:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10namespace lldb {
11
12%feature("docstring",
13"Represents the value of a variable, a register, or an expression.
14
15SBValue supports iteration through its child, which in turn is represented
16as an SBValue. For example, we can get the general purpose registers of a
17frame as an SBValue, and iterate through all the registers,
18
19 registerSet = frame.GetRegisters() # Returns an SBValueList.
20 for regs in registerSet:
21 if 'general purpose registers' in regs.getName().lower():
22 GPRs = regs
23 break
24
25 print '%s (number of children = %d):' % (GPRs.GetName(), GPRs.GetNumChildren())
26 for reg in GPRs:
27 print 'Name: ', reg.GetName(), ' Value: ', reg.GetValue()
28
29produces the output:
30
31General Purpose Registers (number of children = 21):
32Name: rax Value: 0x0000000100000c5c
33Name: rbx Value: 0x0000000000000000
34Name: rcx Value: 0x00007fff5fbffec0
35Name: rdx Value: 0x00007fff5fbffeb8
36Name: rdi Value: 0x0000000000000001
37Name: rsi Value: 0x00007fff5fbffea8
38Name: rbp Value: 0x00007fff5fbffe80
39Name: rsp Value: 0x00007fff5fbffe60
40Name: r8 Value: 0x0000000008668682
41Name: r9 Value: 0x0000000000000000
42Name: r10 Value: 0x0000000000001200
43Name: r11 Value: 0x0000000000000206
44Name: r12 Value: 0x0000000000000000
45Name: r13 Value: 0x0000000000000000
46Name: r14 Value: 0x0000000000000000
47Name: r15 Value: 0x0000000000000000
48Name: rip Value: 0x0000000100000dae
49Name: rflags Value: 0x0000000000000206
50Name: cs Value: 0x0000000000000027
51Name: fs Value: 0x0000000000000010
Johnny Chende856cc2011-07-25 23:41:08 +000052Name: gs Value: 0x0000000000000048
53
54See also linked_list_iter() for another perspective on how to iterate through an
55SBValue instance which interprets the value object as representing the head of a
56linked list."
Johnny Chenc3fba812011-07-18 20:13:38 +000057) SBValue;
Johnny Chen854a1ba2011-07-18 19:08:30 +000058class SBValue
59{
60public:
61 SBValue ();
62
63 SBValue (const SBValue &rhs);
64
65 ~SBValue ();
66
67 bool
Greg Claytond68e0892011-09-09 23:04:00 +000068 IsValid();
Johnny Chen854a1ba2011-07-18 19:08:30 +000069
Jim Inghame0bd5712011-12-19 20:39:44 +000070 void
71 Clear();
72
Johnny Chen854a1ba2011-07-18 19:08:30 +000073 SBError
74 GetError();
75
76 lldb::user_id_t
77 GetID ();
78
79 const char *
80 GetName();
81
82 const char *
83 GetTypeName ();
84
85 size_t
86 GetByteSize ();
87
Johnny Chen854a1ba2011-07-18 19:08:30 +000088 bool
89 IsInScope ();
90
91 lldb::Format
Greg Claytond68e0892011-09-09 23:04:00 +000092 GetFormat ();
Johnny Chen854a1ba2011-07-18 19:08:30 +000093
94 void
95 SetFormat (lldb::Format format);
96
Johnny Chen854a1ba2011-07-18 19:08:30 +000097 const char *
98 GetValue ();
99
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000100 int64_t
Enrico Granatac92eb402011-08-04 01:41:02 +0000101 GetValueAsSigned(SBError& error, int64_t fail_value=0);
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000102
103 uint64_t
Enrico Granatac92eb402011-08-04 01:41:02 +0000104 GetValueAsUnsigned(SBError& error, uint64_t fail_value=0);
105
106 int64_t
107 GetValueAsSigned(int64_t fail_value=0);
108
109 uint64_t
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000110 GetValueAsUnsigned(uint64_t fail_value=0);
111
Johnny Chen854a1ba2011-07-18 19:08:30 +0000112 ValueType
113 GetValueType ();
114
Johnny Chen854a1ba2011-07-18 19:08:30 +0000115 bool
116 GetValueDidChange ();
117
Johnny Chen854a1ba2011-07-18 19:08:30 +0000118 const char *
119 GetSummary ();
120
Johnny Chen854a1ba2011-07-18 19:08:30 +0000121 const char *
122 GetObjectDescription ();
123
Jim Ingham1b425752011-12-08 19:44:08 +0000124 lldb::SBValue
125 GetDynamicValue (lldb::DynamicValueType use_dynamic);
126
127 lldb::SBValue
128 GetStaticValue ();
129
130 bool
131 IsDynamic();
132
Johnny Chen854a1ba2011-07-18 19:08:30 +0000133 const char *
134 GetLocation ();
135
Johnny Chen854a1ba2011-07-18 19:08:30 +0000136 bool
137 SetValueFromCString (const char *value_str);
138
Enrico Granatad760907c2012-02-17 03:18:30 +0000139 lldb::SBTypeFormat
140 GetTypeFormat ();
141
142 lldb::SBTypeSummary
143 GetTypeSummary ();
144
145 lldb::SBTypeFilter
146 GetTypeFilter ();
147
148 lldb::SBTypeSynthetic
149 GetTypeSynthetic ();
150
Johnny Chen854a1ba2011-07-18 19:08:30 +0000151 lldb::SBValue
152 GetChildAtIndex (uint32_t idx);
153
154 %feature("docstring", "
155 //------------------------------------------------------------------
156 /// Get a child value by index from a value.
157 ///
158 /// Structs, unions, classes, arrays and and pointers have child
159 /// values that can be access by index.
160 ///
161 /// Structs and unions access child members using a zero based index
162 /// for each child member. For
163 ///
164 /// Classes reserve the first indexes for base classes that have
165 /// members (empty base classes are omitted), and all members of the
166 /// current class will then follow the base classes.
167 ///
168 /// Pointers differ depending on what they point to. If the pointer
169 /// points to a simple type, the child at index zero
170 /// is the only child value available, unless \a synthetic_allowed
171 /// is \b true, in which case the pointer will be used as an array
172 /// and can create 'synthetic' child values using positive or
173 /// negative indexes. If the pointer points to an aggregate type
174 /// (an array, class, union, struct), then the pointee is
175 /// transparently skipped and any children are going to be the indexes
176 /// of the child values within the aggregate type. For example if
177 /// we have a 'Point' type and we have a SBValue that contains a
178 /// pointer to a 'Point' type, then the child at index zero will be
179 /// the 'x' member, and the child at index 1 will be the 'y' member
180 /// (the child at index zero won't be a 'Point' instance).
181 ///
182 /// Arrays have a preset number of children that can be accessed by
183 /// index and will returns invalid child values for indexes that are
184 /// out of bounds unless the \a synthetic_allowed is \b true. In this
185 /// case the array can create 'synthetic' child values for indexes
186 /// that aren't in the array bounds using positive or negative
187 /// indexes.
188 ///
189 /// @param[in] idx
190 /// The index of the child value to get
191 ///
192 /// @param[in] use_dynamic
193 /// An enumeration that specifies wether to get dynamic values,
194 /// and also if the target can be run to figure out the dynamic
195 /// type of the child value.
196 ///
197 /// @param[in] synthetic_allowed
198 /// If \b true, then allow child values to be created by index
199 /// for pointers and arrays for indexes that normally wouldn't
200 /// be allowed.
201 ///
202 /// @return
203 /// A new SBValue object that represents the child member value.
204 //------------------------------------------------------------------
205 ") GetChildAtIndex;
206 lldb::SBValue
207 GetChildAtIndex (uint32_t idx,
208 lldb::DynamicValueType use_dynamic,
209 bool can_create_synthetic);
Enrico Granata979e20d2011-07-29 19:53:35 +0000210
211 lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000212 CreateChildAtOffset (const char *name, uint32_t offset, lldb::SBType type);
Enrico Granata979e20d2011-07-29 19:53:35 +0000213
214 lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000215 SBValue::Cast (lldb::SBType type);
Johnny Chen854a1ba2011-07-18 19:08:30 +0000216
Enrico Granata979e20d2011-07-29 19:53:35 +0000217 lldb::SBValue
218 CreateValueFromExpression (const char *name, const char* expression);
219
220 lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000221 CreateValueFromAddress(const char* name, lldb::addr_t address, lldb::SBType type);
Enrico Granata979e20d2011-07-29 19:53:35 +0000222
Enrico Granata91544802011-09-06 19:20:51 +0000223 lldb::SBValue
224 CreateValueFromData (const char* name,
Greg Claytond68e0892011-09-09 23:04:00 +0000225 lldb::SBData data,
226 lldb::SBType type);
Enrico Granata91544802011-09-06 19:20:51 +0000227
Enrico Granata979e20d2011-07-29 19:53:35 +0000228 lldb::SBType
229 GetType();
230
Johnny Chen854a1ba2011-07-18 19:08:30 +0000231 %feature("docstring", "
232 //------------------------------------------------------------------
233 /// Returns the child member index.
234 ///
235 /// Matches children of this object only and will match base classes and
236 /// member names if this is a clang typed object.
237 ///
238 /// @param[in] name
239 /// The name of the child value to get
240 ///
241 /// @return
242 /// An index to the child member value.
243 //------------------------------------------------------------------
244 ") GetIndexOfChildWithName;
245 uint32_t
246 GetIndexOfChildWithName (const char *name);
247
248 lldb::SBValue
249 GetChildMemberWithName (const char *name);
250
251 %feature("docstring", "
252 //------------------------------------------------------------------
253 /// Returns the child member value.
254 ///
255 /// Matches child members of this object and child members of any base
256 /// classes.
257 ///
258 /// @param[in] name
259 /// The name of the child value to get
260 ///
261 /// @param[in] use_dynamic
262 /// An enumeration that specifies wether to get dynamic values,
263 /// and also if the target can be run to figure out the dynamic
264 /// type of the child value.
265 ///
266 /// @return
267 /// A new SBValue object that represents the child member value.
268 //------------------------------------------------------------------
269 ") GetChildMemberWithName;
270 lldb::SBValue
271 GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic);
272
273 %feature("docstring", "Expands nested expressions like .a->b[0].c[1]->d."
274 ) GetValueForExpressionPath;
275 lldb::SBValue
276 GetValueForExpressionPath(const char* expr_path);
277
278 uint32_t
279 GetNumChildren ();
280
281 void *
282 GetOpaqueType();
283
Johnny Chen854a1ba2011-07-18 19:08:30 +0000284 lldb::SBValue
285 Dereference ();
286
Enrico Granata979e20d2011-07-29 19:53:35 +0000287 lldb::SBValue
288 AddressOf();
289
Johnny Chen854a1ba2011-07-18 19:08:30 +0000290 bool
291 TypeIsPointerType ();
Enrico Granata979e20d2011-07-29 19:53:35 +0000292
293 lldb::SBTarget
294 GetTarget();
Johnny Chen854a1ba2011-07-18 19:08:30 +0000295
Enrico Granata979e20d2011-07-29 19:53:35 +0000296 lldb::SBProcess
297 GetProcess();
298
299 lldb::SBThread
300 GetThread();
301
302 lldb::SBFrame
303 GetFrame();
304
Johnny Chenecd4feb2011-10-14 00:42:25 +0000305 %feature("docstring", "
306 /// Find and watch a variable.
307 /// It returns an SBWatchpoint, which may be invalid.
308 ") Watch;
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000309 lldb::SBWatchpoint
310 Watch (bool resolve_location, bool read, bool write);
311
Johnny Chenecd4feb2011-10-14 00:42:25 +0000312 %feature("docstring", "
313 /// Find and watch the location pointed to by a variable.
314 /// It returns an SBWatchpoint, which may be invalid.
315 ") WatchPointee;
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000316 lldb::SBWatchpoint
317 WatchPointee (bool resolve_location, bool read, bool write);
318
Johnny Chen854a1ba2011-07-18 19:08:30 +0000319 bool
320 GetDescription (lldb::SBStream &description);
321
322 bool
323 GetExpressionPath (lldb::SBStream &description);
Enrico Granata91544802011-09-06 19:20:51 +0000324
325 %feature("docstring", "
326 //------------------------------------------------------------------
327 /// Get an SBData wrapping what this SBValue points to.
328 ///
329 /// This method will dereference the current SBValue, if its
330 /// data type is a T* or T[], and extract item_count elements
331 /// of type T from it, copying their contents in an SBData.
332 ///
333 /// @param[in] item_idx
334 /// The index of the first item to retrieve. For an array
335 /// this is equivalent to array[item_idx], for a pointer
336 /// to *(pointer + item_idx). In either case, the measurement
337 /// unit for item_idx is the sizeof(T) rather than the byte
338 ///
339 /// @param[in] item_count
340 /// How many items should be copied into the output. By default
341 /// only one item is copied, but more can be asked for.
342 ///
343 /// @return
344 /// An SBData with the contents of the copied items, on success.
345 /// An empty SBData otherwise.
346 //------------------------------------------------------------------
347 ") GetPointeeData;
348 lldb::SBData
349 GetPointeeData (uint32_t item_idx = 0,
350 uint32_t item_count = 1);
351
352 %feature("docstring", "
353 //------------------------------------------------------------------
354 /// Get an SBData wrapping the contents of this SBValue.
355 ///
356 /// This method will read the contents of this object in memory
357 /// and copy them into an SBData for future use.
358 ///
359 /// @return
360 /// An SBData with the contents of this SBValue, on success.
361 /// An empty SBData otherwise.
362 //------------------------------------------------------------------
363 ") GetData;
364 lldb::SBData
365 GetData ();
366
367 lldb::addr_t
368 GetLoadAddress();
369
370 lldb::SBAddress
371 GetAddress();
Johnny Chen854a1ba2011-07-18 19:08:30 +0000372
373 %feature("docstring", "Returns an expression path for this value."
Enrico Granata91544802011-09-06 19:20:51 +0000374 ) GetExpressionPath;
Johnny Chen854a1ba2011-07-18 19:08:30 +0000375 bool
376 GetExpressionPath (lldb::SBStream &description, bool qualify_cxx_base_classes);
Greg Clayton1b925202012-01-29 06:07:39 +0000377
378 %pythoncode %{
379
380 __swig_getmethods__["name"] = GetName
381 if _newclass: x = property(GetName, None)
382
383 __swig_getmethods__["type"] = GetType
384 if _newclass: x = property(GetType, None)
385
386 __swig_getmethods__["size"] = GetByteSize
387 if _newclass: x = property(GetByteSize, None)
388
389 __swig_getmethods__["name"] = GetName
390 if _newclass: x = property(GetName, None)
391
392 __swig_getmethods__["is_in_scope"] = IsInScope
393 if _newclass: x = property(IsInScope, None)
394
395 __swig_getmethods__["format"] = GetFormat
396 __swig_setmethods__["format"] = SetFormat
397 if _newclass: x = property(GetName, SetFormat)
398
399 __swig_getmethods__["value"] = GetValue
400 __swig_setmethods__["value"] = SetValueFromCString
401 if _newclass: x = property(GetValue, SetValueFromCString)
402
403 __swig_getmethods__["value_type"] = GetValueType
404 if _newclass: x = property(GetValueType, None)
405
406 __swig_getmethods__["changed"] = GetValueDidChange
407 if _newclass: x = property(GetValueDidChange, None)
408
409 __swig_getmethods__["data"] = GetData
410 if _newclass: x = property(GetData, None)
411
412 __swig_getmethods__["load_addr"] = GetLoadAddress
413 if _newclass: x = property(GetLoadAddress, None)
414
415 __swig_getmethods__["addr"] = GetAddress
416 if _newclass: x = property(GetAddress, None)
417
418 __swig_getmethods__["deref"] = Dereference
419 if _newclass: x = property(Dereference, None)
420
421 __swig_getmethods__["address_of"] = AddressOf
422 if _newclass: x = property(AddressOf, None)
423
424 __swig_getmethods__["error"] = GetError
425 if _newclass: x = property(GetError, None)
426
427 __swig_getmethods__["summary"] = GetSummary
428 if _newclass: x = property(GetSummary, None)
429
430 __swig_getmethods__["description"] = GetObjectDescription
431 if _newclass: x = property(GetObjectDescription, None)
432
433 __swig_getmethods__["location"] = GetLocation
434 if _newclass: x = property(GetLocation, None)
435
436 __swig_getmethods__["target"] = GetTarget
437 if _newclass: x = property(GetTarget, None)
438
439 __swig_getmethods__["process"] = GetProcess
440 if _newclass: x = property(GetProcess, None)
441
442 __swig_getmethods__["thread"] = GetThread
443 if _newclass: x = property(GetThread, None)
444
445 __swig_getmethods__["frame"] = GetFrame
446 if _newclass: x = property(GetFrame, None)
447
448 __swig_getmethods__["num_children"] = GetNumChildren
449 if _newclass: x = property(GetNumChildren, None)
450
Greg Claytond62b9c12012-02-03 07:02:37 +0000451 __swig_getmethods__["unsigned"] = GetValueAsUnsigned
452 if _newclass: x = property(GetValueAsUnsigned, None)
453
454 __swig_getmethods__["signed"] = GetValueAsSigned
455 if _newclass: x = property(GetValueAsSigned, None)
456
457 def get_expr_path(self):
458 s = SBStream()
459 self.GetExpressionPath (s)
460 return s.GetData()
461
462 __swig_getmethods__["path"] = get_expr_path
463 if _newclass: x = property(get_expr_path, None)
Greg Clayton1b925202012-01-29 06:07:39 +0000464 %}
465
Johnny Chen854a1ba2011-07-18 19:08:30 +0000466};
467
468} // namespace lldb