Skip to content

Commit 6a05bee

Browse files
[NFC][lldb] Document a few ivars on the value object system. (#124971)
Co-authored-by: Jonas Devlieghere <[email protected]>
1 parent 26c2da5 commit 6a05bee

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

lldb/include/lldb/Core/Value.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,10 @@ class Value {
109109

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

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

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

116118
size_t ResizeData(size_t len);
@@ -148,6 +150,32 @@ class Value {
148150
static ValueType GetValueTypeFromAddressType(AddressType address_type);
149151

150152
protected:
153+
/// Represents a value, which can be a scalar, a load address, a file address,
154+
/// or a host address.
155+
///
156+
/// The interpretation of `m_value` depends on `m_value_type`:
157+
/// - Scalar: `m_value` contains the scalar value.
158+
/// - Load Address: `m_value` contains the load address.
159+
/// - File Address: `m_value` contains the file address.
160+
/// - Host Address: `m_value` contains a pointer to the start of the buffer in
161+
/// host memory.
162+
/// Currently, this can point to either:
163+
/// - The `m_data_buffer` of this Value instance (e.g., in DWARF
164+
/// computations).
165+
/// - The `m_data` of a Value Object containing this Value.
166+
// TODO: the GetScalar() API relies on knowledge not codified by the type
167+
// system, making it hard to understand and easy to misuse.
168+
// - Separate the scalar from the variable that contains the address (be it a
169+
// load, file or host address).
170+
// - Rename GetScalar() to something more indicative to what the scalar is,
171+
// like GetScalarOrAddress() for example.
172+
// - Split GetScalar() into two functions, GetScalar() and GetAddress(), which
173+
// verify (or assert) what m_value_type is to make sure users of the class are
174+
// querying the right thing.
175+
// TODO: It's confusing to point to multiple possible buffers when the
176+
// ValueType is a host address. Value should probably always own its buffer.
177+
// Perhaps as a shared pointer with a copy on write system if the same buffer
178+
// can be shared by multiple classes.
151179
Scalar m_value;
152180
CompilerType m_compiler_type;
153181
void *m_context = nullptr;

lldb/include/lldb/Expression/ExpressionVariable.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,18 @@ class ExpressionVariable
107107

108108
FlagType m_flags; // takes elements of Flags
109109

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

115124
/// \class ExpressionVariableList ExpressionVariable.h

lldb/include/lldb/ValueObject/ValueObjectConstResultImpl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ class ValueObjectConstResultImpl {
6666

6767
private:
6868
ValueObject *m_impl_backend;
69+
/// The memory address in the inferior process that this ValueObject tracks.
70+
/// This address is used to request additional memory when the actual data
71+
/// size exceeds the initial local buffer size, such as when a dynamic type
72+
/// resolution results in a type larger than its statically determined type.
6973
lldb::addr_t m_live_address;
7074
AddressType m_live_address_type;
7175
lldb::ValueObjectSP m_address_of_backend;

lldb/source/Expression/Materializer.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,9 @@ class EntityResultVariable : public Materializer::Entity {
11871187

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

0 commit comments

Comments
 (0)