Skip to content

Commit 46a5fd2

Browse files
authored
Unrolled build for #159837
Rollup merge of #159837 - RalfJung:line-tables-only, r=jieyouxu line-tables-only test: check that the line number matches the function name r? @jieyouxu
2 parents dc3f851 + c9ef902 commit 46a5fd2

2 files changed

Lines changed: 32 additions & 17 deletions

File tree

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
//@ compile-flags: -Cstrip=none -Cdebuginfo=line-tables-only
22

33
#[no_mangle]
4-
pub fn baz<F>(mut cb: F, data: u32) where F: FnMut(u32) {
4+
pub fn backtrace_with_baz_in_it<F>(mut cb: F, data: u32) where F: FnMut(u32) {
55
cb(data);
66
}
77

88
#[no_mangle]
9-
pub fn bar<F>(cb: F, data: u32) where F: FnMut(u32) {
10-
baz(cb, data);
9+
pub fn backtrace_with_bar_in_it<F>(cb: F, data: u32) where F: FnMut(u32) {
10+
backtrace_with_baz_in_it(cb, data);
1111
}
1212

1313
#[no_mangle]
14-
pub fn foo<F>(cb: F, data: u32) where F: FnMut(u32) {
15-
bar(cb, data);
14+
pub fn backtrace_with_foo_in_it<F>(cb: F, data: u32) where F: FnMut(u32) {
15+
backtrace_with_bar_in_it(cb, data);
1616
}
1717

1818
pub fn capture_backtrace() -> std::backtrace::Backtrace {
1919
let mut bt = None;
20-
foo(|_| bt = Some(std::backtrace::Backtrace::capture()), 42);
20+
backtrace_with_foo_in_it(|_| bt = Some(std::backtrace::Backtrace::capture()), 42);
2121
bt.unwrap()
2222
}

tests/ui/backtrace/line-tables-only.rs

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
//@ ignore-visionos needs the `.dSYM` files to be moved to the device
1919
//@ needs-unwind
2020
//@ aux-build: line-tables-only-helper.rs
21-
21+
//@ edition: 2021
22+
#![feature(backtrace_frames)]
2223

2324
extern crate line_tables_only_helper;
2425

@@ -30,13 +31,27 @@ fn assert_contains(
3031
expected_file: &str,
3132
expected_line: u32,
3233
) {
33-
// FIXME(jieyouxu): fix this ugly fragile test when `BacktraceFrame` has accessors like...
34-
// `symbols()`.
35-
let backtrace = format!("{:#?}", backtrace);
36-
eprintln!("{}", backtrace);
37-
assert!(backtrace.contains(expected_name), "backtrace does not contain expected name {}", expected_name);
38-
assert!(backtrace.contains(expected_file), "backtrace does not contain expected file {}", expected_file);
39-
assert!(backtrace.contains(&expected_line.to_string()), "backtrace does not contain expected line {}", expected_line);
34+
// The formatted frames look like this:
35+
// `{ fn: "backtrace_with_baz_in_it", file: ".../tests/ui/backtrace/auxiliary/line-tables-only-helper.rs", line: 5 }`
36+
// or this:
37+
// `{ fn: "line_tables_only_helper::backtrace_with_baz_in_it<line_tables_only_helper::capture_backtrace::closure_env$0>", file: "...\tests\ui\backtrace\auxiliary\line-tables-only-helper.rs", line: 5 },`
38+
// Make sure we match the right part when searching for the function name and line number.
39+
let expected_line_str = format!("line: {expected_line} ");
40+
eprintln!("{:#?}", backtrace);
41+
for frame in backtrace.frames() {
42+
// FIXME: we use string matching. Replace this by getting the actual data out of the frame,
43+
// once that is possible.
44+
let frame = format!("{:#?}", frame);
45+
if frame.contains(expected_name)
46+
&& frame.contains(expected_file)
47+
&& frame.contains(&expected_line_str)
48+
{
49+
return;
50+
}
51+
}
52+
panic!(
53+
"backtrace does not contain expected frame with name={expected_name}, file={expected_file}, line={expected_line}"
54+
);
4055
}
4156

4257
fn main() {
@@ -48,8 +63,8 @@ fn main() {
4863
// And with #143208 we also lost `bar` in the line tables.
4964
#[cfg(not(all(target_pointer_width = "32", target_env = "msvc")))]
5065
{
51-
assert_contains(&backtrace, "foo", "line-tables-only-helper.rs", 5);
52-
assert_contains(&backtrace, "bar", "line-tables-only-helper.rs", 10);
66+
assert_contains(&backtrace, "backtrace_with_foo_in_it", "line-tables-only-helper.rs", 15);
67+
assert_contains(&backtrace, "backtrace_with_bar_in_it", "line-tables-only-helper.rs", 10);
5368
}
54-
assert_contains(&backtrace, "baz", "line-tables-only-helper.rs", 5);
69+
assert_contains(&backtrace, "backtrace_with_baz_in_it", "line-tables-only-helper.rs", 5);
5570
}

0 commit comments

Comments
 (0)