Skip to content

Commit

Permalink
Rollup merge of rust-lang#41364 - alexcrichton:less-backtrace-prune, …
Browse files Browse the repository at this point in the history
…r=petrochenkov

std: Back out backtrace pruning logic

It was discovered rust-lang#40264 that this backtrace pruning logic is a little too
aggressive, so while we figure how out to handle rust-lang#40264 this commit backs out
the changes to prune frames. Note that other cosmetic changes, such as better
path printing and such remain.
  • Loading branch information
frewsxcv authored Apr 18, 2017
2 parents f448cdf + e46a8bd commit 20718c8
Showing 1 changed file with 4 additions and 80 deletions.
84 changes: 4 additions & 80 deletions src/libstd/sys_common/backtrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 20718c8

Please sign in to comment.