Skip to content

Kotlin compiler plugin to recover minimal stack trace of launch site #825

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
SUPERCILEX opened this issue Nov 13, 2018 · 4 comments
Closed

Comments

@SUPERCILEX
Copy link
Contributor

#74 is targeted at full stack trace recovery for debug builds, but would it be possible to recover only the first few items on the stack at compile time? That way, this could be used in prod. The hardcoded stacktrace would stop at the first branch off point, but it would at least provide some context as to where a random crash came from. Currently, there's no way to know where the crash originated. Not sure how this would work with Proguard/R8.

WDYT? Is it possible? Would other people want this?

@fvasco
Copy link
Contributor

fvasco commented Nov 13, 2018

Compute the stack at compile time is not possible.
A function (ie toString()) can be called multiple times by many methods, other functions can be recursive, with a potentially infinite stack trace.
As a prove, if every single method knows its stack at compile time, so every single method knows the caller method/line, there is no reason to store the invocation stack at runtime, because the compiler is able to put a GOTO (or similar) to the right point.

However is possible to include a stack trace (or a part of it) at runtime in the coroutine context, this can recovered, inspected and logged when required. This solution is subject to obfuscation.

Finally compiler can expose some intrinsic methods to recover the current source file name/current source line at build time, in such case the coroutineScope or coroutine builders can save in the scope a single stack frame.

@SUPERCILEX
Copy link
Contributor Author

Finally compiler can expose some intrinsic methods to recover the current source file name/current source line at build time, in such case the coroutineScope or coroutine builders can save in the scope a single stack frame.

Yes, that's what I was referring to.

@elizarov
Copy link
Contributor

It is hard. The plan for debugger support is to capture stacktraces only when a new coroutine is launches, which should not be happening that often, so it might be appropriate for use in prod in many cases.

@qwwdfsad
Copy link
Collaborator

qwwdfsad commented Nov 27, 2018

Frankly speaking, the initial proposal is impossible, because multiple entry-points to a method typically exist.

Nevertheless, the compiler provides some kind of internal API to walk over continuations (at runtime, not statically) and we are leveraging it in #792.

Moreover, we have an even better solution: https://github.com/Kotlin/kotlinx.coroutines/tree/debug-agent/core/kotlinx-coroutines-core-test (without a PR yet, but it is actively evaluated internally).

I will close this issue as it is already covered b these two enhancements

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants