1 //===-- SBValue.h -----------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLDB_SBValue_h_
11 #define LLDB_SBValue_h_
13 #include "lldb/API/SBData.h"
14 #include "lldb/API/SBDefines.h"
15 #include "lldb/API/SBType.h"
24 friend class ValueLocker;
29 SBValue (const lldb::SBValue &rhs);
32 operator =(const lldb::SBValue &rhs);
64 SetFormat (lldb::Format format);
70 GetValueAsSigned (lldb::SBError& error, int64_t fail_value=0);
73 GetValueAsUnsigned (lldb::SBError& error, uint64_t fail_value=0);
76 GetValueAsSigned(int64_t fail_value=0);
79 GetValueAsUnsigned(uint64_t fail_value=0);
91 GetObjectDescription ();
94 GetDynamicValue (lldb::DynamicValueType use_dynamic);
100 GetNonSyntheticValue ();
102 lldb::DynamicValueType
103 GetPreferDynamicValue ();
106 SetPreferDynamicValue (lldb::DynamicValueType use_dynamic);
109 GetPreferSyntheticValue ();
112 SetPreferSyntheticValue (bool use_synthetic);
123 // Deprecated - use the one that takes SBError&
125 SetValueFromCString (const char *value_str);
128 SetValueFromCString (const char *value_str, lldb::SBError& error);
133 #ifndef LLDB_DISABLE_PYTHON
141 #ifndef LLDB_DISABLE_PYTHON
142 lldb::SBTypeSynthetic
147 GetChildAtIndex (uint32_t idx);
150 CreateChildAtOffset (const char *name, uint32_t offset, lldb::SBType type);
153 Cast (lldb::SBType type);
156 CreateValueFromExpression (const char *name, const char* expression);
159 CreateValueFromExpression (const char *name, const char* expression, SBExpressionOptions &options);
162 CreateValueFromAddress (const char* name,
163 lldb::addr_t address,
166 // this has no address! GetAddress() and GetLoadAddress() as well as AddressOf()
167 // on the return of this call all return invalid
169 CreateValueFromData (const char* name,
173 //------------------------------------------------------------------
174 /// Get a child value by index from a value.
176 /// Structs, unions, classes, arrays and and pointers have child
177 /// values that can be access by index.
179 /// Structs and unions access child members using a zero based index
180 /// for each child member. For
182 /// Classes reserve the first indexes for base classes that have
183 /// members (empty base classes are omitted), and all members of the
184 /// current class will then follow the base classes.
186 /// Pointers differ depending on what they point to. If the pointer
187 /// points to a simple type, the child at index zero
188 /// is the only child value available, unless \a synthetic_allowed
189 /// is \b true, in which case the pointer will be used as an array
190 /// and can create 'synthetic' child values using positive or
191 /// negative indexes. If the pointer points to an aggregate type
192 /// (an array, class, union, struct), then the pointee is
193 /// transparently skipped and any children are going to be the indexes
194 /// of the child values within the aggregate type. For example if
195 /// we have a 'Point' type and we have a SBValue that contains a
196 /// pointer to a 'Point' type, then the child at index zero will be
197 /// the 'x' member, and the child at index 1 will be the 'y' member
198 /// (the child at index zero won't be a 'Point' instance).
200 /// Arrays have a preset number of children that can be accessed by
201 /// index and will returns invalid child values for indexes that are
202 /// out of bounds unless the \a synthetic_allowed is \b true. In this
203 /// case the array can create 'synthetic' child values for indexes
204 /// that aren't in the array bounds using positive or negative
208 /// The index of the child value to get
210 /// @param[in] use_dynamic
211 /// An enumeration that specifies wether to get dynamic values,
212 /// and also if the target can be run to figure out the dynamic
213 /// type of the child value.
215 /// @param[in] synthetic_allowed
216 /// If \b true, then allow child values to be created by index
217 /// for pointers and arrays for indexes that normally wouldn't
221 /// A new SBValue object that represents the child member value.
222 //------------------------------------------------------------------
224 GetChildAtIndex (uint32_t idx,
225 lldb::DynamicValueType use_dynamic,
226 bool can_create_synthetic);
228 // Matches children of this object only and will match base classes and
229 // member names if this is a clang typed object.
231 GetIndexOfChildWithName (const char *name);
233 // Matches child members of this object and child members of any base
236 GetChildMemberWithName (const char *name);
238 // Matches child members of this object and child members of any base
241 GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic);
243 // Expands nested expressions like .a->b[0].c[1]->d
245 GetValueForExpressionPath(const char* expr_path);
256 //------------------------------------------------------------------
257 /// Get an SBData wrapping what this SBValue points to.
259 /// This method will dereference the current SBValue, if its
260 /// data type is a T* or T[], and extract item_count elements
261 /// of type T from it, copying their contents in an SBData.
263 /// @param[in] item_idx
264 /// The index of the first item to retrieve. For an array
265 /// this is equivalent to array[item_idx], for a pointer
266 /// to *(pointer + item_idx). In either case, the measurement
267 /// unit for item_idx is the sizeof(T) rather than the byte
269 /// @param[in] item_count
270 /// How many items should be copied into the output. By default
271 /// only one item is copied, but more can be asked for.
274 /// An SBData with the contents of the copied items, on success.
275 /// An empty SBData otherwise.
276 //------------------------------------------------------------------
278 GetPointeeData (uint32_t item_idx = 0,
279 uint32_t item_count = 1);
281 //------------------------------------------------------------------
282 /// Get an SBData wrapping the contents of this SBValue.
284 /// This method will read the contents of this object in memory
285 /// and copy them into an SBData for future use.
288 /// An SBData with the contents of this SBValue, on success.
289 /// An empty SBData otherwise.
290 //------------------------------------------------------------------
295 SetData (lldb::SBData &data, lldb::SBError& error);
300 //------------------------------------------------------------------
301 /// Find out if a SBValue might have children.
303 /// This call is much more efficient than GetNumChildren() as it
304 /// doesn't need to complete the underlying type. This is designed
305 /// to be used in a UI environment in order to detect if the
306 /// disclosure triangle should be displayed or not.
308 /// This function returns true for class, union, structure,
309 /// pointers, references, arrays and more. Again, it does so without
310 /// doing any expensive type completion.
313 /// Returns \b true if the SBValue might have children, or \b
315 //------------------------------------------------------------------
317 MightHaveChildren ();
341 TypeIsPointerType ();
347 GetDescription (lldb::SBStream &description);
350 GetExpressionPath (lldb::SBStream &description);
353 GetExpressionPath (lldb::SBStream &description,
354 bool qualify_cxx_base_classes);
356 SBValue (const lldb::ValueObjectSP &value_sp);
358 //------------------------------------------------------------------
359 /// Watch this value if it resides in memory.
361 /// Sets a watchpoint on the value.
363 /// @param[in] resolve_location
364 /// Resolve the location of this value once and watch its address.
365 /// This value must currently be set to \b true as watching all
366 /// locations of a variable or a variable path is not yet supported,
367 /// though we plan to support it in the future.
370 /// Stop when this value is accessed.
373 /// Stop when this value is modified
376 /// An error object. Contains the reason if there is some failure.
379 /// An SBWatchpoint object. This object might not be valid upon
380 /// return due to a value not being contained in memory, too
381 /// large, or watchpoint resources are not available or all in
383 //------------------------------------------------------------------
385 Watch (bool resolve_location, bool read, bool write, SBError &error);
387 // Backward compatibility fix in the interim.
389 Watch (bool resolve_location, bool read, bool write);
391 //------------------------------------------------------------------
392 /// Watch this value that this value points to in memory
394 /// Sets a watchpoint on the value.
396 /// @param[in] resolve_location
397 /// Resolve the location of this value once and watch its address.
398 /// This value must currently be set to \b true as watching all
399 /// locations of a variable or a variable path is not yet supported,
400 /// though we plan to support it in the future.
403 /// Stop when this value is accessed.
406 /// Stop when this value is modified
409 /// An error object. Contains the reason if there is some failure.
412 /// An SBWatchpoint object. This object might not be valid upon
413 /// return due to a value not being contained in memory, too
414 /// large, or watchpoint resources are not available or all in
416 //------------------------------------------------------------------
418 WatchPointee (bool resolve_location, bool read, bool write, SBError &error);
420 //------------------------------------------------------------------
421 /// Same as the protected version of GetSP that takes a locker, except that we make the
422 /// locker locally in the function. Since the Target API mutex is recursive, and the
423 /// StopLocker is a read lock, you can call this function even if you are already
424 /// holding the two above-mentioned locks.
427 /// A ValueObjectSP of the best kind (static, dynamic or synthetic) we
428 /// can cons up, in accordance with the SBValue's settings.
429 //------------------------------------------------------------------
434 friend class SBBlock;
435 friend class SBFrame;
436 friend class SBTarget;
437 friend class SBThread;
438 friend class SBValueList;
440 //------------------------------------------------------------------
441 /// Get the appropriate ValueObjectSP from this SBValue, consulting the
442 /// use_dynamic and use_synthetic options passed in to SetSP when the
443 /// SBValue's contents were set. Since this often requires examining memory,
444 /// and maybe even running code, it needs to acquire the Target API and Process StopLock.
445 /// Those are held in an opaque class ValueLocker which is currently local to SBValue.cpp.
446 /// So you don't have to get these yourself just default construct a ValueLocker, and pass it into this.
447 /// If we need to make a ValueLocker and use it in some other .cpp file, we'll have to move it to
448 /// ValueObject.h/cpp or somewhere else convenient. We haven't needed to so far.
450 /// @param[in] value_locker
451 /// An object that will hold the Target API, and Process RunLocks, and
452 /// auto-destroy them when it goes out of scope. Currently this is only useful in
456 /// A ValueObjectSP of the best kind (static, dynamic or synthetic) we
457 /// can cons up, in accordance with the SBValue's settings.
458 //------------------------------------------------------------------
460 GetSP (ValueLocker &value_locker) const;
462 // these calls do the right thing WRT adjusting their settings according to the target's preferences
464 SetSP (const lldb::ValueObjectSP &sp);
467 SetSP (const lldb::ValueObjectSP &sp, bool use_synthetic);
470 SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic);
473 SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic, bool use_synthetic);
476 SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic, bool use_synthetic, const char *name);
479 typedef std::shared_ptr<ValueImpl> ValueImplSP;
480 ValueImplSP m_opaque_sp;
483 SetSP (ValueImplSP impl_sp);
488 #endif // LLDB_SBValue_h_