Skip to content

Commit afa00be

Browse files
committed
[lldb][Formatter] Consolidate libstdc++ and libc++ unique_ptr formatter tests into generic test
The libc++ test was a subset of the tests in libstdc++. This test moves the libc++ test into `generic` and somne additional test-cases from `libstdc++` (specifically the recursive unique_ptr case). It turns out the libstdc++ formatter supports dereferencing using the "object" or "obj" names. We could either drop those from the tests or support the same for libc++. I took the latter approach but don't have strong opinions on this. Split out from #146740
1 parent d74c9ef commit afa00be

File tree

9 files changed

+82
-199
lines changed

9 files changed

+82
-199
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ lldb_private::formatters::LibcxxUniquePtrSyntheticFrontEnd::
399399
return 0;
400400
if (name == "deleter")
401401
return 1;
402-
if (name == "$$dereference$$")
402+
if (name == "obj" || name == "object" || name == "$$dereference$$")
403403
return 2;
404404
return llvm::createStringError("Type has no child named '%s'",
405405
name.AsCString());
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
CXX_SOURCES := main.cpp
22

3-
USE_LIBCPP := 1
4-
53
# We need debug info tuning for lldb in order to emit the preferred name for
64
# std::string. See https://reviews.llvm.org/D145803.
75
CXXFLAGS_EXTRAS := -std=c++14 -glldb
Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
"""
2-
Test lldb data formatter for libc++ std::unique_ptr.
2+
Test lldb data formatter for std::unique_ptr.
33
"""
44

5-
65
import lldb
76
from lldbsuite.test.decorators import *
87
from lldbsuite.test.lldbtest import *
@@ -32,10 +31,8 @@ def make_expected_basic_string_ptr(self) -> str:
3231
"std::default_delete<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >"
3332
)
3433

35-
@add_test_categories(["libc++"])
36-
def test_unique_ptr_variables(self):
34+
def do_test(self):
3735
"""Test `frame variable` output for `std::unique_ptr` types."""
38-
self.build()
3936

4037
lldbutil.run_to_source_breakpoint(
4138
self, "// break here", lldb.SBFileSpec("main.cpp")
@@ -121,3 +118,67 @@ def test_unique_ptr_variables(self):
121118
self.expect_var_path("ptr_node->next->value", value="2")
122119
self.expect_var_path("(*ptr_node).value", value="1")
123120
self.expect_var_path("(*(*ptr_node).next).value", value="2")
121+
122+
@add_test_categories(["libstdcxx"])
123+
def test_libstdcxx(self):
124+
self.build(dictionary={"USE_LIBSTDCPP": 1})
125+
self.do_test()
126+
127+
@add_test_categories(["libc++"])
128+
def test_libcxx(self):
129+
self.build(dictionary={"USE_LIBCPP": 1})
130+
self.do_test()
131+
132+
def do_test_recursive_unique_ptr(self):
133+
# Tests that LLDB can handle when we have a loop in the unique_ptr
134+
# reference chain and that it correctly handles the different options
135+
# for the frame variable command in this case.
136+
self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
137+
138+
lldbutil.run_break_set_by_source_regexp(self, "Set break point at this line.")
139+
self.runCmd("run", RUN_SUCCEEDED)
140+
self.expect(
141+
"thread list",
142+
STOPPED_DUE_TO_BREAKPOINT,
143+
substrs=["stopped", "stop reason = breakpoint"],
144+
)
145+
146+
self.expect("frame variable f1->next", substrs=["next = NodeU @"])
147+
self.expect(
148+
"frame variable --ptr-depth=1 f1->next",
149+
substrs=["next = NodeU @", "value = 2"],
150+
)
151+
self.expect(
152+
"frame variable --ptr-depth=2 f1->next",
153+
substrs=["next = NodeU @", "value = 1", "value = 2"],
154+
)
155+
156+
frame = self.frame()
157+
self.assertTrue(frame.IsValid())
158+
self.assertEqual(
159+
2,
160+
frame.GetValueForVariablePath("f1->next.object.value").GetValueAsUnsigned(),
161+
)
162+
self.assertEqual(
163+
2, frame.GetValueForVariablePath("f1->next->value").GetValueAsUnsigned()
164+
)
165+
self.assertEqual(
166+
1,
167+
frame.GetValueForVariablePath(
168+
"f1->next.object.next.obj.value"
169+
).GetValueAsUnsigned(),
170+
)
171+
self.assertEqual(
172+
1,
173+
frame.GetValueForVariablePath("f1->next->next->value").GetValueAsUnsigned(),
174+
)
175+
176+
@add_test_categories(["libstdcxx"])
177+
def test_recursive_unique_ptr_libstdcxx(self):
178+
self.build(dictionary={"USE_LIBSTDCPP": 1})
179+
self.do_test_recursive_unique_ptr()
180+
181+
@add_test_categories(["libc++"])
182+
def test_recursive_unique_ptr_libcxx(self):
183+
self.build(dictionary={"USE_LIBCPP": 1})
184+
self.do_test_recursive_unique_ptr()
Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,20 @@ struct NodeU {
1515
// representation when the type of the second element is an empty class. So
1616
// we need a deleter class with a dummy data member to trigger the other path.
1717
struct NonEmptyIntDeleter {
18-
void operator()(int* ptr) { delete ptr; }
18+
void operator()(int *ptr) { delete ptr; }
1919

2020
int dummy_ = 9999;
2121
};
2222

23+
static void recursive() {
24+
// Set up a structure where we have a loop in the unique_ptr chain.
25+
NodeU *f1 = new NodeU{nullptr, 1};
26+
NodeU *f2 = new NodeU{nullptr, 2};
27+
f1->next.reset(f2);
28+
f2->next.reset(f1);
29+
std::puts("Set break point at this line.");
30+
}
31+
2332
int main() {
2433
std::unique_ptr<int> up_empty;
2534
std::unique_ptr<int> up_int = std::make_unique<int>(10);
@@ -33,5 +42,9 @@ int main() {
3342
std::unique_ptr<NodeU>(new NodeU{nullptr, 2});
3443
ptr_node = std::unique_ptr<NodeU>(new NodeU{std::move(ptr_node), 1});
3544

36-
return 0; // break here
45+
std::puts("// break here");
46+
47+
recursive();
48+
49+
return 0;
3750
}

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

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

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/unique_ptr/TestDataFormatterStdUniquePtr.py

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

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/unique_ptr/invalid/TestDataFormatterInvalidStdUniquePtr.py

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

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

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

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

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

0 commit comments

Comments
 (0)