The LLVM Project is a collection of modular and reusable compiler and toolchain technologies. This fork is used to manage Swift’s stable releases of Clang as well as support the Swift project.
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
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