Skip to content

Commit cf4a54e

Browse files
[lldb][swift] Handle asyncLet_get_throwing trampoline (#10783)
This can also cause a task switch and should be handled like `swift_task_switch` and `asyncLet_get`.
1 parent 49825a6 commit cf4a54e

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntimeNames.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ CreateRunThroughTaskSwitchingTrampolines(Thread &thread,
423423
// void *,
424424
// TaskContinuationFunction *,
425425
if (trampoline_name == "swift_asyncLet_get" ||
426+
trampoline_name == "swift_asyncLet_get_throwing" ||
426427
trampoline_name == "swift_asyncLet_finish")
427428
return CreateRunThroughTaskSwitchThreadPlan(thread,
428429
LLDB_REGNUM_GENERIC_ARG3);

lldb/test/API/lang/swift/async/stepping/step_over_asynclet/TestSwiftAsyncStepOverAsyncLet.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ def check_is_in_line(self, thread, linenum):
1414

1515
@swiftTest
1616
@skipIf(oslist=["windows", "linux"])
17-
def test(self):
17+
def test_nothrow(self):
1818
"""Test conditions for async step-over."""
1919
self.build()
2020

2121
source_file = lldb.SBFileSpec("main.swift")
2222
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
23-
self, "BREAK HERE", source_file
23+
self, "BREAK_NOTHROW", source_file
2424
)
2525

2626
# Step over should reach every line in the interval [10, 20]
@@ -30,3 +30,22 @@ def test(self):
3030
stop_reason = thread.GetStopReason()
3131
self.assertStopReason(stop_reason, lldb.eStopReasonPlanComplete)
3232
self.check_is_in_line(thread, expected_line_num)
33+
34+
@swiftTest
35+
@skipIf(oslist=["windows", "linux"])
36+
def test_throw(self):
37+
"""Test conditions for async step-over."""
38+
self.build()
39+
40+
source_file = lldb.SBFileSpec("main.swift")
41+
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
42+
self, "BREAK_THROW", source_file
43+
)
44+
45+
# Step over should reach every line in the interval [34, 40]
46+
expected_line_nums = range(34, 41)
47+
for expected_line_num in expected_line_nums:
48+
thread.StepOver()
49+
stop_reason = thread.GetStopReason()
50+
self.assertStopReason(stop_reason, lldb.eStopReasonPlanComplete)
51+
self.check_is_in_line(thread, expected_line_num)

lldb/test/API/lang/swift/async/stepping/step_over_asynclet/main.swift

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ func work() {}
66

77
func foo() async {
88
do {
9-
work() // BREAK HERE
9+
work() // BREAK_NOTHROW
1010
async let timestamp1 = getTimestamp(x:1)
1111
work()
1212
async let timestamp2 = getTimestamp(x:2)
@@ -20,8 +20,30 @@ func foo() async {
2020
print(actual_timestamp3)
2121
}
2222

23+
struct NegativeInputError: Error {}
24+
func getTimestamp_throwing(x: Int) async throws -> Int {
25+
if (x < 0) {
26+
throw NegativeInputError()
27+
}
28+
return 40 + x
29+
}
30+
31+
func foo_throwing() async {
32+
do {
33+
work() // BREAK_THROW
34+
async let timestamp1 = getTimestamp_throwing(x:1)
35+
work()
36+
async let timestamp2 = getTimestamp_throwing(x:2)
37+
work()
38+
let timestamps = try await [timestamp1, timestamp2]
39+
print(timestamps)
40+
} catch {print(error)}
41+
work()
42+
}
43+
2344
@main enum entry {
2445
static func main() async {
2546
await foo()
47+
await foo_throwing()
2648
}
2749
}

0 commit comments

Comments
 (0)