[lldb][swift] Fix unwinding of Q funclets by comparing PC to continuation ptr #9574
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Unwinding these funclets is tricky because they change, halfway through the function, the meaning of the async register. In particular, the meaning changes from:
a) "the async context to be freed" [of the async function that just finished executing]
To:
b) "the async context of the current async function" [which has just been resumed].
LLDB has no way of identifying the instruction in which this transition happened.
This patch improves the situation slightly by employing a heuristic: if the async register has a continuation pointer that is equal to the currently executing funclet, then the stop is before the transition point. This heuristic fails on some recursive async functions.
An alternative approach involves assuming we will never stop between the end of the prologue and the transition point, so that LLDB may always unwind assuming it is past the transition point if the stop is outside the prologue. This has the benefit that it should "always work", including in recursive funclets.
However, it is difficult to reason about where a debugger may stop; in fact, very often the transition point is the second instruction after the prologue, which will trigger the fail point in a common scenario. Breakpoints are often placed in the first instruction after the prologue, and any kind of step operation will first "instruction step" over the breakpoint location, placing the debugger exactly in the "incorrect unwinding" zone.
A correct implementation will likely require more guarantees from the compiler. See rdar://139676623