Skip to content

🍒[lldb][swift] Handle asyncLet_get_throwing trampoline (#10783) #10824

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ CreateRunThroughTaskSwitchingTrampolines(Thread &thread,
// void *,
// TaskContinuationFunction *,
if (trampoline_name == "swift_asyncLet_get" ||
trampoline_name == "swift_asyncLet_get_throwing" ||
trampoline_name == "swift_asyncLet_finish")
return CreateRunThroughTaskSwitchThreadPlan(thread,
LLDB_REGNUM_GENERIC_ARG3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ def check_is_in_line(self, thread, linenum):

@swiftTest
@skipIf(oslist=["windows", "linux"])
def test(self):
def test_nothrow(self):
"""Test conditions for async step-over."""
self.build()

source_file = lldb.SBFileSpec("main.swift")
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
self, "BREAK HERE", source_file
self, "BREAK_NOTHROW", source_file
)

# Step over should reach every line in the interval [10, 20]
Expand All @@ -30,3 +30,22 @@ def test(self):
stop_reason = thread.GetStopReason()
self.assertStopReason(stop_reason, lldb.eStopReasonPlanComplete)
self.check_is_in_line(thread, expected_line_num)

@swiftTest
@skipIf(oslist=["windows", "linux"])
def test_throw(self):
"""Test conditions for async step-over."""
self.build()

source_file = lldb.SBFileSpec("main.swift")
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
self, "BREAK_THROW", source_file
)

# Step over should reach every line in the interval [34, 40]
expected_line_nums = range(34, 41)
for expected_line_num in expected_line_nums:
thread.StepOver()
stop_reason = thread.GetStopReason()
self.assertStopReason(stop_reason, lldb.eStopReasonPlanComplete)
self.check_is_in_line(thread, expected_line_num)
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ func work() {}

func foo() async {
do {
work() // BREAK HERE
work() // BREAK_NOTHROW
async let timestamp1 = getTimestamp(x:1)
work()
async let timestamp2 = getTimestamp(x:2)
Expand All @@ -20,8 +20,30 @@ func foo() async {
print(actual_timestamp3)
}

struct NegativeInputError: Error {}
func getTimestamp_throwing(x: Int) async throws -> Int {
if (x < 0) {
throw NegativeInputError()
}
return 40 + x
}

func foo_throwing() async {
do {
work() // BREAK_THROW
async let timestamp1 = getTimestamp_throwing(x:1)
work()
async let timestamp2 = getTimestamp_throwing(x:2)
work()
let timestamps = try await [timestamp1, timestamp2]
print(timestamps)
} catch {print(error)}
work()
}

@main enum entry {
static func main() async {
await foo()
await foo_throwing()
}
}