Skip to content

Commit 57d5de2

Browse files
authored
Merge pull request #6436 from augusto2112/cxx-interop-stepping
[lldb] Add tests for stepping from Swift into C++
2 parents 8ea26b8 + 058e0cb commit 57d5de2

File tree

15 files changed

+514
-34
lines changed

15 files changed

+514
-34
lines changed

lldb/test/API/lang/swift/cxx_interop/forward/step-into-cxx/TestStepIntoCxx.py

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

lldb/test/API/lang/swift/cxx_interop/forward/step-into-cxx/cxx-functions.h

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

lldb/test/API/lang/swift/cxx_interop/forward/step-into-cxx/main.swift

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
SWIFT_SOURCES := main.swift
2+
CXX_SOURCES := impl.cpp
3+
SWIFT_CXX_INTEROP := 1
4+
SWIFTFLAGS_EXTRAS = -Xcc -I$(SRCDIR)
5+
include Makefile.rules
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
2+
"""
3+
Test that stepping works for forward interop
4+
"""
5+
from lldbsuite.test.lldbtest import *
6+
from lldbsuite.test.decorators import *
7+
8+
9+
class TestSteppingForwardInterop(TestBase):
10+
11+
@swiftTest
12+
def test_step_into_function(self):
13+
""" Test that stepping into a simple C++ function works"""
14+
self.build()
15+
self.runCmd('setting set target.experimental.swift-enable-cxx-interop true')
16+
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
17+
self, 'Break here for function', lldb.SBFileSpec('main.swift'))
18+
19+
name = thread.frames[0].GetFunctionName()
20+
self.assertIn('testFunction', name)
21+
thread.StepInto()
22+
name = thread.frames[0].GetFunctionName()
23+
self.assertIn('cxxFunction', name)
24+
thread.StepOut()
25+
name = thread.frames[0].GetFunctionName()
26+
self.assertIn('testFunction', name)
27+
28+
@swiftTest
29+
def test_step_over_function(self):
30+
""" Test that stepping over a simple C++ function works"""
31+
self.build()
32+
self.runCmd('setting set target.experimental.swift-enable-cxx-interop true')
33+
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
34+
self, 'Break here for function', lldb.SBFileSpec('main.swift'))
35+
36+
name = thread.frames[0].GetFunctionName()
37+
self.assertIn('testFunction', name)
38+
thread.StepOver()
39+
name = thread.frames[0].GetFunctionName()
40+
self.assertIn('testFunction', name)
41+
42+
43+
@swiftTest
44+
def test_step_into_method(self):
45+
""" Test that stepping into a C++ method works"""
46+
self.build()
47+
self.runCmd('setting set target.experimental.swift-enable-cxx-interop true')
48+
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
49+
self, 'Break here for method', lldb.SBFileSpec('main.swift'))
50+
51+
name = thread.frames[0].GetFunctionName()
52+
self.assertIn('testMethod', name)
53+
thread.StepInto()
54+
name = thread.frames[0].GetFunctionName()
55+
self.assertIn('cxxMethod', name)
56+
thread.StepOut()
57+
name = thread.frames[0].GetFunctionName()
58+
self.assertIn('testMethod', name)
59+
60+
@swiftTest
61+
def test_step_over_method(self):
62+
""" Test that stepping over a C++ method works"""
63+
self.build()
64+
self.runCmd('setting set target.experimental.swift-enable-cxx-interop true')
65+
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
66+
self, 'Break here for method', lldb.SBFileSpec('main.swift'))
67+
68+
name = thread.frames[0].GetFunctionName()
69+
self.assertIn('testMethod', name)
70+
thread.StepOver()
71+
name = thread.frames[0].GetFunctionName()
72+
self.assertIn('testMethod', name)
73+
74+
@swiftTest
75+
def test_step_into_constructor(self):
76+
""" Test that stepping into a simple C++ constructor works"""
77+
self.build()
78+
self.runCmd('setting set target.experimental.swift-enable-cxx-interop true')
79+
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
80+
self, 'Break here for constructor', lldb.SBFileSpec('main.swift'))
81+
82+
# FIXME: this step over shouldn't be necessary (rdar://105569287)
83+
thread.StepOver()
84+
85+
name = thread.frames[0].GetFunctionName()
86+
self.assertIn('testContructor', name)
87+
thread.StepInto()
88+
name = thread.frames[0].GetFunctionName()
89+
self.assertIn('ClassWithConstructor::ClassWithConstructor', name)
90+
thread.StepOut()
91+
name = thread.frames[0].GetFunctionName()
92+
self.assertIn('testContructor', name)
93+
94+
@swiftTest
95+
def test_step_over_constructor(self):
96+
""" Test that stepping over a simple C++ constructor works"""
97+
self.build()
98+
self.runCmd('setting set target.experimental.swift-enable-cxx-interop true')
99+
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
100+
self, 'Break here for constructor', lldb.SBFileSpec('main.swift'))
101+
102+
# FIXME: this step over shouldn't be necessary (rdar://105569287)
103+
thread.StepOver()
104+
105+
name = thread.frames[0].GetFunctionName()
106+
self.assertIn('testContructor', name)
107+
thread.StepOver()
108+
name = thread.frames[0].GetFunctionName()
109+
self.assertIn('testContructor', name)
110+
111+
@swiftTest
112+
def test_step_into_extension(self):
113+
""" Test that stepping into a C++ function defined in an extension works"""
114+
self.build()
115+
self.runCmd('setting set target.experimental.swift-enable-cxx-interop true')
116+
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
117+
self, 'Break here for extension', lldb.SBFileSpec('main.swift'))
118+
119+
name = thread.frames[0].GetFunctionName()
120+
self.assertIn('testClassWithExtension', name)
121+
thread.StepInto()
122+
name = thread.frames[0].GetFunctionName()
123+
self.assertIn('definedInExtension', name)
124+
thread.StepOut()
125+
name = thread.frames[0].GetFunctionName()
126+
self.assertIn('testClassWithExtension', name)
127+
128+
@swiftTest
129+
def test_step_over_extension(self):
130+
""" Test that stepping over a C++ function defined in an extension works"""
131+
self.build()
132+
self.runCmd('setting set target.experimental.swift-enable-cxx-interop true')
133+
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
134+
self, 'Break here for extension', lldb.SBFileSpec('main.swift'))
135+
136+
name = thread.frames[0].GetFunctionName()
137+
self.assertIn('testClassWithExtension', name)
138+
thread.StepOver()
139+
name = thread.frames[0].GetFunctionName()
140+
self.assertIn('testClassWithExtension', name)
141+
142+
@swiftTest
143+
def test_step_into_call_operator(self):
144+
""" Test that stepping into a C++ call operator works"""
145+
self.build()
146+
self.runCmd('setting set target.experimental.swift-enable-cxx-interop true')
147+
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
148+
self, 'Break here for call operator', lldb.SBFileSpec('main.swift'))
149+
150+
name = thread.frames[0].GetFunctionName()
151+
self.assertIn('testCallOperator', name)
152+
thread.StepInto()
153+
name = thread.frames[0].GetFunctionName()
154+
self.assertIn('ClassWithCallOperator::operator()()', name)
155+
thread.StepOut()
156+
name = thread.frames[0].GetFunctionName()
157+
self.assertIn('testCallOperator', name)
158+
159+
@swiftTest
160+
def test_step_over_call_operator(self):
161+
""" Test that stepping over a C++ call operator works"""
162+
self.build()
163+
self.runCmd('setting set target.experimental.swift-enable-cxx-interop true')
164+
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
165+
self, 'Break here for call operator', lldb.SBFileSpec('main.swift'))
166+
167+
name = thread.frames[0].GetFunctionName()
168+
self.assertIn('testCallOperator', name)
169+
thread.StepOver()
170+
name = thread.frames[0].GetFunctionName()
171+
self.assertIn('testCallOperator', name)
172+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
void cxxFunction();
2+
3+
struct CxxClass {
4+
void cxxMethod();
5+
};
6+
7+
struct ClassWithConstructor {
8+
int a;
9+
bool b;
10+
double c;
11+
12+
ClassWithConstructor(int a, bool b, double c);
13+
14+
};
15+
16+
struct ClassWithExtension {
17+
int val = 42;
18+
19+
int definedInExtension();
20+
};
21+
22+
struct ClassWithCallOperator {
23+
int operator()();
24+
};
25+
26+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include "cxx-functions.h"
2+
3+
void cxxFunction() {
4+
int a = 42;
5+
}
6+
7+
void CxxClass::cxxMethod() {
8+
int a = 42;
9+
}
10+
11+
ClassWithConstructor::ClassWithConstructor(int a, bool b, double c)
12+
: a(a), b(b), c(c) {}
13+
14+
int ClassWithExtension::definedInExtension() { return val; }
15+
16+
int ClassWithCallOperator::operator()() { return 42; }
17+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import CxxFunctions
2+
3+
func testFunction() {
4+
cxxFunction() // Break here for function
5+
}
6+
7+
func testMethod() {
8+
var cxxClass = CxxClass()
9+
cxxClass.cxxMethod() // Break here for method
10+
}
11+
12+
func testContructor() {
13+
//FIXME: remove this statement rdar://105569287
14+
print(1) // Break here for constructor
15+
var classWithConstructor = ClassWithConstructor(4, true, 5.7);
16+
}
17+
18+
protocol P {
19+
mutating func definedInExtension() -> Int32
20+
}
21+
22+
extension ClassWithExtension: P {}
23+
24+
func testClassWithExtension() {
25+
var classWithExtension: P = ClassWithExtension()
26+
classWithExtension.definedInExtension() // Break here for extension
27+
}
28+
29+
30+
func testCallOperator() {
31+
var classWithCallOperator = ClassWithCallOperator()
32+
classWithCallOperator() // Break here for call operator
33+
}
34+
35+
36+
testFunction()
37+
testMethod()
38+
testContructor()
39+
testClassWithExtension()
40+
testCallOperator()

0 commit comments

Comments
 (0)