-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[LLDB] Add more helper functions to ValueObject class. #87197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
68cb68d
b6a1e23
145e74b
22e1b06
b8eee30
8709f70
1e41bfa
28748a9
499a097
fa25850
d4e7f69
6ca00e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -441,6 +441,30 @@ class ValueObject { | |
|
||
virtual int64_t GetValueAsSigned(int64_t fail_value, bool *success = nullptr); | ||
|
||
/// If the current ValueObject is of an appropriate type, convert the | ||
/// value to an APSInt and return that. Otherwise return an error. | ||
llvm::Expected<llvm::APSInt> GetValueAsAPSInt(); | ||
|
||
/// If the current ValueObject is of an appropriate type, convert the | ||
/// value to an APFloat and return that. Otherwise return an error. | ||
llvm::Expected<llvm::APFloat> GetValueAsAPFloat(); | ||
|
||
/// If the current ValueObject is of an appropriate type, convert the | ||
/// value to a boolean and return that. Otherwise return an error. | ||
llvm::Expected<bool> GetValueAsBool(); | ||
|
||
/// Update an existing integer ValueObject with a new integer value. This | ||
/// is only intended to be used with 'temporary' ValueObjects, i.e. ones that | ||
/// are not associated with program variables. It does not update program | ||
/// memory, registers, stack, etc. | ||
void SetValueFromInteger(const llvm::APInt &value, Status &error); | ||
|
||
/// Update an existing integer ValueObject with an integer value created | ||
/// frome 'new_val_sp'. This is only intended to be used with 'temporary' | ||
/// ValueObjects, i.e. ones that are not associated with program variables. | ||
/// It does not update program memory, registers, stack, etc. | ||
void SetValueFromInteger(lldb::ValueObjectSP new_val_sp, Status &error); | ||
|
||
virtual bool SetValueFromCString(const char *value_str, Status &error); | ||
|
||
/// Return the module associated with this value object in case the value is | ||
|
@@ -618,6 +642,32 @@ class ValueObject { | |
virtual lldb::ValueObjectSP CastPointerType(const char *name, | ||
lldb::TypeSP &type_sp); | ||
|
||
/// Return the target load address associated with this value object. | ||
lldb::addr_t GetLoadAddress(); | ||
|
||
/// Take a ValueObject whose type is an inherited class, and cast it to | ||
/// 'type', which should be one of its base classes. 'base_type_indices' | ||
/// contains the indices of direct base classes on the path from the | ||
/// ValueObject's current type to 'type' | ||
llvm::Expected<lldb::ValueObjectSP> | ||
CastDerivedToBaseType(CompilerType type, | ||
const llvm::ArrayRef<uint32_t> &base_type_indices); | ||
|
||
/// Take a ValueObject whose type is a base class, and cast it to 'type', | ||
/// which should be one of its derived classes. 'base_type_indices' | ||
/// contains the indices of direct base classes on the path from the | ||
/// ValueObject's current type to 'type' | ||
llvm::Expected<lldb::ValueObjectSP> CastBaseToDerivedType(CompilerType type, | ||
uint64_t offset); | ||
|
||
// Take a ValueObject that contains a scalar, enum or pointer type, and | ||
// cast it to a "basic" type (integer, float or boolean). | ||
lldb::ValueObjectSP CastToBasicType(CompilerType type); | ||
|
||
// Take a ValueObject that contain an integer, float or enum, and cast it | ||
// to an enum. | ||
lldb::ValueObjectSP CastToEnumType(CompilerType type); | ||
|
||
/// If this object represents a C++ class with a vtable, return an object | ||
/// that represents the virtual function table. If the object isn't a class | ||
/// with a vtable, return a valid ValueObject with the error set correctly. | ||
|
@@ -659,15 +709,41 @@ class ValueObject { | |
const ExecutionContext &exe_ctx, | ||
const EvaluateExpressionOptions &options); | ||
|
||
/// Given an address either create a value object containing the value at | ||
/// that address, or create a value object containing the address itself | ||
/// (pointer value), depending on whether the parameter 'do_deref' is true or | ||
/// false. | ||
static lldb::ValueObjectSP | ||
CreateValueObjectFromAddress(llvm::StringRef name, uint64_t address, | ||
const ExecutionContext &exe_ctx, | ||
CompilerType type); | ||
CompilerType type, bool do_deref = true); | ||
|
||
static lldb::ValueObjectSP | ||
CreateValueObjectFromData(llvm::StringRef name, const DataExtractor &data, | ||
const ExecutionContext &exe_ctx, CompilerType type); | ||
|
||
/// Create a value object containing the given APInt value. | ||
static lldb::ValueObjectSP CreateValueObjectFromAPInt(lldb::TargetSP target, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto for adding a name parameter. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
const llvm::APInt &v, | ||
CompilerType type, | ||
llvm::StringRef name); | ||
|
||
/// Create a value object containing the given APFloat value. | ||
static lldb::ValueObjectSP | ||
CreateValueObjectFromAPFloat(lldb::TargetSP target, const llvm::APFloat &v, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto for adding a name parameter. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
CompilerType type, llvm::StringRef name); | ||
|
||
/// Create a value object containing the given boolean value. | ||
static lldb::ValueObjectSP CreateValueObjectFromBool(lldb::TargetSP target, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. name arg? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
bool value, | ||
llvm::StringRef name); | ||
|
||
/// Create a nullptr value object with the specified type (must be a | ||
/// nullptr type). | ||
static lldb::ValueObjectSP CreateValueObjectFromNullptr(lldb::TargetSP target, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. name arg? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
CompilerType type, | ||
llvm::StringRef name); | ||
|
||
lldb::ValueObjectSP Persist(); | ||
|
||
/// Returns true if this is a char* or a char[] if it is a char* and | ||
|
@@ -719,6 +795,10 @@ class ValueObject { | |
ClearUserVisibleData(eClearUserVisibleDataItemsSummary); | ||
} | ||
|
||
void SetDerefValobj(ValueObject *deref) { m_deref_valobj = deref; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Synthetic child providers also have a way to provide the deref ValueObject dynamically. How do these two ways of doing that job work together? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I use the synthetic child providers way of getting the deref ValueObject to get the value I use for my call to SetDerefValobj (when I'm converting a ValueObject containing a SmartPointer into a ValueObject containing the pointer the SmartPointer was referencing). |
||
|
||
ValueObject *GetDerefValobj() { return m_deref_valobj; } | ||
|
||
void SetValueFormat(lldb::TypeFormatImplSP format) { | ||
m_type_format_sp = std::move(format); | ||
ClearUserVisibleData(eClearUserVisibleDataItemsValue); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this function just a copy of the contents of
lldb::addr_t SBValue::GetLoadAddress()
? If so, we should also fix that function to call this function. Might be nice to have this returnstd::optional<lldb::addr_t>
for internal use as if theValueObject
is a variable that is in a register, this will need to returnLLDB_INVALID_ADDRESS
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is based on SBValue::GetLoadAddress; I'll update that one to call this one. As written, it already does return LLDB_INVALID_ADDRESS in certain cases...I'm not sure what you want me to do differently (probably better to discuss this at the implementation rather than the declaration).