From 809ef2424d0786c9fa50aa3819a448bb1689182c Mon Sep 17 00:00:00 2001 From: yukang Date: Mon, 22 May 2023 02:27:01 +0800 Subject: [PATCH] print omitted frames count for short backtrace mode --- library/std/src/sys_common/backtrace.rs | 19 +++++++++++++++++++ src/tools/build-manifest/Cargo.toml | 2 +- .../const-eval/const-eval-query-stack.rs | 2 +- ...hort-ice-remove-middle-frames-2.run.stderr | 2 ++ .../short-ice-remove-middle-frames.run.stderr | 1 + 5 files changed, 24 insertions(+), 2 deletions(-) diff --git a/library/std/src/sys_common/backtrace.rs b/library/std/src/sys_common/backtrace.rs index 6f020940df12f..84e2c5d8d7f70 100644 --- a/library/std/src/sys_common/backtrace.rs +++ b/library/std/src/sys_common/backtrace.rs @@ -60,6 +60,8 @@ unsafe fn _print_fmt(fmt: &mut fmt::Formatter<'_>, print_fmt: PrintFmt) -> fmt:: bt_fmt.add_context()?; let mut idx = 0; let mut res = Ok(()); + let mut omitted_count: usize = 0; + let mut first_omit = true; // Start immediately if we're not using a short backtrace. let mut start = print_fmt != PrintFmt::Short; backtrace_rs::trace_unsynchronized(|frame| { @@ -85,10 +87,27 @@ unsafe fn _print_fmt(fmt: &mut fmt::Formatter<'_>, print_fmt: PrintFmt) -> fmt:: start = true; return; } + if !start { + omitted_count += 1; + } } } if start { + if omitted_count > 0 { + debug_assert!(print_fmt == PrintFmt::Short); + // only print the message between the middle of frames + if !first_omit { + let _ = writeln!( + bt_fmt.formatter(), + " [... omitted {} frame{} ...]", + omitted_count, + if omitted_count > 1 { "s" } else { "" } + ); + } + first_omit = false; + omitted_count = 0; + } res = bt_fmt.frame().symbol(frame, symbol); } }); diff --git a/src/tools/build-manifest/Cargo.toml b/src/tools/build-manifest/Cargo.toml index 6c3b5bb00a347..7e0c4bee2b3cc 100644 --- a/src/tools/build-manifest/Cargo.toml +++ b/src/tools/build-manifest/Cargo.toml @@ -8,7 +8,7 @@ toml = "0.5" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" anyhow = "1.0.32" -flate2 = "1.0.16" +flate2 = "1.0.26" xz2 = "0.1.7" tar = "0.4.29" sha2 = "0.10.1" diff --git a/tests/ui/consts/const-eval/const-eval-query-stack.rs b/tests/ui/consts/const-eval/const-eval-query-stack.rs index 81f28c1755deb..6f6bc4c643eb3 100644 --- a/tests/ui/consts/const-eval/const-eval-query-stack.rs +++ b/tests/ui/consts/const-eval/const-eval-query-stack.rs @@ -10,7 +10,7 @@ // normalize-stderr-test "\s\d{1,}: .*\n" -> "" // normalize-stderr-test "\s at .*\n" -> "" // normalize-stderr-test ".*note: Some details.*\n" -> "" - +// normalize-stderr-test ".*omitted \d{1,} frames.*\n" -> "" #![allow(unconditional_panic)] const X: i32 = 1 / 0; //~ERROR constant diff --git a/tests/ui/panics/short-ice-remove-middle-frames-2.run.stderr b/tests/ui/panics/short-ice-remove-middle-frames-2.run.stderr index 2592b7479186a..7263c03bab3ee 100644 --- a/tests/ui/panics/short-ice-remove-middle-frames-2.run.stderr +++ b/tests/ui/panics/short-ice-remove-middle-frames-2.run.stderr @@ -3,8 +3,10 @@ stack backtrace: 0: std::panicking::begin_panic 1: short_ice_remove_middle_frames_2::eight 2: short_ice_remove_middle_frames_2::seven::{{closure}} + [... omitted 3 frames ...] 3: short_ice_remove_middle_frames_2::fifth 4: short_ice_remove_middle_frames_2::fourth::{{closure}} + [... omitted 4 frames ...] 5: short_ice_remove_middle_frames_2::first 6: short_ice_remove_middle_frames_2::main 7: core::ops::function::FnOnce::call_once diff --git a/tests/ui/panics/short-ice-remove-middle-frames.run.stderr b/tests/ui/panics/short-ice-remove-middle-frames.run.stderr index 9c15f2e08feed..a221668066064 100644 --- a/tests/ui/panics/short-ice-remove-middle-frames.run.stderr +++ b/tests/ui/panics/short-ice-remove-middle-frames.run.stderr @@ -4,6 +4,7 @@ stack backtrace: 1: short_ice_remove_middle_frames::seven 2: short_ice_remove_middle_frames::sixth 3: short_ice_remove_middle_frames::fifth::{{closure}} + [... omitted 4 frames ...] 4: short_ice_remove_middle_frames::second 5: short_ice_remove_middle_frames::first::{{closure}} 6: short_ice_remove_middle_frames::first