Skip to content

Commit 14c4dda

Browse files
committed
test backtraces
1 parent b107f5f commit 14c4dda

5 files changed

Lines changed: 72 additions & 1 deletion

File tree

compiler/rustc_codegen_llvm/src/mono_item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
125125
/// This is not a problem: instead of using LLVM aliases, we can just generate
126126
/// a new function symbol (with target architecture!) which effectively comes down to:
127127
///
128-
/// ```rust,ignore
128+
/// ```ignore (illustrative example)
129129
/// fn alias_name(...args) {
130130
/// original_name(...args)
131131
/// }
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//@ no-prefer-dynamic
2+
//@ needs-unwind
3+
//@ exec-env:RUST_BACKTRACE=1
4+
#![crate_type = "rlib"]
5+
#![feature(extern_item_impls)]
6+
7+
#[eii(eii1)]
8+
pub fn decl1(x: u64) {
9+
// Print a backtrace here, to verify that the shim function is
10+
// effectively skipped in the backtrace:
11+
// it doesn't really exist, it's just part of our workaround for function aliases.
12+
println!("{:#?}", std::backtrace::Backtrace::capture());
13+
14+
panic!("{}", x);
15+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//@ no-prefer-dynamic
2+
//@ aux-build: decl_with_default_panics.rs
3+
//@ edition: 2021
4+
//@ run-pass
5+
//@ check-run-results
6+
//@ needs-unwind
7+
//@ exec-env:RUST_BACKTRACE=1
8+
//@ ignore-backends: gcc
9+
// FIXME: linking on windows (speciifcally mingw) not yet supported, see tracking issue #125418
10+
//@ ignore-windows
11+
// A small test to make sure that unwinding works properly.
12+
//
13+
// Functions can have target-cpu applied. On apple-darwin this is super important,
14+
// since you can have binaries which mix x86 and aarch64 code that are compatible
15+
// with both architectures. So we can't just reject target_cpu on EIIs since apple
16+
// puts them on by default. The problem: we generate aliases. And aliases cannot
17+
// get target_cpu applied to them. So, instead we should, in the case of functions,
18+
// generate a shim function. For statics aliases should keep working.
19+
// However, to make this work properly,
20+
// on LLVM we generate shim functions instead of function aliases.
21+
// Little extra functions that look like
22+
// ```
23+
// function alias_symbol(*args) {return (tailcall) aliasee(*args);}
24+
// ```
25+
// This is a simple test to make sure that we can unwind through these,
26+
// and that this wrapper function effectively doesn't show up in the trace.
27+
#![feature(extern_item_impls)]
28+
29+
extern crate decl_with_default_panics;
30+
31+
fn main() {
32+
let result = std::panic::catch_unwind(|| {
33+
decl_with_default_panics::decl1(10);
34+
});
35+
assert!(result.is_err());
36+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
thread 'main' ($TID) panicked at $DIR/auxiliary/decl_with_default_panics.rs:14:5:
3+
10
4+
stack backtrace:
5+
0: __rustc::rust_begin_unwind
6+
1: core::panicking::panic_fmt
7+
2: core::panicking::panic_display::<u64>
8+
3: decl_with_default_panics::_::dflt::decl1
9+
4: call_default_panics::main
10+
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Backtrace [
2+
{ fn: "decl_with_default_panics::_::dflt::decl1" },
3+
{ fn: "call_default_panics::main" },
4+
{ fn: "std::sys::backtrace::__rust_begin_short_backtrace::<fn(), ()>" },
5+
{ fn: "std::rt::lang_start::<()>::{closure#0}" },
6+
{ fn: "std::rt::lang_start_internal" },
7+
{ fn: "main" },
8+
{ fn: "__libc_start_main" },
9+
{ fn: "_start" },
10+
]

0 commit comments

Comments
 (0)