-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Add initial debug fmt for Backtrace #69038
Conversation
r? @shepmaster (rust_highfive has picked a reviewer for you, use r? to override) |
I'm starting with this most basic version of a Debug format that just derives everything and doesn't force any symbol resolution as a starting point for the rest of the PR, I still haven't tested how this looks in practice because compile times but I'm working on getting a unit test that I can use as a playground to render the format pre and post resolution so I can paste that into this issue for review. |
This is the current format from this PR, lmk what further changes are necessary.
As generated by this small snippet #[cfg(test)]
mod tests {
use super::*;
#[test]
fn debug_backtrace_fmt() {
let bt = Backtrace::capture();
eprintln!("uncaptured: {:?}", bt);
let bt = Backtrace::force_capture();
eprintln!("captured: {:?}", bt);
eprintln!("display print: {}", bt);
eprintln!("resolved: {:?}", bt);
unimplemented!();
}
} |
r? @dtolnay |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That representation looks extremely verbose to me. I expect that debug-printed backtraces are going to be a thing that humans see somewhat often (unfortunately) from unwrapped or debug printed error objects containing a backtrace. Could you see if you can strip out everything that wouldn't be informative to the reader?
Before:
Backtrace {
inner: Captured(
Mutex {
data: Capture {
actual_start: 2,
resolved: true,
frames: [
BacktraceFrame {
frame: Frame {
ip: 0x55c1fc866e5d,
symbol_address: 0x55c1fc866de0,
},
symbols: [
BacktraceSymbol {
name: Some(
std::backtrace::Backtrace::create,
),
filename: None,
lineno: None,
},
],
},
BacktraceFrame {
frame: Frame {
ip: 0x55c1fc866dd0,
symbol_address: 0x55c1fc866dc0,
},
symbols: [
BacktraceSymbol {
name: Some(
std::backtrace::Backtrace::force_capture,
),
filename: None,
lineno: None,
},
],
},
...
...
...
],
},
},
),
}
More reasonable:
Backtrace [
"std::backtrace::Backtrace::create",
"std::backtrace::Backtrace::force_capture",
"core::ops::function::FnOnce::call_once @ /rustc/src/libcore/ops/function.rs:231",
]
or list-of-maps style as suggested in #65280:
Backtrace [
{ fn: "std::backtrace::Backtrace::create" },
{ fn: "std::backtrace::Backtrace::force_capture" },
{ fn: "core::ops::function::FnOnce::call_once", file: "/rustc/src/libcore/ops/function.rs", line: 231 },
]
Sure, but I'm not sure how to handle the fact that a backtrace frame can have multiple symbols. Also, I'd personally prefer the to use How do you feel about this format
|
|
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
The logic within |
9d73fbf
to
c0ba79e
Compare
Okay, independent of my previous comment, here is the current format @dtolnay with the changes you've requested.
Fixing the |
Current version, this adds some
|
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Okay here is the current version
I manually added |
and here we go again, for possibly the last time she says with great hubris
|
Sigh... Why are these lines
being skipped in the display impl ._. investigates Edit: its because of |
Nice! Almost there I think. Thanks for sticking with this.
|
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
I believe the display impl prints the hashes for Here's the comparison between the alt and default display impls
They feel equally easy to read to me, so I have no preference, if you want my vote I'm gonna vote for no Edit: One thing I think might be important is how easily the debug impl can be parsed, so if you think that adding |
Oh I just noticed the resolved / non-opt debug print for Backtrace had hashes, thats definitely wrong, fixing. |
And now its backwards, because apparently they switched the meanings of alt where they use the alt print for PrintFmt::Short which is selected when alt is false 🙃 Gonna just make an executive decision here and not try to maintain exact compat with old behavior. |
Final-final-v2-format.jpg
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great. Looks good to me without the deliberately failing test. I don't know if there is a way to instantiate a hardcoded backtrace for testing purposes, but I wouldn't worry about it if it turns out to be not easy.
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
@bors r+ |
📌 Commit ec8ee7f has been approved by |
Add initial debug fmt for Backtrace Fixes the first point in rust-lang#65280 related to rust-lang#53487
Rollup of 7 pull requests Successful merges: - #67954 (Support new LLVM pass manager) - #68981 ( Account for type params on method without parentheses) - #69002 (miri: improve and simplify overflow detection) - #69038 (Add initial debug fmt for Backtrace) - #69040 (Cleanup SGX entry code) - #69086 (Update compiler-builtins to 0.1.25) - #69095 (Minified theme check) Failed merges: r? @ghost
Fixes the first point in #65280
related to #53487