SFrame for C++ coroutine stack traces
Mehrdad Niknami
mniknami@google.com
Fri Jan 23 17:41:30 GMT 2026
On Fri, Jan 23, 2026 at 6:43 AM Jens Remus <jremus@linux.ibm.com> wrote:
> Would it work if factorial() would get annotated as coroutine, e.g. using
> a new CFI directive .cfi_coroutine[_frame] (similar to .cfi_signal_frame)
> emitted by the compiler, so that e.g. a SFrame stack tracer would then
> invoke a coroutine stack tracer before continuing as usual?
>
> The SFrame stack tracer would produce (only the IP's of course):
> printf()
> factorial(n=3) // coroutine frame [*]
>
> The then called coroutine stack tracer would produce:
> factorial(n=2) (.resume)
> factorial(n=1) (.resume)
>
> Then the SFrame stack tracer would continue to produce:
> std::coroutine_handle<>::resume()
> Task<>::Resume()
> main()
>
> [*]: Actually this would only get detected while "unwinding" from
> this IP. I annotated it here for easier understanding of the concept.
>
That sounds quite plausible; I suspect so. If there is an obstacle here, it
would probably be inlining, but I imagine that is already handled elsewhere
and wouldn't be too different here.
> The missing piece of the puzzle is: how would the interleaving process
> figure out *where* to insert the coroutine frames into the ordinary
> stack trace?
> > Conceptually, we need some way to identify Task::Resume() in the
> stack trace, and insert everything beneath the
> std::coroutine_handle<>::resume() that it is eventually calling downstream.
>
> If it is preferable to identify where to insert the missing pieces then
> e.g. Task::Resume() could get annotated in a similar way.
>
The pieces would always need to be inserted immediately before the leaf
coroutine call (factorial(n=3)).
We're only using Task::Resume() as a search needle/anchor here to avoid the
performance overhead (and noise, etc.) of marking *every* coroutine as
noinline.
(Task::Resume() is only the top-level resumption function, so in many
applications it is invoked infrequently. As long as any coroutine is
running, hand-offs between them occur elsewhere in internal machinery, so
all resumptions are inlinable until everything suspends.)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://sourceware.org/pipermail/binutils/attachments/20260123/194586c0/attachment.htm>
More information about the Binutils
mailing list