-
-
Notifications
You must be signed in to change notification settings - Fork 23.4k
Add a method to print the stack trace #64205
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
base: master
Are you sure you want to change the base?
Conversation
4034658
to
b530bd3
Compare
Doing this would address godotengine/godot-proposals#963 🙂 I agree it should be off by default though (and there should be two project settings to toggle it: one for errors, one for warnings). |
How about obtaining the stack trace in a data structure instead of directly printing it? This way it can be routed elsewhere or formatted in other ways. |
I think this is worth adding as a separate method, but the method for quick printing should remain available for convenience. |
For the record (Aaron is already aware), this partially overlaps with the existing crash handler implementations in See also #61006. |
This adds a new method to the error macros that allows printing the stack trace. Add
print_stack_trace();
to any method to print the stack trace at that point. You can also specify if you want to skip a part of the stack trace at the beginning or end, to avoid any noisy lines you don't care about. It's only available in debug builds.There is no way to print the stack trace in a cross-platform way, so we need platform-specific code. On Mac and Linux, the code to print the stack trace is simple, since there is a handy library that does all the work for us, but we don't have fine control over the output. On Windows, it's more complicated, the code was designed based on this SO post and this article. I made the Windows code's output somewhat mimic the Mac/Linux code for consistency between platforms. Also, Windows stack trace printing only works on x86_32 and x86_64 (and technically Itanium, but Godot doesn't run on that).
This work was sponsored by The Mirror, we plan to use this by adding
print_stack_trace(2);
to thevoid _err_print_error
method so that we will get stack traces for every error (and the2
skips the calls to_err_print_error
itself). This is not included in this PR since it would be spammy, but it's one line away for anyone who wants it.