summaryrefslogtreecommitdiff
path: root/lldb/source/DataFormatters/FormattersHelpers.cpp
diff options
context:
space:
mode:
authorMichael Buch <michaelbuch12@gmail.com>2025-07-04 09:18:24 +0100
committerGitHub <noreply@github.com>2025-07-04 09:18:24 +0100
commita89e232058a29260eb9bfe77b862715ce875f962 (patch)
treeb8bbb25cc538ab1e3f68eac81dfcc37fe53a0bd6 /lldb/source/DataFormatters/FormattersHelpers.cpp
parent25f05c02afb99c3af483bfb8bc3abac54f4cabc3 (diff)
[lldb][DataFormatter] Format libstdc++ unique_ptr like we do libc++ (#146909)
The only difference is that with libc++ the summary string contains the derefernced pointer value. With libstdc++ we currently display the pointer itself, which seems redundant. E.g., ``` (std::unique_ptr<int>) iup = 0x55555556d2b0 { pointer = 0x000055555556d2b0 } (std::unique_ptr<std::basic_string<char> >) sup = 0x55555556d2d0 { pointer = "foobar" } ``` This patch moves the logic into a common helper that's shared between the libc++ and libstdc++ formatters. After this patch we can combine the libc++ and libstdc++ API tests (see https://github.com/llvm/llvm-project/pull/146740).
Diffstat (limited to 'lldb/source/DataFormatters/FormattersHelpers.cpp')
-rw-r--r--lldb/source/DataFormatters/FormattersHelpers.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/lldb/source/DataFormatters/FormattersHelpers.cpp b/lldb/source/DataFormatters/FormattersHelpers.cpp
index d7b058d91c4a..81c76b06fc47 100644
--- a/lldb/source/DataFormatters/FormattersHelpers.cpp
+++ b/lldb/source/DataFormatters/FormattersHelpers.cpp
@@ -126,3 +126,22 @@ lldb_private::formatters::GetArrayAddressOrPointerValue(ValueObject &valobj) {
return data_addr.address;
}
+
+void lldb_private::formatters::DumpCxxSmartPtrPointerSummary(
+ Stream &stream, ValueObject &ptr, const TypeSummaryOptions &options) {
+ if (ptr.GetValueAsUnsigned(0) == 0) {
+ stream.Printf("nullptr");
+ return;
+ }
+
+ Status error;
+ ValueObjectSP pointee_sp = ptr.Dereference(error);
+ if (!pointee_sp || !error.Success())
+ return;
+
+ if (!pointee_sp->DumpPrintableRepresentation(
+ stream, ValueObject::eValueObjectRepresentationStyleSummary,
+ lldb::eFormatInvalid,
+ ValueObject::PrintableRepresentationSpecialCases::eDisable, false))
+ stream.Printf("ptr = 0x%" PRIx64, ptr.GetValueAsUnsigned(0));
+}