-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
stacktraces can now show custom runtime msgs per frame #13351
Conversation
79f8b88
to
e973254
Compare
This is really slick! I can see this being used in things like backend servers to annotate exceptions when something unexpected happens in a request. |
6e29493
to
577e95e
Compare
PTAL @Araq, ready for review |
friendly ping @Araq this really helps for debugging, whether you're debugging compiler or debugging user code, making stacktraces a lot more powerful |
Do you know if this would be compatible with talk of using libbacktrace? |
this only works with nim's default backtrace which relies on inserting code at begin/end of each function; this can't work with libbacktrace (which you get with |
577e95e
to
0ea91b7
Compare
PTAL, all comments addressed, and now test works with or without --gc:arc; I'd really like to have this PR merged as it helps a lot when debugging (whether it's user programs or nim compiler itself); |
Cool. Looks like a nice feature, up to Araq or someone else knowledgeable with these internals to review though. :) |
0ea91b7
to
4a6b786
Compare
PTAL @Araq
done, see latest commit; |
|
4a6b786
to
114b91e
Compare
friendly ping @Araq |
Sorry, I was unclear. Can the |
I don't see how that'd work, please explain; the problem with proc fun()=setFrameMsg("foo")
try:
fun()
except Exception as e:
printf("%s\n", e.frameMsg) # that should be safe even though stack was unwinded
bar() # this could overwrite what `e.frameMsg` points to, potentially
printf("%s\n", e.frameMsg) # now we are reading the wrong thing unless what you mean is for notehow about I hide this behind |
Ok. |
114b91e
to
350d6f4
Compare
done, PTAL
|
note: when defined nimHasStacktraceMsgs: switch("stacktraceMsgs", "on") which is backward compatible |
stacktraces can now show custom runtime msgs per frame.
useful in many cases where the stacktrace alone isn't sufficient to debug an issue; in particular for any parser / compiler (such as nim compiler), showing additional runtime info helps showing tracing program along with traced source code (+ arbitrary computed values)
efficient implementation using a fixed string, so there is no allocation cost (amortized cost = O(1)); the only allocations happen if an exception is thrown; for stackframe entries with a nonempty custom msg, a string will be allocated before unwinding the stack so that the custom msg isn't invalidated by further calls to
setFrameMsg
example:
say you want to debug an internal compiler error such as #12263 which normally gives a regular stacktrace error (with --stacktrace:on);
if we simply add the following line inside
proc semExpr(...)
(obviouslysetFrameMsg
can be called in other places as needed)it'll show that context in each stackframe corresponding to that (re-entrant) function, which helps showing the progress in the file being compiled:
stacktrace with custom runtime msgs for
nim c /pathto/t1015.nim
shows both tracing and traced programs along side:
unrelated changes