Skip to content

Commit fd997d8

Browse files
authored
[lldb][test] Combine libstdc++ and libc++ tuple tests into generic test (#147139)
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
1 parent 2e57761 commit fd997d8

File tree

8 files changed

+83
-109
lines changed

8 files changed

+83
-109
lines changed

lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1504,6 +1504,10 @@ static void LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
15041504
"^std::((__debug::)?|(__cxx11::)?)list<.+>(( )?&)?$",
15051505
stl_summary_flags, true);
15061506

1507+
AddCXXSummary(cpp_category_sp, ContainerSizeSummaryProvider,
1508+
"libstdc++ std::tuple summary provider",
1509+
"^std::tuple<.*>(( )?&)?$", stl_summary_flags, true);
1510+
15071511
cpp_category_sp->AddTypeSummary(
15081512
"^std::((__debug::)?|(__cxx11::)?)forward_list<.+>(( )?&)?$",
15091513
eFormatterMatchRegex,
@@ -1546,7 +1550,7 @@ static void LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
15461550
AddCXXSynthetic(
15471551
cpp_category_sp,
15481552
lldb_private::formatters::LibStdcppTupleSyntheticFrontEndCreator,
1549-
"std::tuple synthetic children", "^std::tuple<.+>(( )?&)?$",
1553+
"std::tuple synthetic children", "^std::tuple<.*>(( )?&)?$",
15501554
stl_synth_flags, true);
15511555

15521556
static constexpr const char *const libstdcpp_std_coroutine_handle_regex =
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
CXX_SOURCES := main.cpp
22

3-
USE_LIBCPP := 1
43
include Makefile.rules
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
"""
2+
Test lldb data formatter subsystem.
3+
"""
4+
5+
import lldb
6+
from lldbsuite.test.decorators import *
7+
from lldbsuite.test.lldbtest import *
8+
from lldbsuite.test import lldbutil
9+
10+
11+
class TestDataFormatterStdTuple(TestBase):
12+
def setUp(self):
13+
TestBase.setUp(self)
14+
self.line = line_number("main.cpp", "// break here")
15+
self.namespace = "std"
16+
17+
def do_test(self):
18+
"""Test that std::tuple is displayed correctly"""
19+
lldbutil.run_to_source_breakpoint(
20+
self, "// break here", lldb.SBFileSpec("main.cpp", False)
21+
)
22+
23+
tuple_name = self.namespace + "::tuple"
24+
self.expect("frame variable empty", substrs=[tuple_name, "size=0", "{}"])
25+
26+
self.expect(
27+
"frame variable one_elt",
28+
substrs=[tuple_name, "size=1", "{", "[0] = 47", "}"],
29+
)
30+
31+
self.expect(
32+
"frame variable three_elts",
33+
substrs=[
34+
tuple_name,
35+
"size=3",
36+
"{",
37+
"[0] = 1",
38+
"[1] = 47",
39+
'[2] = "foo"',
40+
"}",
41+
],
42+
)
43+
44+
frame = self.frame()
45+
self.assertTrue(frame.IsValid())
46+
47+
self.assertEqual(
48+
47, frame.GetValueForVariablePath("one_elt[0]").GetValueAsUnsigned()
49+
)
50+
self.assertFalse(frame.GetValueForVariablePath("one_elt[1]").IsValid())
51+
52+
self.assertEqual(
53+
'"foobar"', frame.GetValueForVariablePath("string_elt[0]").GetSummary()
54+
)
55+
self.assertFalse(frame.GetValueForVariablePath("string_elt[1]").IsValid())
56+
57+
self.assertEqual(
58+
1, frame.GetValueForVariablePath("three_elts[0]").GetValueAsUnsigned()
59+
)
60+
self.assertEqual(
61+
47, frame.GetValueForVariablePath("three_elts[1]").GetValueAsUnsigned()
62+
)
63+
self.assertEqual(
64+
'"foo"', frame.GetValueForVariablePath("three_elts[2]").GetSummary()
65+
)
66+
self.assertFalse(frame.GetValueForVariablePath("three_elts[3]").IsValid())
67+
68+
@add_test_categories(["libc++"])
69+
def test_libcxx(self):
70+
self.build(dictionary={"USE_LIBCPP": 1})
71+
self.do_test()
72+
73+
@add_test_categories(["libstdcxx"])
74+
def test_libstdcxx(self):
75+
self.build(dictionary={"USE_LIBSTDCPP": 1})
76+
self.do_test()
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
#include <tuple>
21
#include <string>
2+
#include <tuple>
33

44
int main() {
55
std::tuple<> empty;
66
std::tuple<int> one_elt{47};
7+
std::tuple<std::string> string_elt{"foobar"};
78
std::tuple<int, long, std::string> three_elts{1, 47l, "foo"};
89
return 0; // break here
910
}

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/tuple/TestDataFormatterLibcxxTuple.py

Lines changed: 0 additions & 45 deletions
This file was deleted.

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/tuple/Makefile

Lines changed: 0 additions & 5 deletions
This file was deleted.

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/tuple/TestDataFormatterStdTuple.py

Lines changed: 0 additions & 47 deletions
This file was deleted.

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/tuple/main.cpp

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)