|
|
|||
File indexing completed on 2026-05-10 08:42:43
0001 //===-- SBValue.h -----------------------------------------------*- C++ -*-===// 0002 // 0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 0004 // See https://llvm.org/LICENSE.txt for license information. 0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 0006 // 0007 //===----------------------------------------------------------------------===// 0008 0009 #ifndef LLDB_API_SBVALUE_H 0010 #define LLDB_API_SBVALUE_H 0011 0012 #include "lldb/API/SBData.h" 0013 #include "lldb/API/SBDefines.h" 0014 #include "lldb/API/SBType.h" 0015 0016 class ValueImpl; 0017 class ValueLocker; 0018 0019 namespace lldb_private { 0020 namespace python { 0021 class SWIGBridge; 0022 } 0023 } // namespace lldb_private 0024 0025 namespace lldb { 0026 0027 class LLDB_API SBValue { 0028 public: 0029 SBValue(); 0030 0031 SBValue(const lldb::SBValue &rhs); 0032 0033 lldb::SBValue &operator=(const lldb::SBValue &rhs); 0034 0035 ~SBValue(); 0036 0037 explicit operator bool() const; 0038 0039 bool IsValid(); 0040 0041 void Clear(); 0042 0043 SBError GetError(); 0044 0045 lldb::user_id_t GetID(); 0046 0047 const char *GetName(); 0048 0049 const char *GetTypeName(); 0050 0051 const char *GetDisplayTypeName(); 0052 0053 size_t GetByteSize(); 0054 0055 bool IsInScope(); 0056 0057 lldb::Format GetFormat(); 0058 0059 void SetFormat(lldb::Format format); 0060 0061 const char *GetValue(); 0062 0063 int64_t GetValueAsSigned(lldb::SBError &error, int64_t fail_value = 0); 0064 0065 uint64_t GetValueAsUnsigned(lldb::SBError &error, uint64_t fail_value = 0); 0066 0067 int64_t GetValueAsSigned(int64_t fail_value = 0); 0068 0069 uint64_t GetValueAsUnsigned(uint64_t fail_value = 0); 0070 0071 lldb::addr_t GetValueAsAddress(); 0072 0073 ValueType GetValueType(); 0074 0075 // If you call this on a newly created ValueObject, it will always return 0076 // false. 0077 bool GetValueDidChange(); 0078 0079 const char *GetSummary(); 0080 0081 const char *GetSummary(lldb::SBStream &stream, 0082 lldb::SBTypeSummaryOptions &options); 0083 0084 const char *GetObjectDescription(); 0085 0086 lldb::SBValue GetDynamicValue(lldb::DynamicValueType use_dynamic); 0087 0088 lldb::SBValue GetStaticValue(); 0089 0090 lldb::SBValue GetNonSyntheticValue(); 0091 0092 lldb::SBValue GetSyntheticValue(); 0093 0094 lldb::DynamicValueType GetPreferDynamicValue(); 0095 0096 void SetPreferDynamicValue(lldb::DynamicValueType use_dynamic); 0097 0098 bool GetPreferSyntheticValue(); 0099 0100 void SetPreferSyntheticValue(bool use_synthetic); 0101 0102 bool IsDynamic(); 0103 0104 bool IsSynthetic(); 0105 0106 bool IsSyntheticChildrenGenerated(); 0107 0108 void SetSyntheticChildrenGenerated(bool); 0109 0110 const char *GetLocation(); 0111 0112 LLDB_DEPRECATED_FIXME("Use the variant that takes an SBError &", 0113 "SetValueFromCString(const char *, SBError &)") 0114 bool SetValueFromCString(const char *value_str); 0115 0116 bool SetValueFromCString(const char *value_str, lldb::SBError &error); 0117 0118 lldb::SBTypeFormat GetTypeFormat(); 0119 0120 lldb::SBTypeSummary GetTypeSummary(); 0121 0122 lldb::SBTypeFilter GetTypeFilter(); 0123 0124 lldb::SBTypeSynthetic GetTypeSynthetic(); 0125 0126 lldb::SBValue GetChildAtIndex(uint32_t idx); 0127 0128 lldb::SBValue CreateChildAtOffset(const char *name, uint32_t offset, 0129 lldb::SBType type); 0130 0131 LLDB_DEPRECATED("Use the expression evaluator to perform type casting") 0132 lldb::SBValue Cast(lldb::SBType type); 0133 0134 lldb::SBValue CreateValueFromExpression(const char *name, 0135 const char *expression); 0136 0137 lldb::SBValue CreateValueFromExpression(const char *name, 0138 const char *expression, 0139 SBExpressionOptions &options); 0140 0141 lldb::SBValue CreateValueFromAddress(const char *name, lldb::addr_t address, 0142 lldb::SBType type); 0143 0144 // this has no address! GetAddress() and GetLoadAddress() as well as 0145 // AddressOf() on the return of this call all return invalid 0146 lldb::SBValue CreateValueFromData(const char *name, lldb::SBData data, 0147 lldb::SBType type); 0148 // Returned value has no address. 0149 lldb::SBValue CreateBoolValue(const char *name, bool value); 0150 0151 /// Get a child value by index from a value. 0152 /// 0153 /// Structs, unions, classes, arrays and pointers have child 0154 /// values that can be access by index. 0155 /// 0156 /// Structs and unions access child members using a zero based index 0157 /// for each child member. For 0158 /// 0159 /// Classes reserve the first indexes for base classes that have 0160 /// members (empty base classes are omitted), and all members of the 0161 /// current class will then follow the base classes. 0162 /// 0163 /// Pointers differ depending on what they point to. If the pointer 0164 /// points to a simple type, the child at index zero 0165 /// is the only child value available, unless \a synthetic_allowed 0166 /// is \b true, in which case the pointer will be used as an array 0167 /// and can create 'synthetic' child values using positive or 0168 /// negative indexes. If the pointer points to an aggregate type 0169 /// (an array, class, union, struct), then the pointee is 0170 /// transparently skipped and any children are going to be the indexes 0171 /// of the child values within the aggregate type. For example if 0172 /// we have a 'Point' type and we have a SBValue that contains a 0173 /// pointer to a 'Point' type, then the child at index zero will be 0174 /// the 'x' member, and the child at index 1 will be the 'y' member 0175 /// (the child at index zero won't be a 'Point' instance). 0176 /// 0177 /// If you actually need an SBValue that represents the type pointed 0178 /// to by a SBValue for which GetType().IsPointeeType() returns true, 0179 /// regardless of the pointee type, you can do that with SBValue::Dereference. 0180 /// 0181 /// Arrays have a preset number of children that can be accessed by 0182 /// index and will returns invalid child values for indexes that are 0183 /// out of bounds unless the \a synthetic_allowed is \b true. In this 0184 /// case the array can create 'synthetic' child values for indexes 0185 /// that aren't in the array bounds using positive or negative 0186 /// indexes. 0187 /// 0188 /// \param[in] idx 0189 /// The index of the child value to get 0190 /// 0191 /// \param[in] use_dynamic 0192 /// An enumeration that specifies whether to get dynamic values, 0193 /// and also if the target can be run to figure out the dynamic 0194 /// type of the child value. 0195 /// 0196 /// \param[in] can_create_synthetic 0197 /// If \b true, then allow child values to be created by index 0198 /// for pointers and arrays for indexes that normally wouldn't 0199 /// be allowed. 0200 /// 0201 /// \return 0202 /// A new SBValue object that represents the child member value. 0203 lldb::SBValue GetChildAtIndex(uint32_t idx, 0204 lldb::DynamicValueType use_dynamic, 0205 bool can_create_synthetic); 0206 0207 // Matches children of this object only and will match base classes and 0208 // member names if this is a clang typed object. 0209 uint32_t GetIndexOfChildWithName(const char *name); 0210 0211 // Matches child members of this object and child members of any base 0212 // classes. 0213 lldb::SBValue GetChildMemberWithName(const char *name); 0214 0215 // Matches child members of this object and child members of any base 0216 // classes. 0217 lldb::SBValue GetChildMemberWithName(const char *name, 0218 lldb::DynamicValueType use_dynamic); 0219 0220 // Expands nested expressions like .a->b[0].c[1]->d 0221 lldb::SBValue GetValueForExpressionPath(const char *expr_path); 0222 0223 lldb::SBValue AddressOf(); 0224 0225 lldb::addr_t GetLoadAddress(); 0226 0227 lldb::SBAddress GetAddress(); 0228 0229 /// Get an SBData wrapping what this SBValue points to. 0230 /// 0231 /// This method will dereference the current SBValue, if its 0232 /// data type is a T* or T[], and extract item_count elements 0233 /// of type T from it, copying their contents in an SBData. 0234 /// 0235 /// \param[in] item_idx 0236 /// The index of the first item to retrieve. For an array 0237 /// this is equivalent to array[item_idx], for a pointer 0238 /// to *(pointer + item_idx). In either case, the measurement 0239 /// unit for item_idx is the sizeof(T) rather than the byte 0240 /// 0241 /// \param[in] item_count 0242 /// How many items should be copied into the output. By default 0243 /// only one item is copied, but more can be asked for. 0244 /// 0245 /// \return 0246 /// An SBData with the contents of the copied items, on success. 0247 /// An empty SBData otherwise. 0248 lldb::SBData GetPointeeData(uint32_t item_idx = 0, uint32_t item_count = 1); 0249 0250 /// Get an SBData wrapping the contents of this SBValue. 0251 /// 0252 /// This method will read the contents of this object in memory 0253 /// and copy them into an SBData for future use. 0254 /// 0255 /// \return 0256 /// An SBData with the contents of this SBValue, on success. 0257 /// An empty SBData otherwise. 0258 lldb::SBData GetData(); 0259 0260 bool SetData(lldb::SBData &data, lldb::SBError &error); 0261 0262 /// Creates a copy of the SBValue with a new name and setting the current 0263 /// SBValue as its parent. It should be used when we want to change the 0264 /// name of a SBValue without modifying the actual SBValue itself 0265 /// (e.g. sythetic child provider). 0266 lldb::SBValue Clone(const char *new_name); 0267 0268 lldb::SBDeclaration GetDeclaration(); 0269 0270 /// Find out if a SBValue might have children. 0271 /// 0272 /// This call is much more efficient than GetNumChildren() as it 0273 /// doesn't need to complete the underlying type. This is designed 0274 /// to be used in a UI environment in order to detect if the 0275 /// disclosure triangle should be displayed or not. 0276 /// 0277 /// This function returns true for class, union, structure, 0278 /// pointers, references, arrays and more. Again, it does so without 0279 /// doing any expensive type completion. 0280 /// 0281 /// \return 0282 /// Returns \b true if the SBValue might have children, or \b 0283 /// false otherwise. 0284 bool MightHaveChildren(); 0285 0286 bool IsRuntimeSupportValue(); 0287 0288 /// Return the number of children of this variable. Note that for some 0289 /// variables this operation can be expensive. If possible, prefer calling 0290 /// GetNumChildren(max) with the maximum number of children you are interested 0291 /// in. 0292 uint32_t GetNumChildren(); 0293 0294 /// Return the numer of children of this variable, with a hint that the 0295 /// caller is interested in at most \a max children. Use this function to 0296 /// avoid expensive child computations in some cases. For example, if you know 0297 /// you will only ever display 100 elements, calling GetNumChildren(100) can 0298 /// avoid enumerating all the other children. If the returned value is smaller 0299 /// than \a max, then it represents the true number of children, otherwise it 0300 /// indicates that their number is at least \a max. Do not assume the returned 0301 /// number will always be less than or equal to \a max, as the implementation 0302 /// may choose to return a larger (but still smaller than the actual number of 0303 /// children) value. 0304 uint32_t GetNumChildren(uint32_t max); 0305 0306 LLDB_DEPRECATED("SBValue::GetOpaqueType() is deprecated.") 0307 void *GetOpaqueType(); 0308 0309 lldb::SBTarget GetTarget(); 0310 0311 lldb::SBProcess GetProcess(); 0312 0313 lldb::SBThread GetThread(); 0314 0315 lldb::SBFrame GetFrame(); 0316 0317 lldb::SBValue Dereference(); 0318 0319 LLDB_DEPRECATED("Use GetType().IsPointerType() instead") 0320 bool TypeIsPointerType(); 0321 0322 lldb::SBType GetType(); 0323 0324 lldb::SBValue Persist(); 0325 0326 bool GetDescription(lldb::SBStream &description); 0327 0328 bool GetExpressionPath(lldb::SBStream &description); 0329 0330 bool GetExpressionPath(lldb::SBStream &description, 0331 bool qualify_cxx_base_classes); 0332 0333 lldb::SBValue EvaluateExpression(const char *expr) const; 0334 lldb::SBValue EvaluateExpression(const char *expr, 0335 const SBExpressionOptions &options) const; 0336 lldb::SBValue EvaluateExpression(const char *expr, 0337 const SBExpressionOptions &options, 0338 const char *name) const; 0339 0340 /// Watch this value if it resides in memory. 0341 /// 0342 /// Sets a watchpoint on the value. 0343 /// 0344 /// \param[in] resolve_location 0345 /// Resolve the location of this value once and watch its address. 0346 /// This value must currently be set to \b true as watching all 0347 /// locations of a variable or a variable path is not yet supported, 0348 /// though we plan to support it in the future. 0349 /// 0350 /// \param[in] read 0351 /// Stop when this value is accessed. 0352 /// 0353 /// \param[in] write 0354 /// Stop when this value is modified 0355 /// 0356 /// \param[out] error 0357 /// An error object. Contains the reason if there is some failure. 0358 /// 0359 /// \return 0360 /// An SBWatchpoint object. This object might not be valid upon 0361 /// return due to a value not being contained in memory, too 0362 /// large, or watchpoint resources are not available or all in 0363 /// use. 0364 lldb::SBWatchpoint Watch(bool resolve_location, bool read, bool write, 0365 SBError &error); 0366 0367 // Backward compatibility fix in the interim. 0368 lldb::SBWatchpoint Watch(bool resolve_location, bool read, bool write); 0369 0370 /// Watch this value that this value points to in memory 0371 /// 0372 /// Sets a watchpoint on the value. 0373 /// 0374 /// \param[in] resolve_location 0375 /// Resolve the location of this value once and watch its address. 0376 /// This value must currently be set to \b true as watching all 0377 /// locations of a variable or a variable path is not yet supported, 0378 /// though we plan to support it in the future. 0379 /// 0380 /// \param[in] read 0381 /// Stop when this value is accessed. 0382 /// 0383 /// \param[in] write 0384 /// Stop when this value is modified 0385 /// 0386 /// \param[out] error 0387 /// An error object. Contains the reason if there is some failure. 0388 /// 0389 /// \return 0390 /// An SBWatchpoint object. This object might not be valid upon 0391 /// return due to a value not being contained in memory, too 0392 /// large, or watchpoint resources are not available or all in 0393 /// use. 0394 lldb::SBWatchpoint WatchPointee(bool resolve_location, bool read, bool write, 0395 SBError &error); 0396 0397 /// If this value represents a C++ class that has a vtable, return an value 0398 /// that represents the virtual function table. 0399 /// 0400 /// SBValue::GetError() will be in the success state if this value represents 0401 /// a C++ class with a vtable, or an appropriate error describing that the 0402 /// object isn't a C++ class with a vtable or not a C++ class. 0403 /// 0404 /// SBValue::GetName() will be the demangled symbol name for the virtual 0405 /// function table like "vtable for <classname>". 0406 /// 0407 /// SBValue::GetValue() will be the address of the first vtable entry if the 0408 /// current SBValue is a class with a vtable, or nothing the current SBValue 0409 /// is not a C++ class or not a C++ class that has a vtable. 0410 /// 0411 /// SBValue::GetValueAtUnsigned(...) will return the address of the first 0412 /// vtable entry. 0413 /// 0414 /// SBValue::GetLoadAddress() will return the address of the vtable pointer 0415 /// found in the parent SBValue. 0416 /// 0417 /// SBValue::GetNumChildren() will return the number of virtual function 0418 /// pointers in the vtable, or zero on error. 0419 /// 0420 /// SBValue::GetChildAtIndex(...) will return each virtual function pointer 0421 /// as a SBValue object. 0422 /// 0423 /// The child SBValue objects will have the following values: 0424 /// 0425 /// SBValue::GetError() will indicate success if the vtable entry was 0426 /// successfully read from memory, or an error if not. 0427 /// 0428 /// SBValue::GetName() will be the vtable function index in the form "[%u]" 0429 /// where %u is the index. 0430 /// 0431 /// SBValue::GetValue() will be the virtual function pointer value as a 0432 /// string. 0433 /// 0434 /// SBValue::GetValueAtUnsigned(...) will return the virtual function 0435 /// pointer value. 0436 /// 0437 /// SBValue::GetLoadAddress() will return the address of the virtual function 0438 /// pointer. 0439 /// 0440 /// SBValue::GetNumChildren() returns 0 0441 lldb::SBValue GetVTable(); 0442 0443 protected: 0444 friend class SBBlock; 0445 friend class SBFrame; 0446 friend class SBModule; 0447 friend class SBTarget; 0448 friend class SBThread; 0449 friend class SBTypeStaticField; 0450 friend class SBTypeSummary; 0451 friend class SBValueList; 0452 0453 friend class lldb_private::python::SWIGBridge; 0454 0455 SBValue(const lldb::ValueObjectSP &value_sp); 0456 0457 /// Same as the protected version of GetSP that takes a locker, except that we 0458 /// make the 0459 /// locker locally in the function. Since the Target API mutex is recursive, 0460 /// and the 0461 /// StopLocker is a read lock, you can call this function even if you are 0462 /// already 0463 /// holding the two above-mentioned locks. 0464 /// 0465 /// \return 0466 /// A ValueObjectSP of the best kind (static, dynamic or synthetic) we 0467 /// can cons up, in accordance with the SBValue's settings. 0468 lldb::ValueObjectSP GetSP() const; 0469 0470 /// Get the appropriate ValueObjectSP from this SBValue, consulting the 0471 /// use_dynamic and use_synthetic options passed in to SetSP when the 0472 /// SBValue's contents were set. Since this often requires examining memory, 0473 /// and maybe even running code, it needs to acquire the Target API and 0474 /// Process StopLock. 0475 /// Those are held in an opaque class ValueLocker which is currently local to 0476 /// SBValue.cpp. 0477 /// So you don't have to get these yourself just default construct a 0478 /// ValueLocker, and pass it into this. 0479 /// If we need to make a ValueLocker and use it in some other .cpp file, we'll 0480 /// have to move it to 0481 /// ValueObject.h/cpp or somewhere else convenient. We haven't needed to so 0482 /// far. 0483 /// 0484 /// \param[in] value_locker 0485 /// An object that will hold the Target API, and Process RunLocks, and 0486 /// auto-destroy them when it goes out of scope. Currently this is only 0487 /// useful in 0488 /// SBValue.cpp. 0489 /// 0490 /// \return 0491 /// A ValueObjectSP of the best kind (static, dynamic or synthetic) we 0492 /// can cons up, in accordance with the SBValue's settings. 0493 lldb::ValueObjectSP GetSP(ValueLocker &value_locker) const; 0494 0495 // these calls do the right thing WRT adjusting their settings according to 0496 // the target's preferences 0497 void SetSP(const lldb::ValueObjectSP &sp); 0498 0499 void SetSP(const lldb::ValueObjectSP &sp, bool use_synthetic); 0500 0501 void SetSP(const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic); 0502 0503 void SetSP(const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic, 0504 bool use_synthetic); 0505 0506 void SetSP(const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic, 0507 bool use_synthetic, const char *name); 0508 0509 private: 0510 typedef std::shared_ptr<ValueImpl> ValueImplSP; 0511 ValueImplSP m_opaque_sp; 0512 0513 void SetSP(ValueImplSP impl_sp); 0514 }; 0515 0516 } // namespace lldb 0517 0518 #endif // LLDB_API_SBVALUE_H
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|