Skip to content

[NFC][lldb] Document a few ivars on the value object system. #124971

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

Merged
merged 3 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions lldb/include/lldb/Core/Value.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,10 @@ class Value {

Scalar &ResolveValue(ExecutionContext *exe_ctx, Module *module = nullptr);

/// See comment on m_scalar to understand what GetScalar returns.
const Scalar &GetScalar() const { return m_value; }

/// See comment on m_scalar to understand what GetScalar returns.
Scalar &GetScalar() { return m_value; }

size_t ResizeData(size_t len);
Expand Down Expand Up @@ -148,6 +150,32 @@ class Value {
static ValueType GetValueTypeFromAddressType(AddressType address_type);

protected:
/// Represents a value, which can be a scalar, a load address, a file address,
/// or a host address.
///
/// The interpretation of `m_value` depends on `m_value_type`:
/// - Scalar: `m_value` contains the scalar value.
/// - Load Address: `m_value` contains the load address.
/// - File Address: `m_value` contains the file address.
/// - Host Address: `m_value` contains a pointer to the start of the buffer in
/// host memory.
/// Currently, this can point to either:
/// - The `m_data_buffer` of this Value instance (e.g., in DWARF
/// computations).
/// - The `m_data` of a Value Object containing this Value.
// TODO: the GetScalar() API relies on knowledge not codified by the type
// system, making it hard to understand and easy to misuse.
// - Separate the scalar from the variable that contains the address (be it a
// load, file or host address).
// - Rename GetScalar() to something more indicative to what the scalar is,
// like GetScalarOrAddress() for example.
// - Split GetScalar() into two functions, GetScalar() and GetAddress(), which
// verify (or assert) what m_value_type is to make sure users of the class are
// querying the right thing.
// TODO: It's confusing to point to multiple possible buffers when the
// ValueType is a host address. Value should probably always own its buffer.
// Perhaps as a shared pointer with a copy on write system if the same buffer
// can be shared by multiple classes.
Scalar m_value;
CompilerType m_compiler_type;
void *m_context = nullptr;
Expand Down
11 changes: 10 additions & 1 deletion lldb/include/lldb/Expression/ExpressionVariable.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,18 @@ class ExpressionVariable

FlagType m_flags; // takes elements of Flags

// these should be private
/// These members should be private.
/// @{
/// A value object whose value's data lives in host (lldb's) memory.
lldb::ValueObjectSP m_frozen_sp;
/// The ValueObject counterpart to m_frozen_sp that tracks the value in
/// inferior memory. This object may not always exist; its presence depends on
/// whether it is logical for the value to exist in the inferior memory. For
/// example, when evaluating a C++ expression that generates an r-value, such
/// as a single function call, there is no memory address in the inferior to
/// track.
lldb::ValueObjectSP m_live_sp;
/// @}
};

/// \class ExpressionVariableList ExpressionVariable.h
Expand Down
4 changes: 4 additions & 0 deletions lldb/include/lldb/ValueObject/ValueObjectConstResultImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ class ValueObjectConstResultImpl {

private:
ValueObject *m_impl_backend;
/// The memory address in the inferior process that this ValueObject tracks.
/// This address is used to request additional memory when the actual data
/// size exceeds the initial local buffer size, such as when a dynamic type
/// resolution results in a type larger than its statically determined type.
lldb::addr_t m_live_address;
AddressType m_live_address_type;
lldb::ValueObjectSP m_address_of_backend;
Expand Down
3 changes: 3 additions & 0 deletions lldb/source/Expression/Materializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,9 @@ class EntityResultVariable : public Materializer::Entity {

private:
CompilerType m_type;
/// This is used both to control whether this result entity can (and should)
/// track the value in inferior memory, as well as to control whether LLDB
/// needs to allocate memory for the variable during materialization.
bool m_is_program_reference;
bool m_keep_in_memory;

Expand Down
Loading