diff --git a/src/report.rs b/src/report.rs index dfa5123..86ee18a 100644 --- a/src/report.rs +++ b/src/report.rs @@ -75,16 +75,10 @@ impl Report { } fn render_backtrace() -> String { - //We skip 3 frames from backtrace library - //Then we skip 3 frames for our own library - //(including closure that we set as hook) - //Then we skip 2 functions from Rust's runtime - //that calls panic hook - const SKIP_FRAMES_NUM: usize = 8; //We take padding for address and extra two letters //to pad after index. #[allow(unused_qualifications)] // needed for pre-1.80 MSRV - const HEX_WIDTH: usize = mem::size_of::() + 2; + const HEX_WIDTH: usize = mem::size_of::() * 2 + 2; //Padding for next lines after frame's address const NEXT_SYMBOL_PADDING: usize = HEX_WIDTH + 6; @@ -95,50 +89,58 @@ fn render_backtrace() -> String { //We need to print its address //and symbol(e.g. function name), //if it is available - for (idx, frame) in Backtrace::new() - .frames() - .iter() - .skip(SKIP_FRAMES_NUM) - .enumerate() - { - let ip = frame.ip(); - let _ = write!(backtrace, "\n{idx:4}: {ip:HEX_WIDTH$?}"); - + let mut entry_idx = 0; + let mut skip = true; + for frame in Backtrace::new().frames().iter() { let symbols = frame.symbols(); if symbols.is_empty() { - let _ = write!(backtrace, " - "); - continue; - } - - for (idx, symbol) in symbols.iter().enumerate() { - //Print symbols from this address, - //if there are several addresses - //we need to put it on next line - if idx != 0 { - let _ = write!(backtrace, "\n{:1$}", "", NEXT_SYMBOL_PADDING); - } - - if let Some(name) = symbol.name() { - let _ = write!(backtrace, " - {name}"); - } else { - let _ = write!(backtrace, " - "); - } - - //See if there is debug information with file name and line - if let (Some(file), Some(line)) = (symbol.filename(), symbol.lineno()) { - let _ = write!( - backtrace, - "\n{:3$}at {}:{}", - "", - file.display(), - line, - NEXT_SYMBOL_PADDING - ); + let ip = frame.ip(); + let _ = writeln!(backtrace, "{entry_idx:4}: {ip:HEX_WIDTH$?} - "); + entry_idx += 1; + } else { + let mut first = true; + for symbol in symbols.iter() { + if skip { + if symbol.name().map(|s| s.to_string()).as_deref() == Some("rust_begin_unwind") + { + skip = false; + } + continue; + } + //Print symbols from this address, + //if there are several addresses + //we need to put it on next line + if first { + let ip = frame.ip(); + let _ = write!(backtrace, "{entry_idx:4}: {ip:HEX_WIDTH$?}"); + first = false; + } else { + let _ = write!(backtrace, "{entry_idx:4}: {:HEX_WIDTH$?}", ""); + } + + if let Some(name) = symbol.name() { + let _ = write!(backtrace, " - {name}"); + } else { + let _ = write!(backtrace, " - "); + } + + let _ = writeln!(backtrace); + entry_idx += 1; + + //See if there is debug information with file name and line + if let (Some(file), Some(line)) = (symbol.filename(), symbol.lineno()) { + let _ = writeln!( + backtrace, + "{:3$}at {}:{}", + "", + file.display(), + line, + NEXT_SYMBOL_PADDING + ); + } } } } - let _ = writeln!(backtrace); - backtrace } diff --git a/tests/single-panic/tests/integration.rs b/tests/single-panic/tests/integration.rs index d9a9efc..60482d0 100644 --- a/tests/single-panic/tests/integration.rs +++ b/tests/single-panic/tests/integration.rs @@ -55,7 +55,6 @@ Panic occurred in file 'tests/single-panic/src/main.rs' at line [..] "cause" = "OMG EVERYTHING IS ON FIRE!!!" "method" = "Panic" "backtrace" = """ - ... """