1//===-- SWIG Interface for SBValue ------------------------------*- C++ -*-===//
2//
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
52Name:  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."
57) SBValue;
58class SBValue
59{
60public:
61    SBValue ();
62
63    SBValue (const SBValue &rhs);
64
65    ~SBValue ();
66
67    bool
68    IsValid();
69
70    void
71    Clear();
72
73    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
88    bool
89    IsInScope ();
90
91    lldb::Format
92    GetFormat ();
93
94    void
95    SetFormat (lldb::Format format);
96
97    const char *
98    GetValue ();
99
100    int64_t
101    GetValueAsSigned(SBError& error, int64_t fail_value=0);
102
103    uint64_t
104    GetValueAsUnsigned(SBError& error, uint64_t fail_value=0);
105
106    int64_t
107    GetValueAsSigned(int64_t fail_value=0);
108
109    uint64_t
110    GetValueAsUnsigned(uint64_t fail_value=0);
111
112    ValueType
113    GetValueType ();
114
115    bool
116    GetValueDidChange ();
117
118    const char *
119    GetSummary ();
120
121    const char *
122    GetObjectDescription ();
123
124    lldb::SBValue
125    GetDynamicValue (lldb::DynamicValueType use_dynamic);
126
127    lldb::SBValue
128    GetStaticValue ();
129
130    lldb::SBValue
131    GetNonSyntheticValue ();
132
133    lldb::DynamicValueType
134    GetPreferDynamicValue ();
135
136    void
137    SetPreferDynamicValue (lldb::DynamicValueType use_dynamic);
138
139    bool
140    GetPreferSyntheticValue ();
141
142    void
143    SetPreferSyntheticValue (bool use_synthetic);
144
145    bool
146    IsDynamic();
147
148    bool
149    IsSynthetic ();
150
151    const char *
152    GetLocation ();
153
154    bool
155    SetValueFromCString (const char *value_str);
156
157    bool
158    SetValueFromCString (const char *value_str, lldb::SBError& error);
159
160    lldb::SBTypeFormat
161    GetTypeFormat ();
162
163    lldb::SBTypeSummary
164    GetTypeSummary ();
165
166    lldb::SBTypeFilter
167    GetTypeFilter ();
168
169    lldb::SBTypeSynthetic
170    GetTypeSynthetic ();
171
172    lldb::SBValue
173    GetChildAtIndex (uint32_t idx);
174
175    %feature("docstring", "
176    //------------------------------------------------------------------
177    /// Get a child value by index from a value.
178    ///
179    /// Structs, unions, classes, arrays and and pointers have child
180    /// values that can be access by index.
181    ///
182    /// Structs and unions access child members using a zero based index
183    /// for each child member. For
184    ///
185    /// Classes reserve the first indexes for base classes that have
186    /// members (empty base classes are omitted), and all members of the
187    /// current class will then follow the base classes.
188    ///
189    /// Pointers differ depending on what they point to. If the pointer
190    /// points to a simple type, the child at index zero
191    /// is the only child value available, unless \a synthetic_allowed
192    /// is \b true, in which case the pointer will be used as an array
193    /// and can create 'synthetic' child values using positive or
194    /// negative indexes. If the pointer points to an aggregate type
195    /// (an array, class, union, struct), then the pointee is
196    /// transparently skipped and any children are going to be the indexes
197    /// of the child values within the aggregate type. For example if
198    /// we have a 'Point' type and we have a SBValue that contains a
199    /// pointer to a 'Point' type, then the child at index zero will be
200    /// the 'x' member, and the child at index 1 will be the 'y' member
201    /// (the child at index zero won't be a 'Point' instance).
202    ///
203    /// Arrays have a preset number of children that can be accessed by
204    /// index and will returns invalid child values for indexes that are
205    /// out of bounds unless the \a synthetic_allowed is \b true. In this
206    /// case the array can create 'synthetic' child values for indexes
207    /// that aren't in the array bounds using positive or negative
208    /// indexes.
209    ///
210    /// @param[in] idx
211    ///     The index of the child value to get
212    ///
213    /// @param[in] use_dynamic
214    ///     An enumeration that specifies wether to get dynamic values,
215    ///     and also if the target can be run to figure out the dynamic
216    ///     type of the child value.
217    ///
218    /// @param[in] synthetic_allowed
219    ///     If \b true, then allow child values to be created by index
220    ///     for pointers and arrays for indexes that normally wouldn't
221    ///     be allowed.
222    ///
223    /// @return
224    ///     A new SBValue object that represents the child member value.
225    //------------------------------------------------------------------
226    ") GetChildAtIndex;
227    lldb::SBValue
228    GetChildAtIndex (uint32_t idx,
229                     lldb::DynamicValueType use_dynamic,
230                     bool can_create_synthetic);
231
232    lldb::SBValue
233    CreateChildAtOffset (const char *name, uint32_t offset, lldb::SBType type);
234
235    lldb::SBValue
236    SBValue::Cast (lldb::SBType type);
237
238    lldb::SBValue
239    CreateValueFromExpression (const char *name, const char* expression);
240
241    lldb::SBValue
242    CreateValueFromExpression (const char *name, const char* expression, SBExpressionOptions &options);
243
244    lldb::SBValue
245    CreateValueFromAddress(const char* name, lldb::addr_t address, lldb::SBType type);
246
247	lldb::SBValue
248	CreateValueFromData (const char* name,
249	                     lldb::SBData data,
250	                     lldb::SBType type);
251
252    lldb::SBType
253    GetType();
254
255    %feature("docstring", "
256    //------------------------------------------------------------------
257    /// Returns the child member index.
258    ///
259    /// Matches children of this object only and will match base classes and
260    /// member names if this is a clang typed object.
261    ///
262    /// @param[in] name
263    ///     The name of the child value to get
264    ///
265    /// @return
266    ///     An index to the child member value.
267    //------------------------------------------------------------------
268    ") GetIndexOfChildWithName;
269    uint32_t
270    GetIndexOfChildWithName (const char *name);
271
272    lldb::SBValue
273    GetChildMemberWithName (const char *name);
274
275    %feature("docstring", "
276    //------------------------------------------------------------------
277    /// Returns the child member value.
278    ///
279    /// Matches child members of this object and child members of any base
280    /// classes.
281    ///
282    /// @param[in] name
283    ///     The name of the child value to get
284    ///
285    /// @param[in] use_dynamic
286    ///     An enumeration that specifies wether to get dynamic values,
287    ///     and also if the target can be run to figure out the dynamic
288    ///     type of the child value.
289    ///
290    /// @return
291    ///     A new SBValue object that represents the child member value.
292    //------------------------------------------------------------------
293    ") GetChildMemberWithName;
294    lldb::SBValue
295    GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic);
296
297    %feature("docstring", "Expands nested expressions like .a->b[0].c[1]->d."
298    ) GetValueForExpressionPath;
299    lldb::SBValue
300    GetValueForExpressionPath(const char* expr_path);
301
302    lldb::SBDeclaration
303    GetDeclaration ();
304
305    bool
306    MightHaveChildren ();
307
308    uint32_t
309    GetNumChildren ();
310
311    void *
312    GetOpaqueType();
313
314    lldb::SBValue
315    Dereference ();
316
317    lldb::SBValue
318    AddressOf();
319
320    bool
321    TypeIsPointerType ();
322
323    lldb::SBTarget
324    GetTarget();
325
326    lldb::SBProcess
327    GetProcess();
328
329    lldb::SBThread
330    GetThread();
331
332    lldb::SBFrame
333    GetFrame();
334
335    %feature("docstring", "
336    /// Find and watch a variable.
337    /// It returns an SBWatchpoint, which may be invalid.
338    ") Watch;
339    lldb::SBWatchpoint
340    Watch (bool resolve_location, bool read, bool write, SBError &error);
341
342    %feature("docstring", "
343    /// Find and watch the location pointed to by a variable.
344    /// It returns an SBWatchpoint, which may be invalid.
345    ") WatchPointee;
346    lldb::SBWatchpoint
347    WatchPointee (bool resolve_location, bool read, bool write, SBError &error);
348
349    bool
350    GetDescription (lldb::SBStream &description);
351
352    bool
353    GetExpressionPath (lldb::SBStream &description);
354
355	%feature("docstring", "
356	//------------------------------------------------------------------
357    /// Get an SBData wrapping what this SBValue points to.
358    ///
359    /// This method will dereference the current SBValue, if its
360    /// data type is a T* or T[], and extract item_count elements
361    /// of type T from it, copying their contents in an SBData.
362    ///
363    /// @param[in] item_idx
364    ///     The index of the first item to retrieve. For an array
365    ///     this is equivalent to array[item_idx], for a pointer
366    ///     to *(pointer + item_idx). In either case, the measurement
367    ///     unit for item_idx is the sizeof(T) rather than the byte
368    ///
369    /// @param[in] item_count
370    ///     How many items should be copied into the output. By default
371    ///     only one item is copied, but more can be asked for.
372    ///
373    /// @return
374    ///     An SBData with the contents of the copied items, on success.
375    ///     An empty SBData otherwise.
376    //------------------------------------------------------------------
377	") GetPointeeData;
378	lldb::SBData
379	GetPointeeData (uint32_t item_idx = 0,
380					uint32_t item_count = 1);
381
382    %feature("docstring", "
383	//------------------------------------------------------------------
384    /// Get an SBData wrapping the contents of this SBValue.
385    ///
386    /// This method will read the contents of this object in memory
387    /// and copy them into an SBData for future use.
388    ///
389    /// @return
390    ///     An SBData with the contents of this SBValue, on success.
391    ///     An empty SBData otherwise.
392    //------------------------------------------------------------------
393	") GetData;
394    lldb::SBData
395    GetData ();
396
397    bool
398    SetData (lldb::SBData &data, lldb::SBError& error);
399
400	lldb::addr_t
401	GetLoadAddress();
402
403	lldb::SBAddress
404	GetAddress();
405
406    %feature("docstring", "Returns an expression path for this value."
407    ) GetExpressionPath;
408    bool
409    GetExpressionPath (lldb::SBStream &description, bool qualify_cxx_base_classes);
410
411    %pythoncode %{
412        def __get_dynamic__ (self):
413            '''Helper function for the "SBValue.dynamic" property.'''
414            return self.GetDynamicValue (eDynamicCanRunTarget)
415
416        __swig_getmethods__["name"] = GetName
417        if _newclass: name = property(GetName, None, doc='''A read only property that returns the name of this value as a string.''')
418
419        __swig_getmethods__["type"] = GetType
420        if _newclass: type = property(GetType, None, doc='''A read only property that returns a lldb.SBType object that represents the type for this value.''')
421
422        __swig_getmethods__["size"] = GetByteSize
423        if _newclass: size = property(GetByteSize, None, doc='''A read only property that returns the size in bytes of this value.''')
424
425        __swig_getmethods__["is_in_scope"] = IsInScope
426        if _newclass: is_in_scope = property(IsInScope, None, doc='''A read only property that returns a boolean value that indicates whether this value is currently lexically in scope.''')
427
428        __swig_getmethods__["format"] = GetFormat
429        __swig_setmethods__["format"] = SetFormat
430        if _newclass: format = property(GetName, SetFormat, doc='''A read/write property that gets/sets the format used for lldb.SBValue().GetValue() for this value. See enumerations that start with "lldb.eFormat".''')
431
432        __swig_getmethods__["value"] = GetValue
433        __swig_setmethods__["value"] = SetValueFromCString
434        if _newclass: value = property(GetValue, SetValueFromCString, doc='''A read/write property that gets/sets value from a string.''')
435
436        __swig_getmethods__["value_type"] = GetValueType
437        if _newclass: value_type = property(GetValueType, None, doc='''A read only property that returns an lldb enumeration value (see enumerations that start with "lldb.eValueType") that represents the type of this value (local, argument, global, register, etc.).''')
438
439        __swig_getmethods__["changed"] = GetValueDidChange
440        if _newclass: changed = property(GetValueDidChange, None, doc='''A read only property that returns a boolean value that indicates if this value has changed since it was last updated.''')
441
442        __swig_getmethods__["data"] = GetData
443        if _newclass: data = property(GetData, None, doc='''A read only property that returns an lldb object (lldb.SBData) that represents the bytes that make up the value for this object.''')
444
445        __swig_getmethods__["load_addr"] = GetLoadAddress
446        if _newclass: load_addr = property(GetLoadAddress, None, doc='''A read only property that returns the load address of this value as an integer.''')
447
448        __swig_getmethods__["addr"] = GetAddress
449        if _newclass: addr = property(GetAddress, None, doc='''A read only property that returns an lldb.SBAddress that represents the address of this value if it is in memory.''')
450
451        __swig_getmethods__["deref"] = Dereference
452        if _newclass: deref = property(Dereference, None, doc='''A read only property that returns an lldb.SBValue that is created by dereferencing this value.''')
453
454        __swig_getmethods__["address_of"] = AddressOf
455        if _newclass: address_of = property(AddressOf, None, doc='''A read only property that returns an lldb.SBValue that represents the address-of this value.''')
456
457        __swig_getmethods__["error"] = GetError
458        if _newclass: error = property(GetError, None, doc='''A read only property that returns the lldb.SBError that represents the error from the last time the variable value was calculated.''')
459
460        __swig_getmethods__["summary"] = GetSummary
461        if _newclass: summary = property(GetSummary, None, doc='''A read only property that returns the summary for this value as a string''')
462
463        __swig_getmethods__["description"] = GetObjectDescription
464        if _newclass: description = property(GetObjectDescription, None, doc='''A read only property that returns the language-specific description of this value as a string''')
465
466        __swig_getmethods__["dynamic"] = __get_dynamic__
467        if _newclass: dynamic = property(__get_dynamic__, None, doc='''A read only property that returns an lldb.SBValue that is created by finding the dynamic type of this value.''')
468
469        __swig_getmethods__["location"] = GetLocation
470        if _newclass: location = property(GetLocation, None, doc='''A read only property that returns the location of this value as a string.''')
471
472        __swig_getmethods__["target"] = GetTarget
473        if _newclass: target = property(GetTarget, None, doc='''A read only property that returns the lldb.SBTarget that this value is associated with.''')
474
475        __swig_getmethods__["process"] = GetProcess
476        if _newclass: process = property(GetProcess, None, doc='''A read only property that returns the lldb.SBProcess that this value is associated with, the returned value might be invalid and should be tested.''')
477
478        __swig_getmethods__["thread"] = GetThread
479        if _newclass: thread = property(GetThread, None, doc='''A read only property that returns the lldb.SBThread that this value is associated with, the returned value might be invalid and should be tested.''')
480
481        __swig_getmethods__["frame"] = GetFrame
482        if _newclass: frame = property(GetFrame, None, doc='''A read only property that returns the lldb.SBFrame that this value is associated with, the returned value might be invalid and should be tested.''')
483
484        __swig_getmethods__["num_children"] = GetNumChildren
485        if _newclass: num_children = property(GetNumChildren, None, doc='''A read only property that returns the number of child lldb.SBValues that this value has.''')
486
487        __swig_getmethods__["unsigned"] = GetValueAsUnsigned
488        if _newclass: unsigned = property(GetValueAsUnsigned, None, doc='''A read only property that returns the value of this SBValue as an usigned integer.''')
489
490        __swig_getmethods__["signed"] = GetValueAsSigned
491        if _newclass: signed = property(GetValueAsSigned, None, doc='''A read only property that returns the value of this SBValue as a signed integer.''')
492
493        def get_expr_path(self):
494            s = SBStream()
495            self.GetExpressionPath (s)
496            return s.GetData()
497
498        __swig_getmethods__["path"] = get_expr_path
499        if _newclass: path = property(get_expr_path, None, doc='''A read only property that returns the expression path that one can use to reach this value in an expression.''')
500    %}
501
502};
503
504} // namespace lldb
505