Skip to content

Commit 93c131e

Browse files
committed
Auto merge of #122918 - jieyouxu:port-backtrace-line-tables-only, r=workingjubilee
Port backtrace's `line-tables-only` test over to rustc Part of #122899.
2 parents 8b2459c + d4aeff7 commit 93c131e

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//@ compile-flags: -Cstrip=none -Cdebuginfo=line-tables-only
2+
3+
#[no_mangle]
4+
pub fn baz<F>(mut cb: F, data: u32) where F: FnMut(u32) {
5+
cb(data);
6+
}
7+
8+
#[no_mangle]
9+
pub fn bar<F>(cb: F, data: u32) where F: FnMut(u32) {
10+
baz(cb, data);
11+
}
12+
13+
#[no_mangle]
14+
pub fn foo<F>(cb: F, data: u32) where F: FnMut(u32) {
15+
bar(cb, data);
16+
}
17+
18+
pub fn capture_backtrace() -> std::backtrace::Backtrace {
19+
let mut bt = None;
20+
foo(|_| bt = Some(std::backtrace::Backtrace::capture()), 42);
21+
bt.unwrap()
22+
}

Diff for: tests/ui/debuginfo/backtrace-line-tables-only.rs

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Test that when debug info only includes line tables that backtrace is still generated
2+
// successfully.
3+
// Original test:
4+
// <https://github.com/rust-lang/backtrace-rs/tree/6fa4b85b9962c3e1be8c2e5cc605cd078134152b/crates/line-tables-only>.
5+
// Part of <https://github.com/rust-lang/rust/issues/122899> porting some backtrace tests to rustc.
6+
// This test diverges from the original test in that it now uses a Rust library auxiliary because
7+
// rustc now has `-Cdebuginfo=line-tables-only`.
8+
// ignore-tidy-linelength
9+
//@ run-pass
10+
//@ compile-flags: -Cstrip=none -Cdebuginfo=line-tables-only
11+
//@ ignore-android FIXME #17520
12+
//@ ignore-fuchsia Backtraces not symbolized
13+
//@ needs-unwind
14+
//@ aux-build: line-tables-only-helper.rs
15+
16+
#![feature(backtrace_frames)]
17+
18+
extern crate line_tables_only_helper;
19+
20+
use std::backtrace::Backtrace;
21+
22+
fn assert_contains(
23+
backtrace: &Backtrace,
24+
expected_name: &str,
25+
expected_file: &str,
26+
expected_line: u32,
27+
) {
28+
// FIXME(jieyouxu): fix this ugly fragile test when `BacktraceFrame` has accessors like...
29+
// `symbols()`.
30+
let backtrace = format!("{:#?}", backtrace);
31+
eprintln!("{}", backtrace);
32+
assert!(backtrace.contains(expected_name), "backtrace does not contain expected name {}", expected_name);
33+
assert!(backtrace.contains(expected_file), "backtrace does not contain expected file {}", expected_file);
34+
assert!(backtrace.contains(&expected_line.to_string()), "backtrace does not contain expected line {}", expected_line);
35+
}
36+
37+
fn main() {
38+
std::env::set_var("RUST_BACKTRACE", "1");
39+
let backtrace = line_tables_only_helper::capture_backtrace();
40+
41+
// FIXME(jieyouxu): for some forsaken reason on i686-msvc `foo` doesn't have an entry in the
42+
// line tables?
43+
#[cfg(not(all(target_pointer_width = "32", target_env = "msvc")))]
44+
{
45+
assert_contains(&backtrace, "foo", "line-tables-only-helper.rs", 5);
46+
}
47+
assert_contains(&backtrace, "bar", "line-tables-only-helper.rs", 10);
48+
assert_contains(&backtrace, "baz", "line-tables-only-helper.rs", 15);
49+
}

0 commit comments

Comments
 (0)