Add the ability to pass a parent to ValueObjectMemory::Create. (#195155)
Some checks failed
Release Asset Audit / Release Asset Audit (push) Has been cancelled
Release Asset Audit / Notify Audit Failed (push) Has been cancelled
Github Actions CodeQL / Github Actions CodeQL (push) Has been cancelled
Post-Commit Static Analyzer / post-commit-analyzer (push) Has been cancelled

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.
This commit is contained in:
jimingham
2026-04-30 14:56:39 -07:00
committed by GitHub
parent 8ae4978155
commit bc97fbe489
5 changed files with 43 additions and 18 deletions

View File

@@ -1012,6 +1012,35 @@ protected:
size_t m_children_count = 0; 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 // Classes that inherit from ValueObject can see and modify these
/// The parent value object, or nullptr if this has no parent. /// The parent value object, or nullptr if this has no parent.

View File

@@ -174,16 +174,6 @@ private:
ValueObjectConstResult(ExecutionContextScope *exe_scope, ValueObjectConstResult(ExecutionContextScope *exe_scope,
ValueObjectManager &manager, Status &&error); 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 { ValueObject *CreateChildAtIndex(size_t idx) override {
return m_impl.CreateChildAtIndex(idx); return m_impl.CreateChildAtIndex(idx);
} }

View File

@@ -34,12 +34,14 @@ public:
static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope, static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope,
llvm::StringRef name, llvm::StringRef name,
const Address &address, const Address &address,
lldb::TypeSP &type_sp); lldb::TypeSP &type_sp,
ValueObject *parent = nullptr);
static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope, static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope,
llvm::StringRef name, llvm::StringRef name,
const Address &address, const Address &address,
const CompilerType &ast_type); const CompilerType &ast_type,
ValueObject *parent = nullptr);
llvm::Expected<uint64_t> GetByteSize() override; llvm::Expected<uint64_t> GetByteSize() override;

View File

@@ -31,8 +31,7 @@ ValueObjectSP ValueObjectConstResult::Create(ExecutionContextScope *exe_scope,
uint32_t addr_byte_size, uint32_t addr_byte_size,
lldb::addr_t address, lldb::addr_t address,
ValueObjectManager *manager) { ValueObjectManager *manager) {
std::shared_ptr<ValueObjectManager> manager_sp = ValueObjectManagerSP manager_sp = CreateManagerIfEmpty(manager);
CreateManagerIfEmpty(manager);
return (new ValueObjectConstResult(exe_scope, *manager, byte_order, return (new ValueObjectConstResult(exe_scope, *manager, byte_order,
addr_byte_size, address)) addr_byte_size, address))

View File

@@ -32,8 +32,11 @@ using namespace lldb_private;
ValueObjectSP ValueObjectMemory::Create(ExecutionContextScope *exe_scope, ValueObjectSP ValueObjectMemory::Create(ExecutionContextScope *exe_scope,
llvm::StringRef name, llvm::StringRef name,
const Address &address, const Address &address,
lldb::TypeSP &type_sp) { lldb::TypeSP &type_sp,
auto manager_sp = ValueObjectManager::Create(); ValueObject *parent) {
std::shared_ptr<ValueObjectManager> manager_sp =
ValueObject::ReuseManagerIfParent(parent);
return (new ValueObjectMemory(exe_scope, *manager_sp, name, address, type_sp)) return (new ValueObjectMemory(exe_scope, *manager_sp, name, address, type_sp))
->GetSP(); ->GetSP();
} }
@@ -41,8 +44,10 @@ ValueObjectSP ValueObjectMemory::Create(ExecutionContextScope *exe_scope,
ValueObjectSP ValueObjectMemory::Create(ExecutionContextScope *exe_scope, ValueObjectSP ValueObjectMemory::Create(ExecutionContextScope *exe_scope,
llvm::StringRef name, llvm::StringRef name,
const Address &address, const Address &address,
const CompilerType &ast_type) { const CompilerType &ast_type,
auto manager_sp = ValueObjectManager::Create(); ValueObject *parent) {
std::shared_ptr<ValueObjectManager> manager_sp =
ValueObject::ReuseManagerIfParent(parent);
return (new ValueObjectMemory(exe_scope, *manager_sp, name, address, return (new ValueObjectMemory(exe_scope, *manager_sp, name, address,
ast_type)) ast_type))
->GetSP(); ->GetSP();