diff options
author | Michael Buch <michaelbuch12@gmail.com> | 2025-07-07 12:08:24 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-07-07 12:08:24 +0100 |
commit | 40fb90efed7be2dc0e9ca37a5dc4ecc0e0ae8622 (patch) | |
tree | 053a79b941f1a4f7f9b43d090f9efc14294830d1 /lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp | |
parent | 87632451165a9dd54f799c4544cea971e15f7719 (diff) | |
download | llvm-40fb90efed7be2dc0e9ca37a5dc4ecc0e0ae8622.zip llvm-40fb90efed7be2dc0e9ca37a5dc4ecc0e0ae8622.tar.gz llvm-40fb90efed7be2dc0e9ca37a5dc4ecc0e0ae8622.tar.bz2 |
[lldb][Formatters] Add shared/weak count to libstdc++ std::shared_ptr summary (#147166)
Depends on https://github.com/llvm/llvm-project/pull/147165
This adds weak/strong counts to the std::shared_ptr summary of the
libstdcxx formatters. We already do this for libcxx. This will make it
easier to consolidate the tests into a generic one (see
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 | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp index 7668a87..8444227 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp @@ -10,6 +10,7 @@ #include "LibCxx.h" #include "Plugins/TypeSystem/Clang/TypeSystemClang.h" +#include "lldb/DataFormatters/FormattersHelpers.h" #include "lldb/DataFormatters/StringPrinter.h" #include "lldb/DataFormatters/VectorIterator.h" #include "lldb/Target/Target.h" @@ -330,29 +331,37 @@ bool lldb_private::formatters::LibStdcppSmartPointerSummaryProvider( if (!ptr_sp) return false; - ValueObjectSP usecount_sp( - valobj_sp->GetChildAtNamePath({"_M_refcount", "_M_pi", "_M_use_count"})); - if (!usecount_sp) + DumpCxxSmartPtrPointerSummary(stream, *ptr_sp, options); + + ValueObjectSP pi_sp = valobj_sp->GetChildAtNamePath({"_M_refcount", "_M_pi"}); + if (!pi_sp) return false; - if (ptr_sp->GetValueAsUnsigned(0) == 0 || - usecount_sp->GetValueAsUnsigned(0) == 0) { - stream.Printf("nullptr"); + bool success; + uint64_t pi_addr = pi_sp->GetValueAsUnsigned(0, &success); + // Empty control field. We're done. + if (!success || pi_addr == 0) return true; + + int64_t shared_count = 0; + if (auto count_sp = pi_sp->GetChildMemberWithName("_M_use_count")) { + bool success; + shared_count = count_sp->GetValueAsSigned(0, &success); + if (!success) + return false; + + stream.Printf(" strong=%" PRId64, shared_count); } - Status error; - ValueObjectSP pointee_sp = ptr_sp->Dereference(error); - if (pointee_sp && error.Success()) { - if (pointee_sp->DumpPrintableRepresentation( - stream, ValueObject::eValueObjectRepresentationStyleSummary, - lldb::eFormatInvalid, - ValueObject::PrintableRepresentationSpecialCases::eDisable, - false)) { - return true; - } + // _M_weak_count is the number of weak references + (_M_use_count != 0). + if (auto weak_count_sp = pi_sp->GetChildMemberWithName("_M_weak_count")) { + bool success; + int64_t count = weak_count_sp->GetValueAsUnsigned(0, &success); + if (!success) + return false; + + stream.Printf(" weak=%" PRId64, count - (shared_count != 0)); } - stream.Printf("ptr = 0x%" PRIx64, ptr_sp->GetValueAsUnsigned(0)); return true; } |