Skip to content

Commit d21e17f

Browse files
committed
Add a test for swift call site breakpoint and stepping.
1 parent 71ce522 commit d21e17f

File tree

4 files changed

+64
-7
lines changed

4 files changed

+64
-7
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
@freestanding(expression) public macro stringify<T>(_ value: T) -> (T, String) = #externalMacro(module: "MacroImpl", type: "StringifyMacro")
2+
3+
@freestanding(expression) public macro no_return<T>(_ value: T) = #externalMacro(module: "MacroImpl", type: "NoReturnMacro")

lldb/test/API/lang/swift/macro/MacroImpl.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,16 @@ public struct StringifyMacro: ExpressionMacro {
1414
return "(\(argument), \(StringLiteralExprSyntax(content: argument.description)))"
1515
}
1616
}
17+
18+
public struct NoReturnMacro: ExpressionMacro {
19+
public static func expansion(
20+
of macro: some FreestandingMacroExpansionSyntax,
21+
in context: some MacroExpansionContext
22+
) -> ExprSyntax {
23+
guard let argument = macro.argumentList.first?.expression else {
24+
fatalError("boom")
25+
}
26+
27+
return "print(\(argument), \(StringLiteralExprSyntax(content: argument.description)))"
28+
}
29+
}

lldb/test/API/lang/swift/macro/TestSwiftMacro.py

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,58 @@ def testDebugging(self):
3434
"""Test Swift macros"""
3535
self.build(dictionary={'SWIFT_SOURCES': 'main.swift'})
3636
self.setupPluginServerForTesting()
37+
main_spec = lldb.SBFileSpec('main.swift')
3738
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
38-
self, 'break here', lldb.SBFileSpec('main.swift'))
39+
self, 'break here', main_spec
40+
)
41+
42+
# We're testing line breakpoint setting here:
43+
call_site_line = lldbtest.line_number("main.swift", "#no_return(a / b)")
44+
call_site_bp = target.BreakpointCreateByLocation(main_spec, call_site_line)
3945

4046
thread.StepOver()
4147
thread.StepInto()
48+
4249
# This is the expanded macro source, we should be able to step into it.
43-
self.expect('reg read pc', substrs=[
44-
'[inlined] freestanding macro expansion #1 of stringify in module a file main.swift line 5 column 11',
45-
'stringify'
46-
])
50+
# Don't check the actual line number so we are line independent
51+
self.assertIn(
52+
'freestanding macro expansion #1 of stringify in module a file main.swift line 5 column 11',
53+
thread.frames[0].name,
54+
"Stopped in stringify macro"
55+
)
4756

4857
self.expect('expression -- #stringify(1)', substrs=['0 = 1', '1 = "1"'])
4958

59+
# Step out should get us out of stringify, then in to the next macro:
60+
thread.StepOut()
61+
self.assertIn("a.testStringify", thread.frames[0].name, "Step out back to origin")
62+
thread.StepInto()
63+
self.assertIn(
64+
"freestanding macro expansion #1 of no_return in module a file main.swift line 6 column 3",
65+
thread.frames[0].name,
66+
"Step out and in gets to no_return"
67+
)
68+
69+
# We've set a breakpoint on the call site for another instance - run to that:
70+
threads = lldbutil.continue_to_breakpoint(process, call_site_bp)
71+
self.assertEqual(len(threads), 1, "Stopped at one thread")
72+
thread = threads[0]
73+
frame_0 = thread.frames[0]
74+
line_entry_0 = frame_0.line_entry
75+
self.assertEqual(line_entry_0.line, call_site_line, "Got the right line attribution")
76+
self.assertEqual(line_entry_0.file, main_spec, "Got the right file attribution")
77+
78+
# Now test stepping in and back out again:
79+
thread.StepInto()
80+
self.assertIn(
81+
"freestanding macro expansion #3 of no_return in module a file main.swift line 8 column 3",
82+
thread.frames[0].name,
83+
"Step out and in gets to no_return"
84+
)
85+
86+
thread.StepOut()
87+
self.assertIn("a.testStringify", thread.frames[0].name, "Step out from no_return")
88+
5089
# Make sure we can set a symbolic breakpoint on a macro.
5190
b = target.BreakpointCreateByName("stringify")
5291
self.assertGreaterEqual(b.GetNumLocations(), 1)
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import Macro
2-
2+
// This test depends on the layout of the lines in this file.
33
func testStringify(a: Int, b: Int) {
44
print("break here")
55
let s = #stringify(a / b)
6+
#no_return(a)
7+
#no_return(b)
8+
#no_return(a / b)
69
print(s.1)
710
}
811

9-
testStringify(a: 23, b: 0)
12+
testStringify(a: 23, b: 1)

0 commit comments

Comments
 (0)