Are there any tools, released or otherwise, that h...
# coroutines
j
Are there any tools, released or otherwise, that help debug coroutine stack-traces?
🤔 2
g
I have been thinking about this for a very long time, AFAIK the answer is still no, though I threatened to build it at kotlin-conf.
Asking for general support at runtime is impossible to my knowledge, to keep the runtime maintaining any degree of efficiency the information about the stack-frame-chunks (frames between resume-calls and suspend-calls) are lost. what you could do is create a dispatcher that calls the stack-walking API (alternatively
new Exception().subSequence(...)
) at every suspension point. Since every continuation has a reference to its parent, you could then "walk" back up the continuations, asking each for its stack-trace sub-section, stitch them together, and produce a full stack trace. note that this means every suspension call is doing a fairly expensive reflection operation, which would reduce your performance by an order of magnitude (or more) --which, honestly, might not be a problem, depending on your application.
I'd like to build this, but its packaging would be tricky. I think what youd like is to be able to do something like supply a regex or a package name or similar to be able to say "apply this stack-trace-keeping stuff to only these code areas". but i dont know what the right combination of class loader games and byte-code-manipulation would be.
j
why does it have to be for every suspension call? Couldn’t you defer the walk until a stack trace is requested?
at least for me, it doesn’t have to look like a traditional stack-trace. Just need information on what the current state is. Not sure if that makes the problem any easier though