LLDB  mainline
SBValue.h
Go to the documentation of this file.
1 //===-- SBValue.h -----------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLDB_SBValue_h_
10 #define LLDB_SBValue_h_
11 
12 #include "lldb/API/SBData.h"
13 #include "lldb/API/SBDefines.h"
14 #include "lldb/API/SBType.h"
15 
16 class ValueImpl;
17 class ValueLocker;
18 
19 namespace lldb {
20 
22 public:
23  SBValue();
24 
25  SBValue(const lldb::SBValue &rhs);
26 
27  lldb::SBValue &operator=(const lldb::SBValue &rhs);
28 
29  ~SBValue();
30 
31  explicit operator bool() const;
32 
33  bool IsValid();
34 
35  void Clear();
36 
37  SBError GetError();
38 
39  lldb::user_id_t GetID();
40 
41  const char *GetName();
42 
43  const char *GetTypeName();
44 
45  const char *GetDisplayTypeName();
46 
47  size_t GetByteSize();
48 
49  bool IsInScope();
50 
51  lldb::Format GetFormat();
52 
53  void SetFormat(lldb::Format format);
54 
55  const char *GetValue();
56 
57  int64_t GetValueAsSigned(lldb::SBError &error, int64_t fail_value = 0);
58 
59  uint64_t GetValueAsUnsigned(lldb::SBError &error, uint64_t fail_value = 0);
60 
61  int64_t GetValueAsSigned(int64_t fail_value = 0);
62 
63  uint64_t GetValueAsUnsigned(uint64_t fail_value = 0);
64 
65  ValueType GetValueType();
66 
67  // If you call this on a newly created ValueObject, it will always return
68  // false.
69  bool GetValueDidChange();
70 
71  const char *GetSummary();
72 
73  const char *GetSummary(lldb::SBStream &stream,
75 
76  const char *GetObjectDescription();
77 
78  const char *GetTypeValidatorResult();
79 
80  lldb::SBValue GetDynamicValue(lldb::DynamicValueType use_dynamic);
81 
82  lldb::SBValue GetStaticValue();
83 
84  lldb::SBValue GetNonSyntheticValue();
85 
86  lldb::DynamicValueType GetPreferDynamicValue();
87 
88  void SetPreferDynamicValue(lldb::DynamicValueType use_dynamic);
89 
90  bool GetPreferSyntheticValue();
91 
92  void SetPreferSyntheticValue(bool use_synthetic);
93 
94  bool IsDynamic();
95 
96  bool IsSynthetic();
97 
98  bool IsSyntheticChildrenGenerated();
99 
100  void SetSyntheticChildrenGenerated(bool);
101 
102  const char *GetLocation();
103 
104  // Deprecated - use the one that takes SBError&
105  bool SetValueFromCString(const char *value_str);
106 
107  bool SetValueFromCString(const char *value_str, lldb::SBError &error);
108 
109  lldb::SBTypeFormat GetTypeFormat();
110 
111  lldb::SBTypeSummary GetTypeSummary();
112 
113  lldb::SBTypeFilter GetTypeFilter();
114 
115  lldb::SBTypeSynthetic GetTypeSynthetic();
116 
117  lldb::SBValue GetChildAtIndex(uint32_t idx);
118 
119  lldb::SBValue CreateChildAtOffset(const char *name, uint32_t offset,
120  lldb::SBType type);
121 
122  // Deprecated - use the expression evaluator to perform type casting
123  lldb::SBValue Cast(lldb::SBType type);
124 
125  lldb::SBValue CreateValueFromExpression(const char *name,
126  const char *expression);
127 
128  lldb::SBValue CreateValueFromExpression(const char *name,
129  const char *expression,
130  SBExpressionOptions &options);
131 
132  lldb::SBValue CreateValueFromAddress(const char *name, lldb::addr_t address,
133  lldb::SBType type);
134 
135  // this has no address! GetAddress() and GetLoadAddress() as well as
136  // AddressOf() on the return of this call all return invalid
137  lldb::SBValue CreateValueFromData(const char *name, lldb::SBData data,
138  lldb::SBType type);
139 
140  /// Get a child value by index from a value.
141  ///
142  /// Structs, unions, classes, arrays and pointers have child
143  /// values that can be access by index.
144  ///
145  /// Structs and unions access child members using a zero based index
146  /// for each child member. For
147  ///
148  /// Classes reserve the first indexes for base classes that have
149  /// members (empty base classes are omitted), and all members of the
150  /// current class will then follow the base classes.
151  ///
152  /// Pointers differ depending on what they point to. If the pointer
153  /// points to a simple type, the child at index zero
154  /// is the only child value available, unless \a synthetic_allowed
155  /// is \b true, in which case the pointer will be used as an array
156  /// and can create 'synthetic' child values using positive or
157  /// negative indexes. If the pointer points to an aggregate type
158  /// (an array, class, union, struct), then the pointee is
159  /// transparently skipped and any children are going to be the indexes
160  /// of the child values within the aggregate type. For example if
161  /// we have a 'Point' type and we have a SBValue that contains a
162  /// pointer to a 'Point' type, then the child at index zero will be
163  /// the 'x' member, and the child at index 1 will be the 'y' member
164  /// (the child at index zero won't be a 'Point' instance).
165  ///
166  /// If you actually need an SBValue that represents the type pointed
167  /// to by a SBValue for which GetType().IsPointeeType() returns true,
168  /// regardless of the pointee type, you can do that with SBValue::Dereference.
169  ///
170  /// Arrays have a preset number of children that can be accessed by
171  /// index and will returns invalid child values for indexes that are
172  /// out of bounds unless the \a synthetic_allowed is \b true. In this
173  /// case the array can create 'synthetic' child values for indexes
174  /// that aren't in the array bounds using positive or negative
175  /// indexes.
176  ///
177  /// \param[in] idx
178  /// The index of the child value to get
179  ///
180  /// \param[in] use_dynamic
181  /// An enumeration that specifies whether to get dynamic values,
182  /// and also if the target can be run to figure out the dynamic
183  /// type of the child value.
184  ///
185  /// \param[in] can_create_synthetic
186  /// If \b true, then allow child values to be created by index
187  /// for pointers and arrays for indexes that normally wouldn't
188  /// be allowed.
189  ///
190  /// \return
191  /// A new SBValue object that represents the child member value.
192  lldb::SBValue GetChildAtIndex(uint32_t idx,
193  lldb::DynamicValueType use_dynamic,
194  bool can_create_synthetic);
195 
196  // Matches children of this object only and will match base classes and
197  // member names if this is a clang typed object.
198  uint32_t GetIndexOfChildWithName(const char *name);
199 
200  // Matches child members of this object and child members of any base
201  // classes.
202  lldb::SBValue GetChildMemberWithName(const char *name);
203 
204  // Matches child members of this object and child members of any base
205  // classes.
206  lldb::SBValue GetChildMemberWithName(const char *name,
207  lldb::DynamicValueType use_dynamic);
208 
209  // Expands nested expressions like .a->b[0].c[1]->d
210  lldb::SBValue GetValueForExpressionPath(const char *expr_path);
211 
212  lldb::SBValue AddressOf();
213 
214  lldb::addr_t GetLoadAddress();
215 
216  lldb::SBAddress GetAddress();
217 
218  /// Get an SBData wrapping what this SBValue points to.
219  ///
220  /// This method will dereference the current SBValue, if its
221  /// data type is a T* or T[], and extract item_count elements
222  /// of type T from it, copying their contents in an SBData.
223  ///
224  /// \param[in] item_idx
225  /// The index of the first item to retrieve. For an array
226  /// this is equivalent to array[item_idx], for a pointer
227  /// to *(pointer + item_idx). In either case, the measurement
228  /// unit for item_idx is the sizeof(T) rather than the byte
229  ///
230  /// \param[in] item_count
231  /// How many items should be copied into the output. By default
232  /// only one item is copied, but more can be asked for.
233  ///
234  /// \return
235  /// An SBData with the contents of the copied items, on success.
236  /// An empty SBData otherwise.
237  lldb::SBData GetPointeeData(uint32_t item_idx = 0, uint32_t item_count = 1);
238 
239  /// Get an SBData wrapping the contents of this SBValue.
240  ///
241  /// This method will read the contents of this object in memory
242  /// and copy them into an SBData for future use.
243  ///
244  /// \return
245  /// An SBData with the contents of this SBValue, on success.
246  /// An empty SBData otherwise.
247  lldb::SBData GetData();
248 
249  bool SetData(lldb::SBData &data, lldb::SBError &error);
250 
251  lldb::SBDeclaration GetDeclaration();
252 
253  /// Find out if a SBValue might have children.
254  ///
255  /// This call is much more efficient than GetNumChildren() as it
256  /// doesn't need to complete the underlying type. This is designed
257  /// to be used in a UI environment in order to detect if the
258  /// disclosure triangle should be displayed or not.
259  ///
260  /// This function returns true for class, union, structure,
261  /// pointers, references, arrays and more. Again, it does so without
262  /// doing any expensive type completion.
263  ///
264  /// \return
265  /// Returns \b true if the SBValue might have children, or \b
266  /// false otherwise.
267  bool MightHaveChildren();
268 
269  bool IsRuntimeSupportValue();
270 
271  uint32_t GetNumChildren();
272 
273  uint32_t GetNumChildren(uint32_t max);
274 
275  void *GetOpaqueType();
276 
277  lldb::SBTarget GetTarget();
278 
279  lldb::SBProcess GetProcess();
280 
281  lldb::SBThread GetThread();
282 
283  lldb::SBFrame GetFrame();
284 
285  lldb::SBValue Dereference();
286 
287  // Deprecated - please use GetType().IsPointerType() instead.
288  bool TypeIsPointerType();
289 
290  lldb::SBType GetType();
291 
292  lldb::SBValue Persist();
293 
294  bool GetDescription(lldb::SBStream &description);
295 
296  bool GetExpressionPath(lldb::SBStream &description);
297 
298  bool GetExpressionPath(lldb::SBStream &description,
299  bool qualify_cxx_base_classes);
300 
301  lldb::SBValue EvaluateExpression(const char *expr) const;
302  lldb::SBValue EvaluateExpression(const char *expr,
303  const SBExpressionOptions &options) const;
304  lldb::SBValue EvaluateExpression(const char *expr,
305  const SBExpressionOptions &options,
306  const char *name) const;
307 
308  SBValue(const lldb::ValueObjectSP &value_sp);
309 
310  /// Watch this value if it resides in memory.
311  ///
312  /// Sets a watchpoint on the value.
313  ///
314  /// \param[in] resolve_location
315  /// Resolve the location of this value once and watch its address.
316  /// This value must currently be set to \b true as watching all
317  /// locations of a variable or a variable path is not yet supported,
318  /// though we plan to support it in the future.
319  ///
320  /// \param[in] read
321  /// Stop when this value is accessed.
322  ///
323  /// \param[in] write
324  /// Stop when this value is modified
325  ///
326  /// \param[out] error
327  /// An error object. Contains the reason if there is some failure.
328  ///
329  /// \return
330  /// An SBWatchpoint object. This object might not be valid upon
331  /// return due to a value not being contained in memory, too
332  /// large, or watchpoint resources are not available or all in
333  /// use.
334  lldb::SBWatchpoint Watch(bool resolve_location, bool read, bool write,
335  SBError &error);
336 
337  // Backward compatibility fix in the interim.
338  lldb::SBWatchpoint Watch(bool resolve_location, bool read, bool write);
339 
340  /// Watch this value that this value points to in memory
341  ///
342  /// Sets a watchpoint on the value.
343  ///
344  /// \param[in] resolve_location
345  /// Resolve the location of this value once and watch its address.
346  /// This value must currently be set to \b true as watching all
347  /// locations of a variable or a variable path is not yet supported,
348  /// though we plan to support it in the future.
349  ///
350  /// \param[in] read
351  /// Stop when this value is accessed.
352  ///
353  /// \param[in] write
354  /// Stop when this value is modified
355  ///
356  /// \param[out] error
357  /// An error object. Contains the reason if there is some failure.
358  ///
359  /// \return
360  /// An SBWatchpoint object. This object might not be valid upon
361  /// return due to a value not being contained in memory, too
362  /// large, or watchpoint resources are not available or all in
363  /// use.
364  lldb::SBWatchpoint WatchPointee(bool resolve_location, bool read, bool write,
365  SBError &error);
366 
367  /// Same as the protected version of GetSP that takes a locker, except that we
368  /// make the
369  /// locker locally in the function. Since the Target API mutex is recursive,
370  /// and the
371  /// StopLocker is a read lock, you can call this function even if you are
372  /// already
373  /// holding the two above-mentioned locks.
374  ///
375  /// \return
376  /// A ValueObjectSP of the best kind (static, dynamic or synthetic) we
377  /// can cons up, in accordance with the SBValue's settings.
378  lldb::ValueObjectSP GetSP() const;
379 
380 protected:
381  friend class SBBlock;
382  friend class SBFrame;
383  friend class SBTarget;
384  friend class SBThread;
385  friend class SBValueList;
386 
387  /// Get the appropriate ValueObjectSP from this SBValue, consulting the
388  /// use_dynamic and use_synthetic options passed in to SetSP when the
389  /// SBValue's contents were set. Since this often requires examining memory,
390  /// and maybe even running code, it needs to acquire the Target API and
391  /// Process StopLock.
392  /// Those are held in an opaque class ValueLocker which is currently local to
393  /// SBValue.cpp.
394  /// So you don't have to get these yourself just default construct a
395  /// ValueLocker, and pass it into this.
396  /// If we need to make a ValueLocker and use it in some other .cpp file, we'll
397  /// have to move it to
398  /// ValueObject.h/cpp or somewhere else convenient. We haven't needed to so
399  /// far.
400  ///
401  /// \param[in] value_locker
402  /// An object that will hold the Target API, and Process RunLocks, and
403  /// auto-destroy them when it goes out of scope. Currently this is only
404  /// useful in
405  /// SBValue.cpp.
406  ///
407  /// \return
408  /// A ValueObjectSP of the best kind (static, dynamic or synthetic) we
409  /// can cons up, in accordance with the SBValue's settings.
410  lldb::ValueObjectSP GetSP(ValueLocker &value_locker) const;
411 
412  // these calls do the right thing WRT adjusting their settings according to
413  // the target's preferences
414  void SetSP(const lldb::ValueObjectSP &sp);
415 
416  void SetSP(const lldb::ValueObjectSP &sp, bool use_synthetic);
417 
418  void SetSP(const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic);
419 
420  void SetSP(const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic,
421  bool use_synthetic);
422 
423  void SetSP(const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic,
424  bool use_synthetic, const char *name);
425 
426 private:
427  typedef std::shared_ptr<ValueImpl> ValueImplSP;
428  ValueImplSP m_opaque_sp;
429 
430  void SetSP(ValueImplSP impl_sp);
431 };
432 
433 } // namespace lldb
434 
435 #endif // LLDB_SBValue_h_
uint64_t user_id_t
Definition: lldb-types.h:84
class LLDB_API SBValue
Definition: SBDefines.h:90
#define LLDB_API
Definition: lldb-defines.h:23
uint64_t addr_t
Definition: lldb-types.h:83
Definition: SBAddress.h:15