diff options
author | Michael Buch <michaelbuch12@gmail.com> | 2025-07-07 09:13:52 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-07-07 09:13:52 +0100 |
commit | 6fec6a98c01523a5478ce2aa9617e884dc772f6f (patch) | |
tree | 9946b697401e6e81d4e6e2251ef0778810147b0c /lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp | |
parent | d06956e24afaed103dfbcc67e81257692ae0a8b2 (diff) | |
download | llvm-6fec6a98c01523a5478ce2aa9617e884dc772f6f.zip llvm-6fec6a98c01523a5478ce2aa9617e884dc772f6f.tar.gz llvm-6fec6a98c01523a5478ce2aa9617e884dc772f6f.tar.bz2 |
[lldb][Formatters] Make libc++ and libstdc++ std::shared_ptr formatters consistent with each other (#147165)
This patch adjusts the libcxx and libstdcxx std::shared_ptr formatters
to look the same.
Changes to libcxx:
* Now creates a synthetic child called `pointer` (like we already do for
`std::unique_ptr`)
Changes to libstdcxx:
* When asked to dereference the pointer, cast the type of the result
ValueObject to the element type (which we get from the template argument
to std::shared_ptr).
Before:
```
(std::__shared_ptr<int, __gnu_cxx::_S_atomic>::element_type) *foo = 123
```
After:
```
(int) *foo = 123
```
Tested in https://github.com/llvm/llvm-project/pull/147141
Diffstat (limited to 'lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp')
-rw-r--r-- | lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp index 28b7c01..7668a87 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp @@ -77,8 +77,7 @@ private: // objects are only destroyed when every shared pointer to any of them // is destroyed, so we must not store a shared pointer to any ValueObject // derived from our backend ValueObject (since we're in the same cluster). - ValueObject* m_ptr_obj = nullptr; // Underlying pointer (held, not owned) - ValueObject* m_obj_obj = nullptr; // Underlying object (held, not owned) + ValueObject *m_ptr_obj = nullptr; // Underlying pointer (held, not owned) }; } // end of anonymous namespace @@ -266,15 +265,20 @@ LibStdcppSharedPtrSyntheticFrontEnd::GetChildAtIndex(uint32_t idx) { if (idx == 0) return m_ptr_obj->GetSP(); + if (idx == 1) { - if (m_ptr_obj && !m_obj_obj) { - Status error; - ValueObjectSP obj_obj = m_ptr_obj->Dereference(error); - if (error.Success()) - m_obj_obj = obj_obj->Clone(ConstString("object")).get(); - } - if (m_obj_obj) - return m_obj_obj->GetSP(); + ValueObjectSP valobj_sp = m_backend.GetSP(); + if (!valobj_sp) + return nullptr; + + Status status; + auto value_type_sp = valobj_sp->GetCompilerType() + .GetTypeTemplateArgument(0) + .GetPointerType(); + ValueObjectSP cast_ptr_sp = m_ptr_obj->Cast(value_type_sp); + ValueObjectSP value_sp = cast_ptr_sp->Dereference(status); + if (status.Success()) + return value_sp; } return lldb::ValueObjectSP(); } @@ -293,7 +297,6 @@ lldb::ChildCacheState LibStdcppSharedPtrSyntheticFrontEnd::Update() { return lldb::ChildCacheState::eRefetch; m_ptr_obj = ptr_obj_sp->Clone(ConstString("pointer")).get(); - m_obj_obj = nullptr; return lldb::ChildCacheState::eRefetch; } @@ -302,8 +305,10 @@ llvm::Expected<size_t> LibStdcppSharedPtrSyntheticFrontEnd::GetIndexOfChildWithName(ConstString name) { if (name == "pointer") return 0; + if (name == "object" || name == "$$dereference$$") return 1; + return llvm::createStringError("Type has no child named '%s'", name.AsCString()); } |