[Lldb-commits] [lldb] [NFC][lldb] Document a few ivars on the value object system. (PR #124971)

Augusto Noronha via lldb-commits lldb-commits at lists.llvm.org
Thu Jan 30 14:26:15 PST 2025


https://github.com/augusto2112 updated https://github.com/llvm/llvm-project/pull/124971

>From c6a1cd5115894b9f075229e878796c8b343ecde9 Mon Sep 17 00:00:00 2001
From: Augusto Noronha <anoronha at apple.com>
Date: Wed, 29 Jan 2025 10:53:23 -0800
Subject: [PATCH 1/3] [NFC][lldb] Document a few ivars on the value object
 system.

---
 lldb/include/lldb/Core/Value.h                | 28 +++++++++++++++++++
 .../lldb/Expression/ExpressionVariable.h      | 11 +++++++-
 .../ValueObject/ValueObjectConstResultImpl.h  |  4 +++
 lldb/source/Expression/Materializer.cpp       |  3 ++
 4 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/lldb/include/lldb/Core/Value.h b/lldb/include/lldb/Core/Value.h
index d0c338ffec0cd3..3fd3ff1d2ccfa4 100644
--- a/lldb/include/lldb/Core/Value.h
+++ b/lldb/include/lldb/Core/Value.h
@@ -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);
@@ -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;
diff --git a/lldb/include/lldb/Expression/ExpressionVariable.h b/lldb/include/lldb/Expression/ExpressionVariable.h
index fc36793b3a475c..f5bd9389219668 100644
--- a/lldb/include/lldb/Expression/ExpressionVariable.h
+++ b/lldb/include/lldb/Expression/ExpressionVariable.h
@@ -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
diff --git a/lldb/include/lldb/ValueObject/ValueObjectConstResultImpl.h b/lldb/include/lldb/ValueObject/ValueObjectConstResultImpl.h
index dbd68160acb4dc..5509886a8965da 100644
--- a/lldb/include/lldb/ValueObject/ValueObjectConstResultImpl.h
+++ b/lldb/include/lldb/ValueObject/ValueObjectConstResultImpl.h
@@ -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;
diff --git a/lldb/source/Expression/Materializer.cpp b/lldb/source/Expression/Materializer.cpp
index 8cd050f9fdb7ef..13a72a9921e1d6 100644
--- a/lldb/source/Expression/Materializer.cpp
+++ b/lldb/source/Expression/Materializer.cpp
@@ -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;
 

>From 7d25616a93dbc0567b174eb711eecfee302e9827 Mon Sep 17 00:00:00 2001
From: Augusto Noronha <anoronha at apple.com>
Date: Thu, 30 Jan 2025 14:25:56 -0800
Subject: [PATCH 2/3] Update lldb/include/lldb/Core/Value.h

Co-authored-by: Jonas Devlieghere <jonas at devlieghere.com>
---
 lldb/include/lldb/Core/Value.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/include/lldb/Core/Value.h b/lldb/include/lldb/Core/Value.h
index 3fd3ff1d2ccfa4..a4eae469ea7379 100644
--- a/lldb/include/lldb/Core/Value.h
+++ b/lldb/include/lldb/Core/Value.h
@@ -158,7 +158,7 @@ class 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.
+  ///    host memory.
   ///   Currently, this can point to either:
   ///     - The `m_data_buffer` of this Value instance (e.g., in DWARF
   ///     computations).

>From 87eca7770ba2a747db1843a8abfdceaa2f4debf8 Mon Sep 17 00:00:00 2001
From: Augusto Noronha <anoronha at apple.com>
Date: Thu, 30 Jan 2025 14:26:06 -0800
Subject: [PATCH 3/3] Update lldb/include/lldb/Core/Value.h

Co-authored-by: Jonas Devlieghere <jonas at devlieghere.com>
---
 lldb/include/lldb/Core/Value.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lldb/include/lldb/Core/Value.h b/lldb/include/lldb/Core/Value.h
index a4eae469ea7379..3714621b469ecf 100644
--- a/lldb/include/lldb/Core/Value.h
+++ b/lldb/include/lldb/Core/Value.h
@@ -166,12 +166,12 @@ class 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).
+  //   load, file or host address).
   // - Rename GetScalar() to something more indicative to what the scalar is,
-  // like GetScalarOrAddress() for example.
+  //   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.
+  //   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



More information about the lldb-commits mailing list