Skip to content

Commit 8b656b8

Browse files
committed
[lldb] Re-eanble and rewrite TestCPPStaticMembers
It's not clear why the whole test got disabled, but the linked bug report has since been fixed and the only part of it that still fails is the test for the too permissive lookup. This re-enables the test, rewrites it to use the modern test functions we have and splits the failing part into its own test that we can skip without disabling the rest.
1 parent 8f681d5 commit 8b656b8

File tree

2 files changed

+32
-58
lines changed

2 files changed

+32
-58
lines changed

lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,51 +11,30 @@
1111
from lldbsuite.test import lldbutil
1212

1313

14-
class CPPStaticMembersTestCase(TestBase):
14+
class TestCase(TestBase):
1515

1616
mydir = TestBase.compute_mydir(__file__)
1717

18-
@expectedFailure # llvm.org/pr15401
1918
@expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr21765")
20-
def test_with_run_command(self):
21-
"""Test that member variables have the correct layout, scope and qualifiers when stopped inside and outside C++ methods"""
19+
def test_access_from_main(self):
2220
self.build()
23-
self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
21+
lldbutil.run_to_source_breakpoint(self, "// stop in main", lldb.SBFileSpec("main.cpp"))
2422

25-
self.set_breakpoint(line_number('main.cpp', '// breakpoint 1'))
26-
self.set_breakpoint(line_number('main.cpp', '// breakpoint 2'))
23+
self.expect_expr("my_a.m_a", result_type="short", result_value="1")
24+
self.expect_expr("my_a.s_b", result_type="long", result_value="2")
25+
self.expect_expr("my_a.s_c", result_type="int", result_value="3")
2726

28-
self.runCmd("process launch", RUN_SUCCEEDED)
29-
self.expect("expression my_a.access()",
30-
startstr="(long) $0 = 10")
31-
32-
self.expect("expression my_a.m_a",
33-
startstr="(short) $1 = 1")
34-
35-
# Note: SymbolFileDWARF::ParseChildMembers doesn't call
36-
# AddFieldToRecordType, consistent with clang's AST layout.
37-
self.expect("expression my_a.s_d",
38-
startstr="(int) $2 = 4")
39-
40-
self.expect("expression my_a.s_b",
41-
startstr="(long) $3 = 2")
42-
43-
self.expect("expression A::s_b",
44-
startstr="(long) $4 = 2")
45-
46-
# should not be available in global scope
47-
self.expect("expression s_d",
27+
def test_access_from_member_function(self):
28+
self.build()
29+
lldbutil.run_to_source_breakpoint(self, "// stop in member function", lldb.SBFileSpec("main.cpp"))
30+
self.expect_expr("m_a", result_type="short", result_value="1")
31+
self.expect_expr("s_b", result_type="long", result_value="2")
32+
self.expect_expr("s_c", result_type="int", result_value="3")
33+
34+
# Currently lookups find variables that are in any scope.
35+
@expectedFailureAll()
36+
def test_access_without_scope(self):
37+
self.build()
38+
self.createTestTarget()
39+
self.expect("expression s_c", error=True,
4840
startstr="error: use of undeclared identifier 's_d'")
49-
50-
self.runCmd("process continue")
51-
self.expect("expression m_c",
52-
startstr="(char) $5 = \'\\x03\'")
53-
54-
self.expect("expression s_b",
55-
startstr="(long) $6 = 2")
56-
57-
self.runCmd("process continue")
58-
59-
def set_breakpoint(self, line):
60-
lldbutil.run_break_set_by_file_and_line(
61-
self, "main.cpp", line, num_expected_locations=1, loc_exact=False)
Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
1-
struct A
2-
{
3-
short m_a;
4-
static long s_b;
5-
char m_c;
6-
static int s_d;
1+
struct A {
2+
short m_a;
3+
static long s_b;
4+
static int s_c;
75

8-
long access() {
9-
return m_a + s_b + m_c + s_d; // breakpoint 2
10-
}
6+
long access() {
7+
return m_a + s_b + s_c; // stop in member function
8+
}
119
};
1210

1311
long A::s_b = 2;
14-
int A::s_d = 4;
12+
int A::s_c = 3;
1513

16-
int main()
17-
{
18-
A my_a;
19-
my_a.m_a = 1;
20-
my_a.m_c = 3;
14+
int main() {
15+
A my_a;
16+
my_a.m_a = 1;
2117

22-
my_a.access(); // breakpoint 1
23-
return 0;
18+
my_a.access(); // stop in main
19+
return 0;
2420
}
25-

0 commit comments

Comments
 (0)