
Debugging C++ Coroutines [pdf] - rbanffy
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p2073r0.pdf
======
pjmlp
In .NET it took a couple of VS releases and iterations until tooling really
caught up with async/await.

C++ has the additional problem that each iteration takes about three years and
only a couple of compilers are developed with tooling in mind.

~~~
tybit
The state of async await tooling is shocking IMO.

For anyone curious how bad it was, here’s a StackOverflow post from 2013
asking about intelligible async stack traces in C# with a proper solution not
delivered until 2018 [https://stackoverflow.com/questions/15410661/is-it-
possible-...](https://stackoverflow.com/questions/15410661/is-it-possible-to-
get-a-good-stack-trace-with-net-async-methods)

When it was finally delivered it was done by an amazing individual(Ben Adams)
picking up the slack for Microsoft.

Last time I used Node in anger, last year, their async stack traces were even
worse, losing the stack traces at the await point. Hopefully they’ve fixed it
by now.

~~~
cheez
Python does it pretty well. At least I don't find myself wondering what is
happening.

------
phaedrus
This is a good time to reiterate my idea that I call "stacking the stack"
(like stacking the deck in card games). The idea is that you transform a
simple alternation between coroutineA and coroutineB into nested method calls,
methodA(continuationB) and methodB(continuationA). This way the local context
of A and B are live on the stack for debugging.

Of course there would be a limit of depth, but there's always the option to
pass an empty continuation and allow the stack to unwind. Since they are
coroutines they don't care if you unwind the stack and wind it back up. What I
mean is the stack could look like "A-B-A-B-A-B" or "A-B .. A-B .. A-B" or "A
.. B .. A .." it doesn't matter. For release build (not debugging) you would
just set the depth to 1 and have normal non-nested coroutines.

I can implement this with macros (you wrap your return statements and your
co_xxxx statements with a macro) using hand-rolled coroutines. I haven't yet
gotten familiar enough into C++ std coroutines to implement it there or see if
they allow it to be done without macros.

~~~
cryptonector
Aka, tracing.

------
cjfd
One can always add print statement. And for asynchronous code this is often
the only realistic way to debug. If you pause some thread in a debugger you
might end up with other threads noticing it is no longer responding, firing
timeouts and so on.

~~~
gpderetta
I just want proper stack traces in my core dumps.

------
monadic2
Imagine if C++ had a proper repl.

~~~
pjmlp
Yeah, I wonder how it would look like.

[https://root.cern.ch/cling](https://root.cern.ch/cling)

[https://blog.jupyter.org/interactive-workflows-for-c-with-
ju...](https://blog.jupyter.org/interactive-workflows-for-c-with-jupyter-
fe9b54227d92?gi=25992d652f31)

