Skip to content
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

std: Back out backtrace pruning logic #41364

Merged
merged 1 commit into from
Apr 18, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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