-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #108938 - chenyukang:yukang/fix-107910-shorten-ice, r=c…
…jgillot Shorten backtraces for queries in ICEs r? `@jyn514` Fixes #107910
- Loading branch information
Showing
10 changed files
with
259 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
include ../tools.mk | ||
|
||
# ignore-windows | ||
|
||
export RUSTC := $(RUSTC_ORIGINAL) | ||
export TMPDIR := $(TMPDIR) | ||
|
||
all: | ||
bash check.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/bin/sh | ||
|
||
RUST_BACKTRACE=1 $RUSTC src/lib.rs -Z treat-err-as-bug=1 1>$TMPDIR/rust-test-1.log 2>&1 | ||
RUST_BACKTRACE=full $RUSTC src/lib.rs -Z treat-err-as-bug=1 1>$TMPDIR/rust-test-2.log 2>&1 | ||
|
||
short=$(cat $TMPDIR/rust-test-1.log | wc -l) | ||
full=$(cat $TMPDIR/rust-test-2.log | wc -l) | ||
rustc_query_count=$(cat $TMPDIR/rust-test-1.log | grep rustc_query_ | wc -l) | ||
rustc_query_count_full=$(cat $TMPDIR/rust-test-2.log | grep rustc_query_ | wc -l) | ||
|
||
begin_count=$(cat $TMPDIR/rust-test-2.log | grep __rust_begin_short_backtrace | wc -l) | ||
end_count=$(cat $TMPDIR/rust-test-2.log | grep __rust_end_short_backtrace | wc -l) | ||
|
||
cat $TMPDIR/rust-test-1.log | ||
echo "=====================" | ||
cat $TMPDIR/rust-test-2.log | ||
echo "=====================" | ||
|
||
echo "short backtrace: $short" | ||
echo "full backtrace: $full" | ||
echo "begin_count: $begin_count" | ||
echo "end_count : $end_count" | ||
echo "rustc_query_count: $rustc_query_count" | ||
echo "rustc_query_count_full: $rustc_query_count_full" | ||
|
||
## backtraces to vary a bit depending on platform and configuration options, | ||
## here we make sure that the short backtrace of rustc_query is shorter than the full, | ||
## and marks are in pairs. | ||
if [ $short -lt $full ] && | ||
[ $begin_count -eq $end_count ] && | ||
[ $(($rustc_query_count + 10)) -lt $rustc_query_count_full ] && | ||
[ $rustc_query_count_full -gt 10 ]; then | ||
exit 0 | ||
else | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
fn func(s: &str) { | ||
println!("{}", s); | ||
} | ||
|
||
fn main() { | ||
func(1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// compile-flags:-Cstrip=none | ||
// run-fail | ||
// check-run-results | ||
// exec-env:RUST_BACKTRACE=1 | ||
// ignore-android FIXME #17520 | ||
// ignore-wasm no panic support | ||
// ignore-openbsd no support for libbacktrace without filename | ||
// ignore-emscripten no panic | ||
// ignore-sgx Backtraces not symbolized | ||
// ignore-fuchsia Backtraces not symbolized | ||
// ignore-msvc the `__rust_{begin,end}_short_backtrace` symbols aren't reliable. | ||
|
||
/// This test case make sure that we can have multiple pairs of `__rust_{begin,end}_short_backtrace` | ||
#[inline(never)] | ||
fn __rust_begin_short_backtrace<T, F: FnOnce() -> T>(f: F) -> T { | ||
let result = f(); | ||
std::hint::black_box(result) | ||
} | ||
|
||
#[inline(never)] | ||
fn __rust_end_short_backtrace<T, F: FnOnce() -> T>(f: F) -> T { | ||
let result = f(); | ||
std::hint::black_box(result) | ||
} | ||
|
||
fn first() { | ||
__rust_end_short_backtrace(|| second()); | ||
} | ||
|
||
fn second() { | ||
third(); // won't show up | ||
} | ||
|
||
fn third() { | ||
fourth(); // won't show up | ||
} | ||
|
||
fn fourth() { | ||
__rust_begin_short_backtrace(|| fifth()); | ||
} | ||
|
||
fn fifth() { | ||
__rust_end_short_backtrace(|| sixth()); | ||
} | ||
|
||
fn sixth() { | ||
seven(); // won't show up | ||
} | ||
|
||
fn seven() { | ||
__rust_begin_short_backtrace(|| eight()); | ||
} | ||
|
||
fn eight() { | ||
panic!("debug!!!"); | ||
} | ||
|
||
fn main() { | ||
first(); | ||
} |
11 changes: 11 additions & 0 deletions
11
tests/ui/panics/short-ice-remove-middle-frames-2.run.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
thread 'main' panicked at 'debug!!!', $DIR/short-ice-remove-middle-frames-2.rs:56:5 | ||
stack backtrace: | ||
0: std::panicking::begin_panic | ||
1: short_ice_remove_middle_frames_2::eight | ||
2: short_ice_remove_middle_frames_2::seven::{{closure}} | ||
3: short_ice_remove_middle_frames_2::fifth | ||
4: short_ice_remove_middle_frames_2::fourth::{{closure}} | ||
5: short_ice_remove_middle_frames_2::first | ||
6: short_ice_remove_middle_frames_2::main | ||
7: core::ops::function::FnOnce::call_once | ||
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// compile-flags:-Cstrip=none | ||
// run-fail | ||
// check-run-results | ||
// exec-env:RUST_BACKTRACE=1 | ||
// ignore-android FIXME #17520 | ||
// ignore-wasm no panic support | ||
// ignore-openbsd no support for libbacktrace without filename | ||
// ignore-emscripten no panic | ||
// ignore-sgx Backtraces not symbolized | ||
// ignore-fuchsia Backtraces not symbolized | ||
// ignore-msvc the `__rust_{begin,end}_short_backtrace` symbols aren't reliable. | ||
|
||
|
||
#[inline(never)] | ||
fn __rust_begin_short_backtrace<T, F: FnOnce() -> T>(f: F) -> T { | ||
let result = f(); | ||
std::hint::black_box(result) | ||
} | ||
|
||
#[inline(never)] | ||
fn __rust_end_short_backtrace<T, F: FnOnce() -> T>(f: F) -> T { | ||
let result = f(); | ||
std::hint::black_box(result) | ||
} | ||
|
||
fn first() { | ||
__rust_end_short_backtrace(|| second()); | ||
// do not take effect since we already has a inner call of __rust_end_short_backtrace | ||
} | ||
|
||
fn second() { | ||
__rust_end_short_backtrace(|| third()); | ||
} | ||
|
||
fn third() { | ||
fourth(); // won't show up in backtrace | ||
} | ||
|
||
fn fourth() { | ||
fifth(); // won't show up in backtrace | ||
} | ||
|
||
fn fifth() { | ||
__rust_begin_short_backtrace(|| sixth()); | ||
} | ||
|
||
fn sixth() { | ||
seven(); | ||
} | ||
|
||
fn seven() { | ||
panic!("debug!!!"); | ||
} | ||
|
||
fn main() { | ||
first(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
thread 'main' panicked at 'debug!!!', $DIR/short-ice-remove-middle-frames.rs:52:5 | ||
stack backtrace: | ||
0: std::panicking::begin_panic | ||
1: short_ice_remove_middle_frames::seven | ||
2: short_ice_remove_middle_frames::sixth | ||
3: short_ice_remove_middle_frames::fifth::{{closure}} | ||
4: short_ice_remove_middle_frames::second | ||
5: short_ice_remove_middle_frames::first::{{closure}} | ||
6: short_ice_remove_middle_frames::first | ||
7: short_ice_remove_middle_frames::main | ||
8: core::ops::function::FnOnce::call_once | ||
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. |