[Lldb-commits] [lldb] bc97fbe - Add the ability to pass a parent to ValueObjectMemory::Create. (#195155)
via lldb-commits
lldb-commits at lists.llvm.org
Thu Apr 30 14:56:43 PDT 2026
Author: jimingham
Date: 2026-04-30T14:56:39-07:00
New Revision: bc97fbe489dc5b2857c094abb346768113a4355a
URL: https://github.com/llvm/llvm-project/commit/bc97fbe489dc5b2857c094abb346768113a4355a
DIFF: https://github.com/llvm/llvm-project/commit/bc97fbe489dc5b2857c094abb346768113a4355a.diff
LOG: Add the ability to pass a parent to ValueObjectMemory::Create. (#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.
Added:
Modified:
lldb/include/lldb/ValueObject/ValueObject.h
lldb/include/lldb/ValueObject/ValueObjectConstResult.h
lldb/include/lldb/ValueObject/ValueObjectMemory.h
lldb/source/ValueObject/ValueObjectConstResult.cpp
lldb/source/ValueObject/ValueObjectMemory.cpp
Removed:
################################################################################
diff --git a/lldb/include/lldb/ValueObject/ValueObject.h b/lldb/include/lldb/ValueObject/ValueObject.h
index bf4c47a4b9fe1..029563fa77850 100644
--- a/lldb/include/lldb/ValueObject/ValueObject.h
+++ b/lldb/include/lldb/ValueObject/ValueObject.h
@@ -1012,6 +1012,35 @@ class ValueObject {
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) {
+ ValueObjectManagerSP 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) {
+ ValueObjectManagerSP 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
/// The parent value object, or nullptr if this has no parent.
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..e6a09b748c74c 100644
--- a/lldb/source/ValueObject/ValueObjectConstResult.cpp
+++ b/lldb/source/ValueObject/ValueObjectConstResult.cpp
@@ -31,8 +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 =
- CreateManagerIfEmpty(manager);
+ ValueObjectManagerSP manager_sp = CreateManagerIfEmpty(manager);
return (new ValueObjectConstResult(exe_scope, *manager, byte_order,
addr_byte_size, address))
diff --git a/lldb/source/ValueObject/ValueObjectMemory.cpp b/lldb/source/ValueObject/ValueObjectMemory.cpp
index 3d8d80c6ec480..c85b382156088 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