From e46a8bde3c2ef7b1281f3d01e31febc687be2d12 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 20 Mar 2017 14:13:27 -0700 Subject: [PATCH] std: Back out backtrace pruning logic It was discovered #40264 that this backtrace pruning logic is a little too aggressive, so while we figure how out to handle #40264 this commit backs out the changes to prune frames. Note that other cosmetic changes, such as better path printing and such remain. --- src/libstd/sys_common/backtrace.rs | 84 ++---------------------------- 1 file changed, 4 insertions(+), 80 deletions(-) diff --git a/src/libstd/sys_common/backtrace.rs b/src/libstd/sys_common/backtrace.rs index f5c188f7a7537..04fe5f78b03ce 100644 --- a/src/libstd/sys_common/backtrace.rs +++ b/src/libstd/sys_common/backtrace.rs @@ -93,87 +93,11 @@ fn _print(w: &mut Write, format: PrintFormat) -> io::Result<()> { Ok(()) } -fn filter_frames(frames: &[Frame], - format: PrintFormat, - context: &BacktraceContext) -> (usize, usize) +fn filter_frames(_frames: &[Frame], + _format: PrintFormat, + _context: &BacktraceContext) -> (usize, usize) { - if format == PrintFormat::Full { - return (0, 0); - } - - // We want to filter out frames with some prefixes - // from both top and bottom of the call stack. - static BAD_PREFIXES_TOP: &'static [&'static str] = &[ - "_ZN3std3sys3imp9backtrace", - "ZN3std3sys3imp9backtrace", - "std::sys::imp::backtrace", - "_ZN3std10sys_common9backtrace", - "ZN3std10sys_common9backtrace", - "std::sys_common::backtrace", - "_ZN3std9panicking", - "ZN3std9panicking", - "std::panicking", - "_ZN4core9panicking", - "ZN4core9panicking", - "core::panicking", - "_ZN4core6result13unwrap_failed", - "ZN4core6result13unwrap_failed", - "core::result::unwrap_failed", - "rust_begin_unwind", - "_ZN4drop", - "mingw_set_invalid_parameter_handler", - ]; - static BAD_PREFIXES_BOTTOM: &'static [&'static str] = &[ - "_ZN3std9panicking", - "ZN3std9panicking", - "std::panicking", - "_ZN3std5panic", - "ZN3std5panic", - "std::panic", - "_ZN4core9panicking", - "ZN4core9panicking", - "core::panicking", - "_ZN3std2rt10lang_start", - "ZN3std2rt10lang_start", - "std::rt::lang_start", - "panic_unwind::__rust_maybe_catch_panic", - "__rust_maybe_catch_panic", - "_rust_maybe_catch_panic", - "__libc_start_main", - "__rust_try", - "_start", - "main", - "BaseThreadInitThunk", - "RtlInitializeExceptionChain", - "__scrt_common_main_seh", - "_ZN4drop", - "mingw_set_invalid_parameter_handler", - ]; - - let is_good_frame = |frame: Frame, bad_prefixes: &[&str]| { - resolve_symname(frame, |symname| { - if let Some(mangled_symbol_name) = symname { - if !bad_prefixes.iter().any(|s| mangled_symbol_name.starts_with(s)) { - return Ok(()) - } - } - Err(io::Error::from(io::ErrorKind::Other)) - }, context).is_ok() - }; - - let skipped_before = frames.iter().position(|frame| { - is_good_frame(*frame, BAD_PREFIXES_TOP) - }).unwrap_or(frames.len()); - let skipped_after = frames[skipped_before..].iter().rev().position(|frame| { - is_good_frame(*frame, BAD_PREFIXES_BOTTOM) - }).unwrap_or(frames.len() - skipped_before); - - if skipped_before + skipped_after == frames.len() { - // Avoid showing completely empty backtraces - return (0, 0); - } - - (skipped_before, skipped_after) + (0, 0) } /// Controls how the backtrace should be formated.