aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp
diff options
context:
space:
mode:
authornerix <nerixdev@outlook.de>2025-07-16 11:07:45 +0200
committerGitHub <noreply@github.com>2025-07-16 10:07:45 +0100
commitf98cf07b7dc7af7716e1da9a1257b8c6416f9a46 (patch)
treee0ae65e2ef8d543dfb3f9c8bf5adc0dbe302d2c3 /lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp
parent5ae49393957c6b4d47ace7aaf5fc1e0388d3a695 (diff)
downloadllvm-f98cf07b7dc7af7716e1da9a1257b8c6416f9a46.zip
llvm-f98cf07b7dc7af7716e1da9a1257b8c6416f9a46.tar.gz
llvm-f98cf07b7dc7af7716e1da9a1257b8c6416f9a46.tar.bz2
[LLDB] Convert libstdc++ std::variant summary to C++ (#148929)
This PR converts the `std::variant` summary from Python to C++. Split from #148554. MSVC's STL and libstdc++ use the same type name for `std::variant`, thus they need one "dispatcher" function that checks the type and calls the appropriate summary. For summaries, both need to be implemented in C++. This is mostly a 1:1 translation. The main difference is that in C++, the summary returns `false` if it can't inspect the object properly (e.g. a member could not be found). In Python, this wasn't possible.
Diffstat (limited to 'lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp')
-rw-r--r--lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp
index c80a52d..595e835 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp
@@ -366,3 +366,49 @@ bool lldb_private::formatters::LibStdcppSmartPointerSummaryProvider(
return true;
}
+
+static uint64_t LibStdcppVariantNposValue(size_t index_byte_size) {
+ switch (index_byte_size) {
+ case 1:
+ return 0xff;
+ case 2:
+ return 0xffff;
+ default:
+ return 0xffff'ffff;
+ }
+}
+
+bool formatters::LibStdcppVariantSummaryProvider(
+ ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
+ ValueObjectSP valobj_sp = valobj.GetNonSyntheticValue();
+ if (!valobj_sp)
+ return false;
+
+ ValueObjectSP index_obj = valobj_sp->GetChildMemberWithName("_M_index");
+ ValueObjectSP data_obj = valobj_sp->GetChildMemberWithName("_M_u");
+ if (!index_obj || !data_obj)
+ return false;
+
+ auto index_bytes = index_obj->GetByteSize();
+ if (!index_bytes)
+ return false;
+ auto npos_value = LibStdcppVariantNposValue(*index_bytes);
+ auto index = index_obj->GetValueAsUnsigned(0);
+ if (index == npos_value) {
+ stream.Printf(" No Value");
+ return true;
+ }
+
+ auto variant_type =
+ valobj_sp->GetCompilerType().GetCanonicalType().GetNonReferenceType();
+ if (!variant_type)
+ return false;
+ if (index >= variant_type.GetNumTemplateArguments(true)) {
+ stream.Printf(" <Invalid>");
+ return true;
+ }
+
+ auto active_type = variant_type.GetTypeTemplateArgument(index, true);
+ stream << " Active Type = " << active_type.GetDisplayTypeName() << " ";
+ return true;
+}