Skip to content

[lldb] Use unique line count in swift_task_switch logic #6839

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

Conversation

kastiglione
Copy link

@kastiglione kastiglione commented May 10, 2023

When stepping into an async function, the compiler can emit two cases for the first async function split:

  1. A trampoline that immediately performs async dispatch via swift_task_switch
  2. The initial block of the async function's body

In the second case, step-in is done. In the second case, lldb does additional work to stop when the runtime dispatches to the async function (including setting a conditional internal breakpoint, and more).

lldb needs to distinguish between these two cases, in order to know which stepping logic to perform.

In the first case, the trampoline would ideally have no associated line table entries for the trampoline. However that's not been the case. Instead there has been a single (non-zero) line table entry for the trampoline. The logic lldb uses is to check the line table, and if there's only one line table entry, conclude that it's a trampoline. But, a recent update to the swift compiler has resulted in two line table entries for the trampoline, but both are for the same line – in other words there's still a single line referenced.

This changes the logic to use a set to track the line table entries. If only one unique line is found, conclude the function is a trampoline.

Ultimately, making swiftc emit no line table for these trampolines is the best fix.

@kastiglione
Copy link
Author

@swift-ci test

@kastiglione kastiglione marked this pull request as draft May 10, 2023 22:06
@kastiglione
Copy link
Author

Working on a test.

@kastiglione
Copy link
Author

@swift-ci test

@kastiglione kastiglione marked this pull request as ready for review May 16, 2023 16:22
@kastiglione kastiglione requested a review from adrian-prantl May 16, 2023 16:40
@kastiglione
Copy link
Author

@swift-ci test

@kastiglione
Copy link
Author

@swift-ci test macOS

@kastiglione kastiglione force-pushed the dl/lldb-use-unique-line-count-in-swift_task_switch-logic branch from 95f90d8 to 5c3acb0 Compare May 22, 2023 23:10
@kastiglione
Copy link
Author

@swift-ci test

@kastiglione
Copy link
Author

@adrian-prantl this is ready

@adrian-prantl adrian-prantl merged commit 8971304 into swift/release/5.9 May 23, 2023
target, _, thread, _ = lldbutil.run_to_source_breakpoint(self, "await f()", src)
self.assertEqual(thread.frame[0].function.mangled, "$s1a5entryO4mainyyYaFZ")

function = target.FindFunctions("$s1a5entryO4mainyyYaFZTQ0_")[0].function

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you assert that function is non-null? Will be easier to debug that way.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kastiglione kastiglione deleted the dl/lldb-use-unique-line-count-in-swift_task_switch-logic branch May 23, 2023 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants