[Lldb-commits] [lldb] Add the ability to pass a parent to ValueObjectMemory::Create. (PR #195155)
via lldb-commits
lldb-commits at lists.llvm.org
Thu Apr 30 11:57:51 PDT 2026
https://github.com/jimingham created https://github.com/llvm/llvm-project/pull/195155
Also move the equivalent helper function from ValueObjectConstResult to ValueObject.h where it more properly belongs.
This patch is necessary if one were to use ValueObjectMemory for a synthetic child. There aren't any current uses of this sort in lldb, though there are on the swift fork.
>From 5be51c2553b4c9115cad3137372458d59800b399 Mon Sep 17 00:00:00 2001
From: Jim Ingham <jingham at apple.com>
Date: Thu, 30 Apr 2026 11:52:41 -0700
Subject: [PATCH] Add the ability to pass a parent to
ValueObjectMemory::Create. Also move the equivalent helper function from
ValueObjectConstResult to ValueObject.h where it more properly belongs.
This patch is necessary if one were to use ValueObjectMemory for
a synthetic child. There aren't any current uses of this sort in
lldb, though there are on the swift fork.
---
lldb/include/lldb/ValueObject/ValueObject.h | 31 +++++++++++++++++++
.../lldb/ValueObject/ValueObjectConstResult.h | 10 ------
.../lldb/ValueObject/ValueObjectMemory.h | 6 ++--
.../ValueObject/ValueObjectConstResult.cpp | 2 +-
lldb/source/ValueObject/ValueObjectMemory.cpp | 13 +++++---
5 files changed, 45 insertions(+), 17 deletions(-)
diff --git a/lldb/include/lldb/ValueObject/ValueObject.h b/lldb/include/lldb/ValueObject/ValueObject.h
index bf4c47a4b9fe1..6ff096cc19d31 100644
--- a/lldb/include/lldb/ValueObject/ValueObject.h
+++ b/lldb/include/lldb/ValueObject/ValueObject.h
@@ -1011,6 +1011,35 @@ class ValueObject {
ChildrenMap m_children;
size_t m_children_count = 0;
};
+
+ using ValueObjectManagerSP = std::shared_ptr<ValueObjectManager>;
+
+ /// The following two functions are helpers for Create methods
+ /// for ValueObject subclasses that need to optionally receive
+ /// a parent or external manager.
+ /// This returns a ValueObjectManagerSP that is either the SP of the
+ /// parent - if it is non-null, or a new manager if null.
+ static ValueObjectManagerSP ReuseManagerIfParent(ValueObject *parent) {
+ std::shared_ptr<ValueObjectManager> manager_sp;
+ if (parent)
+ manager_sp = parent->GetManager()->shared_from_this();
+ else
+ manager_sp = ValueObjectManager::Create();
+ return manager_sp;
+ }
+
+ /// If manager is null, makes a new ValueObjectManager and sets
+ /// manager to the new ValueObjectManager. It also returns the
+ /// shared pointer which is necessary to keep the new manager alive.
+ static ValueObjectManagerSP CreateManagerIfEmpty(ValueObjectManager *&manager) {
+ std::shared_ptr<ValueObjectManager> manager_sp;
+ if (!manager) {
+ manager_sp = ValueObjectManager::Create();
+ manager = manager_sp.get();
+ }
+ return manager_sp;
+ }
+
// Classes that inherit from ValueObject can see and modify these
@@ -1183,6 +1212,8 @@ class ValueObject {
protected:
virtual void DoUpdateChildrenAddressType(ValueObject &valobj) {};
+
+
private:
void UpdateChildrenAddressType() {
diff --git a/lldb/include/lldb/ValueObject/ValueObjectConstResult.h b/lldb/include/lldb/ValueObject/ValueObjectConstResult.h
index d313e9f09de5a..0ada4e13acb45 100644
--- a/lldb/include/lldb/ValueObject/ValueObjectConstResult.h
+++ b/lldb/include/lldb/ValueObject/ValueObjectConstResult.h
@@ -174,16 +174,6 @@ class ValueObjectConstResult : public ValueObject {
ValueObjectConstResult(ExecutionContextScope *exe_scope,
ValueObjectManager &manager, Status &&error);
- static std::shared_ptr<ValueObjectManager>
- CreateManagerIfEmpty(ValueObjectManager *&manager) {
- std::shared_ptr<ValueObjectManager> manager_sp;
- if (!manager) {
- manager_sp = ValueObjectManager::Create();
- manager = manager_sp.get();
- }
- return manager_sp;
- }
-
ValueObject *CreateChildAtIndex(size_t idx) override {
return m_impl.CreateChildAtIndex(idx);
}
diff --git a/lldb/include/lldb/ValueObject/ValueObjectMemory.h b/lldb/include/lldb/ValueObject/ValueObjectMemory.h
index c1bd28434e324..71d100772a57d 100644
--- a/lldb/include/lldb/ValueObject/ValueObjectMemory.h
+++ b/lldb/include/lldb/ValueObject/ValueObjectMemory.h
@@ -34,12 +34,14 @@ class ValueObjectMemory : public ValueObject {
static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope,
llvm::StringRef name,
const Address &address,
- lldb::TypeSP &type_sp);
+ lldb::TypeSP &type_sp,
+ ValueObject *parent = nullptr);
static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope,
llvm::StringRef name,
const Address &address,
- const CompilerType &ast_type);
+ const CompilerType &ast_type,
+ ValueObject *parent = nullptr);
llvm::Expected<uint64_t> GetByteSize() override;
diff --git a/lldb/source/ValueObject/ValueObjectConstResult.cpp b/lldb/source/ValueObject/ValueObjectConstResult.cpp
index f5a8cda3d5121..b1c774ba0adde 100644
--- a/lldb/source/ValueObject/ValueObjectConstResult.cpp
+++ b/lldb/source/ValueObject/ValueObjectConstResult.cpp
@@ -31,7 +31,7 @@ ValueObjectSP ValueObjectConstResult::Create(ExecutionContextScope *exe_scope,
uint32_t addr_byte_size,
lldb::addr_t address,
ValueObjectManager *manager) {
- std::shared_ptr<ValueObjectManager> manager_sp =
+ ValueObjectManagerSP manager_sp =
CreateManagerIfEmpty(manager);
return (new ValueObjectConstResult(exe_scope, *manager, byte_order,
diff --git a/lldb/source/ValueObject/ValueObjectMemory.cpp b/lldb/source/ValueObject/ValueObjectMemory.cpp
index 3d8d80c6ec480..7d7a4eec9c18c 100644
--- a/lldb/source/ValueObject/ValueObjectMemory.cpp
+++ b/lldb/source/ValueObject/ValueObjectMemory.cpp
@@ -32,8 +32,11 @@ using namespace lldb_private;
ValueObjectSP ValueObjectMemory::Create(ExecutionContextScope *exe_scope,
llvm::StringRef name,
const Address &address,
- lldb::TypeSP &type_sp) {
- auto manager_sp = ValueObjectManager::Create();
+ lldb::TypeSP &type_sp,
+ ValueObject *parent) {
+
+ std::shared_ptr<ValueObjectManager> manager_sp =
+ ValueObject::ReuseManagerIfParent(parent);
return (new ValueObjectMemory(exe_scope, *manager_sp, name, address, type_sp))
->GetSP();
}
@@ -41,8 +44,10 @@ ValueObjectSP ValueObjectMemory::Create(ExecutionContextScope *exe_scope,
ValueObjectSP ValueObjectMemory::Create(ExecutionContextScope *exe_scope,
llvm::StringRef name,
const Address &address,
- const CompilerType &ast_type) {
- auto manager_sp = ValueObjectManager::Create();
+ const CompilerType &ast_type,
+ ValueObject *parent) {
+ std::shared_ptr<ValueObjectManager> manager_sp =
+ ValueObject::ReuseManagerIfParent(parent);
return (new ValueObjectMemory(exe_scope, *manager_sp, name, address,
ast_type))
->GetSP();
More information about the lldb-commits
mailing list