diff options
| author | Yamakaky <yamakaky@yamaworld.fr> | 2017-03-04 10:27:52 -0500 |
|---|---|---|
| committer | Yamakaky <yamakaky@yamaworld.fr> | 2017-05-09 19:51:50 +0200 |
| commit | ca8b75466cef854d30fdf7614c2358b1eb46816e (patch) | |
| tree | f2bfc45697fca40fadaa04346ed404598a7ad773 /src/libstd/sys_common | |
| parent | f3fc547194d22dc673274ac20e9a7b1e607cb862 (diff) | |
| download | rust-ca8b75466cef854d30fdf7614c2358b1eb46816e.tar.gz rust-ca8b75466cef854d30fdf7614c2358b1eb46816e.zip | |
Don't show the std frames before user code on unwinding.
When `RUST_BACKTRACE=1`, remove all frames after `__rust_maybe_catch_panic`. Tested on `main`, threads, tests and benches. Cleaning of the top of the stacktrace is let to a future PR. Fixes #40201 See #41815
Diffstat (limited to 'src/libstd/sys_common')
| -rw-r--r-- | src/libstd/sys_common/backtrace.rs | 44 |
1 files changed, 40 insertions, 4 deletions
diff --git a/src/libstd/sys_common/backtrace.rs b/src/libstd/sys_common/backtrace.rs index 04fe5f78b03..617218fe7a5 100644 --- a/src/libstd/sys_common/backtrace.rs +++ b/src/libstd/sys_common/backtrace.rs @@ -93,11 +93,47 @@ fn _print(w: &mut Write, format: PrintFormat) -> io::Result<()> { Ok(()) } -fn filter_frames(_frames: &[Frame], - _format: PrintFormat, - _context: &BacktraceContext) -> (usize, usize) +/// Returns a number of frames to remove at the beginning and at the end of the +/// backtrace, according to the backtrace format. +fn filter_frames(frames: &[Frame], + format: PrintFormat, + context: &BacktraceContext) -> (usize, usize) { - (0, 0) + if format == PrintFormat::Full { + return (0, 0); + } + + let skipped_before = 0; + + let skipped_after = frames.len() - frames.iter().position(|frame| { + let mut is_marker = false; + let _ = resolve_symname(*frame, |symname| { + if let Some(mangled_symbol_name) = symname { + // Use grep to find the concerned functions + if mangled_symbol_name.contains("__rust_begin_short_backtrace") { + is_marker = true; + } + } + Ok(()) + }, context); + is_marker + }).unwrap_or(frames.len()); + + if skipped_before + skipped_after >= frames.len() { + // Avoid showing completely empty backtraces + return (0, 0); + } + + (skipped_before, skipped_after) +} + + +/// Fixed frame used to clean the backtrace with `RUST_BACKTRACE=1`. +#[inline(never)] +pub fn __rust_begin_short_backtrace<F, T>(f: F) -> T + where F: FnOnce() -> T, F: Send + 'static, T: Send + 'static +{ + f() } /// Controls how the backtrace should be formated. |
