Skip to content

Commit 985fdf7

Browse files
committed
Auto merge of #112843 - chenyukang:yukang-more-on-backtrace, r=workingjubilee
Print omitted frames count for short backtrace mode Fixes #111730
2 parents d5d081c + 454ab9f commit 985fdf7

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

std/src/sys_common/backtrace.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ unsafe fn _print_fmt(fmt: &mut fmt::Formatter<'_>, print_fmt: PrintFmt) -> fmt::
6060
bt_fmt.add_context()?;
6161
let mut idx = 0;
6262
let mut res = Ok(());
63+
let mut omitted_count: usize = 0;
64+
let mut first_omit = true;
6365
// Start immediately if we're not using a short backtrace.
6466
let mut start = print_fmt != PrintFmt::Short;
6567
backtrace_rs::trace_unsynchronized(|frame| {
@@ -85,10 +87,27 @@ unsafe fn _print_fmt(fmt: &mut fmt::Formatter<'_>, print_fmt: PrintFmt) -> fmt::
8587
start = true;
8688
return;
8789
}
90+
if !start {
91+
omitted_count += 1;
92+
}
8893
}
8994
}
9095

9196
if start {
97+
if omitted_count > 0 {
98+
debug_assert!(print_fmt == PrintFmt::Short);
99+
// only print the message between the middle of frames
100+
if !first_omit {
101+
let _ = writeln!(
102+
bt_fmt.formatter(),
103+
" [... omitted {} frame{} ...]",
104+
omitted_count,
105+
if omitted_count > 1 { "s" } else { "" }
106+
);
107+
}
108+
first_omit = false;
109+
omitted_count = 0;
110+
}
92111
res = bt_fmt.frame().symbol(frame, symbol);
93112
}
94113
});

0 commit comments

Comments
 (0)