Skip to content

Conversation

@Michael137
Copy link
Member

@Michael137 Michael137 commented Jul 5, 2025

This combines the libc++ and libstdc++ test cases. The main difference was that the libstdcpp tests had some tuple indexing tests that libc++ didn't have.

The libstdc++ formatter didn't support size summaries for std::tuple. So I added a ContainerSizeSummaryProvider for it (like we do for libc++). Additionally, the synthetic frontend would only apply to non-empty tuples, so I adjusted the regex to match empty ones too. We do this for libc++ already.

Split out from #146740

@Michael137 Michael137 requested a review from JDevlieghere as a code owner July 5, 2025 10:36
@llvmbot llvmbot added the lldb label Jul 5, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 5, 2025

@llvm/pr-subscribers-lldb

Author: Michael Buch (Michael137)

Changes

This combines the libc++ and libstdc++ test cases. The main difference was that the libstdcpp tests had some tuple indexing tests that libc++ didn't have.

Split out from #146740


Full diff: https://github.com/llvm/llvm-project/pull/147139.diff

7 Files Affected:

  • (renamed) lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/tuple/Makefile (-1)
  • (added) lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/tuple/TestDataFormatterStdTuple.py (+73)
  • (renamed) lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/tuple/main.cpp (+2-1)
  • (removed) lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/tuple/TestDataFormatterLibcxxTuple.py (-45)
  • (removed) lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/tuple/Makefile (-5)
  • (removed) lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/tuple/TestDataFormatterStdTuple.py (-47)
  • (removed) lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/tuple/main.cpp (-9)
diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/tuple/Makefile b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/tuple/Makefile
similarity index 75%
rename from lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/tuple/Makefile
rename to lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/tuple/Makefile
index 680e1abfbef58..99998b20bcb05 100644
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/tuple/Makefile
+++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/tuple/Makefile
@@ -1,4 +1,3 @@
 CXX_SOURCES := main.cpp
 
-USE_LIBCPP := 1
 include Makefile.rules
diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/tuple/TestDataFormatterStdTuple.py b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/tuple/TestDataFormatterStdTuple.py
new file mode 100644
index 0000000000000..9e019d328b6b3
--- /dev/null
+++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/tuple/TestDataFormatterStdTuple.py
@@ -0,0 +1,73 @@
+"""
+Test lldb data formatter subsystem.
+"""
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class TestDataFormatterStdTuple(TestBase):
+    def setUp(self):
+        TestBase.setUp(self)
+        self.line = line_number("main.cpp", "// break here")
+        self.namespace = "std"
+
+    def do_test(self):
+        """Test that std::tuple is displayed correctly"""
+        lldbutil.run_to_source_breakpoint(
+            self, "// break here", lldb.SBFileSpec("main.cpp", False)
+        )
+
+        tuple_name = self.namespace + "::tuple"
+        self.expect("frame variable empty", substrs=[tuple_name, "size=0", "{}"])
+
+        self.expect(
+            "frame variable one_elt",
+            substrs=[tuple_name, "size=1", "{", "[0] = 47", "}"],
+        )
+
+        self.expect(
+            "frame variable three_elts",
+            substrs=[
+                tuple_name,
+                "size=3",
+                "{",
+                "[0] = 1",
+                "[1] = 47",
+                '[2] = "foo"',
+                "}",
+            ],
+        )
+
+        self.assertEqual(
+            1, frame.GetValueForVariablePath("one_elt[0]").GetValueAsUnsigned()
+        )
+        self.assertFalse(frame.GetValueForVariablePath("one_elt[1]").IsValid())
+
+        self.assertEqual(
+            '"foobar"', frame.GetValueForVariablePath("string_elt[0]").GetSummary()
+        )
+        self.assertFalse(frame.GetValueForVariablePath("string_elt[1]").IsValid())
+
+        self.assertEqual(
+            1, frame.GetValueForVariablePath("three_elts[0]").GetValueAsUnsigned()
+        )
+        self.assertEqual(
+            '"baz"', frame.GetValueForVariablePath("three_elts[1]").GetSummary()
+        )
+        self.assertEqual(
+            2, frame.GetValueForVariablePath("three_elts[2]").GetValueAsUnsigned()
+        )
+        self.assertFalse(frame.GetValueForVariablePath("three_elts[3]").IsValid())
+
+    @add_test_categories(["libc++"])
+    def test_libcxx(self):
+        self.build(dictionary={"USE_LIBCPP": 1})
+        self.do_test()
+
+    @add_test_categories(["libstdcxx"])
+    def test_libstdcxx(self):
+        self.build(dictionary={"USE_LIBSTDCPP": 1})
+        self.do_test()
diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/tuple/main.cpp b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/tuple/main.cpp
similarity index 80%
rename from lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/tuple/main.cpp
rename to lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/tuple/main.cpp
index beb44cd960005..d49dbe8a5f1af 100644
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/tuple/main.cpp
+++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/tuple/main.cpp
@@ -1,9 +1,10 @@
-#include <tuple>
 #include <string>
+#include <tuple>
 
 int main() {
   std::tuple<> empty;
   std::tuple<int> one_elt{47};
+  std::tuple<std::string> string_elt{"foobar"};
   std::tuple<int, long, std::string> three_elts{1, 47l, "foo"};
   return 0; // break here
 }
diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/tuple/TestDataFormatterLibcxxTuple.py b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/tuple/TestDataFormatterLibcxxTuple.py
deleted file mode 100644
index 5b6dfaf5e5d9d..0000000000000
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/tuple/TestDataFormatterLibcxxTuple.py
+++ /dev/null
@@ -1,45 +0,0 @@
-"""
-Test lldb data formatter subsystem.
-"""
-
-
-import lldb
-from lldbsuite.test.decorators import *
-from lldbsuite.test.lldbtest import *
-from lldbsuite.test import lldbutil
-
-
-class TestDataFormatterLibcxxTuple(TestBase):
-    def setUp(self):
-        TestBase.setUp(self)
-        self.line = line_number("main.cpp", "// break here")
-        self.namespace = "std"
-
-    @add_test_categories(["libc++"])
-    def test(self):
-        """Test that std::tuple is displayed correctly"""
-        self.build()
-        lldbutil.run_to_source_breakpoint(
-            self, "// break here", lldb.SBFileSpec("main.cpp", False)
-        )
-
-        tuple_name = self.namespace + "::tuple"
-        self.expect("frame variable empty", substrs=[tuple_name, "size=0", "{}"])
-
-        self.expect(
-            "frame variable one_elt",
-            substrs=[tuple_name, "size=1", "{", "[0] = 47", "}"],
-        )
-
-        self.expect(
-            "frame variable three_elts",
-            substrs=[
-                tuple_name,
-                "size=3",
-                "{",
-                "[0] = 1",
-                "[1] = 47",
-                '[2] = "foo"',
-                "}",
-            ],
-        )
diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/tuple/Makefile b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/tuple/Makefile
deleted file mode 100644
index bf8e6b8703f36..0000000000000
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/tuple/Makefile
+++ /dev/null
@@ -1,5 +0,0 @@
-CXX_SOURCES := main.cpp
-
-USE_LIBSTDCPP := 1
-
-include Makefile.rules
diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/tuple/TestDataFormatterStdTuple.py b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/tuple/TestDataFormatterStdTuple.py
deleted file mode 100644
index 1433b5bc1acb8..0000000000000
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/tuple/TestDataFormatterStdTuple.py
+++ /dev/null
@@ -1,47 +0,0 @@
-"""
-Test lldb data formatter subsystem.
-"""
-
-
-import lldb
-from lldbsuite.test.decorators import *
-from lldbsuite.test.lldbtest import *
-from lldbsuite.test import lldbutil
-
-
-class StdTupleDataFormatterTestCase(TestBase):
-    @add_test_categories(["libstdcxx"])
-    @expectedFailureAll(bugnumber="llvm.org/pr50861", compiler="gcc")
-    def test_with_run_command(self):
-        self.build()
-        self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
-
-        lldbutil.run_break_set_by_source_regexp(self, "Set break point at this line.")
-        self.runCmd("run", RUN_SUCCEEDED)
-
-        # The stop reason of the thread should be breakpoint.
-        self.expect(
-            "thread list",
-            STOPPED_DUE_TO_BREAKPOINT,
-            substrs=["stopped", "stop reason = breakpoint"],
-        )
-
-        frame = self.frame()
-        self.assertTrue(frame.IsValid())
-
-        self.expect("frame variable ti", substrs=["[0] = 1"])
-        self.expect("frame variable ts", substrs=['[0] = "foobar"'])
-        self.expect("frame variable tt", substrs=["[0] = 1", '[1] = "baz"', "[2] = 2"])
-
-        self.assertEqual(1, frame.GetValueForVariablePath("ti[0]").GetValueAsUnsigned())
-        self.assertFalse(frame.GetValueForVariablePath("ti[1]").IsValid())
-
-        self.assertEqual(
-            '"foobar"', frame.GetValueForVariablePath("ts[0]").GetSummary()
-        )
-        self.assertFalse(frame.GetValueForVariablePath("ts[1]").IsValid())
-
-        self.assertEqual(1, frame.GetValueForVariablePath("tt[0]").GetValueAsUnsigned())
-        self.assertEqual('"baz"', frame.GetValueForVariablePath("tt[1]").GetSummary())
-        self.assertEqual(2, frame.GetValueForVariablePath("tt[2]").GetValueAsUnsigned())
-        self.assertFalse(frame.GetValueForVariablePath("tt[3]").IsValid())
diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/tuple/main.cpp b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/tuple/main.cpp
deleted file mode 100644
index 7247742ee6bb5..0000000000000
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/tuple/main.cpp
+++ /dev/null
@@ -1,9 +0,0 @@
-#include <memory>
-#include <string>
-
-int main() {
-  std::tuple<int> ti{1};
-  std::tuple<std::string> ts{"foobar"};
-  std::tuple<int, std::string, int> tt{1, "baz", 2};
-  return 0; // Set break point at this line.
-}

@Michael137
Copy link
Member Author

The libstdc++ formatter doesn't have a summary provider for tuples. So one of the test-cases will fail. Will address that after #147140

@Michael137 Michael137 force-pushed the lldb/consolidate-stl-tests-tuple branch from dce966d to 0fd1f00 Compare July 7, 2025 08:09
This combines the libc++ and libstdc++ test cases. The main difference
was that the libstdcpp tests had some tuple indexing tests that libc++ didn't have.

Split out from llvm#146740
@Michael137 Michael137 force-pushed the lldb/consolidate-stl-tests-tuple branch from 2def4cf to d171258 Compare July 7, 2025 17:24
@Michael137 Michael137 merged commit fd997d8 into llvm:main Jul 8, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants