[Lldb-commits] [lldb] [lldb] Make variant formatter work with libstdc++-14 (PR #97568)

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Wed Jul 3 05:26:18 PDT 2024


https://github.com/labath created https://github.com/llvm/llvm-project/pull/97568

In this version the internal data member has grown an additional template parameter (bool), which was throwing the summary provider off.

This patch uses the type of the entire variant object. This is part of the API/ABI, so it should be more stable, but it means we have to explicitly strip typedefs and references to get to the interesting bits, which is why I've extended the test case with examples of those.

>From 53b9fda6f7bf0ec4df32869c9d4ba2203aa1870a Mon Sep 17 00:00:00 2001
From: Pavel Labath <pavel at labath.sk>
Date: Wed, 3 Jul 2024 12:20:12 +0000
Subject: [PATCH] [lldb] Make variant formatter work with libstdc++-14

In this version the internal data member has grown an additional
template parameter (bool), which was throwing the summary provider off.

This patch uses the type of the entire variant object. This is part of
the API/ABI, so it should be more stable, but it means we have to
explicitly strip typedefs and references to get to the interesting bits,
which is why I've extended the test case with examples of those.
---
 lldb/examples/synthetic/gnu_libstdcpp.py      |  7 +++++--
 .../TestDataFormatterLibStdcxxVariant.py      | 20 ++++++++++---------
 .../libstdcpp/variant/main.cpp                |  5 +++++
 3 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/lldb/examples/synthetic/gnu_libstdcpp.py b/lldb/examples/synthetic/gnu_libstdcpp.py
index f778065aaca37..59970574a3604 100644
--- a/lldb/examples/synthetic/gnu_libstdcpp.py
+++ b/lldb/examples/synthetic/gnu_libstdcpp.py
@@ -914,12 +914,15 @@ def get_variant_npos_value(index_byte_size):
     if index == npos_value:
         return " No Value"
 
+    # Strip references and typedefs.
+    variant_type = raw_obj.GetType().GetCanonicalType().GetDereferencedType();
+    template_arg_count = variant_type.GetNumberOfTemplateArguments()
+
     # Invalid index can happen when the variant is not initialized yet.
-    template_arg_count = data_obj.GetType().GetNumberOfTemplateArguments()
     if index >= template_arg_count:
         return " <Invalid>"
 
-    active_type = data_obj.GetType().GetTemplateArgumentType(index)
+    active_type = variant_type.GetTemplateArgumentType(index)
     return f" Active Type = {active_type.GetDisplayTypeName()} "
 
 
diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/variant/TestDataFormatterLibStdcxxVariant.py b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/variant/TestDataFormatterLibStdcxxVariant.py
index ba1641888b6f3..05f31087a566e 100644
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/variant/TestDataFormatterLibStdcxxVariant.py
+++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/variant/TestDataFormatterLibStdcxxVariant.py
@@ -21,15 +21,17 @@ def test_with_run_command(self):
 
         lldbutil.continue_to_breakpoint(self.process, bkpt)
 
-        self.expect(
-            "frame variable v1",
-            substrs=["v1 =  Active Type = int  {", "Value = 12", "}"],
-        )
-
-        self.expect(
-            "frame variable v1_ref",
-            substrs=["v1_ref =  Active Type = int : {", "Value = 12", "}"],
-        )
+        for name in ["v1", "v1_typedef"]:
+          self.expect(
+              "frame variable " + name,
+              substrs=[name + " =  Active Type = int  {", "Value = 12", "}"],
+          )
+
+        for name in ["v1_ref", "v1_typedef_ref"]:
+          self.expect(
+              "frame variable " + name,
+              substrs=[name + " =  Active Type = int : {", "Value = 12", "}"],
+          )
 
         self.expect(
             "frame variable v_v1",
diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/variant/main.cpp b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/variant/main.cpp
index 545318f9358b6..36e0f74f831f8 100644
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/variant/main.cpp
+++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/variant/main.cpp
@@ -14,6 +14,10 @@ int main() {
 
   std::variant<int, double, char> v1;
   std::variant<int, double, char> &v1_ref = v1;
+  using V1_typedef = std::variant<int, double, char>;
+  V1_typedef v1_typedef;
+  V1_typedef &v1_typedef_ref = v1_typedef;
+
   std::variant<int, double, char> v2;
   std::variant<int, double, char> v3;
   std::variant<std::variant<int, double, char>> v_v1;
@@ -43,6 +47,7 @@ int main() {
       v_many_types_no_value;
 
   v1 = 12; // v contains int
+  v1_typedef = v1;
   v_v1 = v1;
   int i = std::get<int>(v1);
   printf("%d\n", i); // break here



More information about the lldb-commits mailing list