Skip to content
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

Reverse the stack traces #38873

Open
emilk opened this issue Jan 6, 2017 · 9 comments
Open

Reverse the stack traces #38873

emilk opened this issue Jan 6, 2017 · 9 comments
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR.

Comments

@emilk
Copy link

emilk commented Jan 6, 2017

A big improvement to the speed at which I can find the origin of a panic would be to reverse the order of the stack trace. At the moment the last line of the stack trace is always main. This means the stack trace is written deep->shallow, or in reverse(!) chronological order:

1:        0x10977219c - function_that_caused_the_panic
2:        0x1097738ee - foo
3:        0x109773590 - bar
4:        0x109773cf6 - baz
5:        0x109773b94 - badger
6:        0x109757669 - main

What you are generally looking for is the place that caused the panic (e.g. the line with an assert! or panic! on it), and so I think it would make sense to have that line last so that it is easy to find. This is particularly important when the call stack is deep and it fills your terminal. Here is a more in-depth argument for this.

So my suggestion is: reverse the stack trace to print the stack frames in chronological order, shallow->deep, with main on the top and the stack frame with the panic at the end:

6:        0x109757669 - main
5:        0x109773b94 - badger
4:        0x109773cf6 - baz
3:        0x109773590 - bar
2:        0x1097738ee - foo
1:        0x10977219c - function_that_caused_the_panic

I realize this can become quite the bikeshedding religious war, and maybe this has been discussed before – if so, I apologize. Still, until the blog post above brought it up I didn't realize that most languages – including Rust – was doing it wrong, and that there was a better way. In C++ I switched the order I print stack traces about a year ago, and since then it has saved me a lot of scrolling.

EDIT: I've created a forum thread about this here: https://users.rust-lang.org/t/reverse-stack-trace-order/8786

@Outpox
Copy link

Outpox commented Jan 6, 2017

Coming from a JS - PHP background I was used to it because it's more relevant to get the latest error written at the top of the page displaying it.
When I had my first error in Rust I was indeed surprised by this order and expected to see the error on the last line.

@aidanhs
Copy link
Member

aidanhs commented Jan 6, 2017

Perhaps worth a discussion on https://users.rust-lang.org (or internals) instead since I can see it being contentious?

@alexcrichton
Copy link
Member

cc #38165 and #37783, other issues for improving the backtrace output

@emilk
Copy link
Author

emilk commented Jan 7, 2017

@Yamakaky
Copy link
Contributor

Yamakaky commented Jan 7, 2017

You may want to wait for #38165 to be merged before making your change, as it would be just adding a .rev() at https://github.com/Yamakaky/rust/blob/39f2709dd465d360cc9e3521afd339b49950aceb/src/libstd/sys_common/backtrace.rs#L56.

@emilk
Copy link
Author

emilk commented Jan 9, 2017

Note that this suggestion is all about improving the edit-compile-debug cycle, an explicit goal in the 2017 roadmap.

Of course, whether or not it does improve it might be a personal thing. For me it absolutely does. Maybe an option to reverse it is a fair compromise, or at least a start?

@Mark-Simulacrum Mark-Simulacrum added the T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue. label Jun 23, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-feature-request Category: A feature request, i.e: not implemented / a PR. label Jul 26, 2017
@jasonhansel
Copy link

jasonhansel commented Jan 26, 2018

I'd like this too! It would also be nice if stack traces had pretty (terminal) colors, perhaps with an extension to RUST_BACKTRACE. Also: it would be useful if one could hide standard library sources from the stack trace.

@steveklabnik
Copy link
Member

Triage: no changes here.

@ehuss ehuss removed the T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue. label Feb 15, 2022
@matklad
Copy link
Member

matklad commented Oct 18, 2022

Couple of thoughts: at this point, there’s no way we actually flip the default presentation. At the same time, we already allow controlling backtrace formatting via RUST_BACKTRACE env var. I think implementing a nightly-only RUST_BACKTRACE=“short,reversed” would be an immediate win which wouldn’t require too much bike shedding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR.
Projects
None yet
Development

No branches or pull requests

10 participants