Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions tests/ui/backtrace/auxiliary/line-tables-only-helper.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
//@ compile-flags: -Cstrip=none -Cdebuginfo=line-tables-only

#[no_mangle]
pub fn baz<F>(mut cb: F, data: u32) where F: FnMut(u32) {
pub fn backtrace_with_baz_in_it<F>(mut cb: F, data: u32) where F: FnMut(u32) {
cb(data);
}

#[no_mangle]
pub fn bar<F>(cb: F, data: u32) where F: FnMut(u32) {
baz(cb, data);
pub fn backtrace_with_bar_in_it<F>(cb: F, data: u32) where F: FnMut(u32) {
backtrace_with_baz_in_it(cb, data);
}

#[no_mangle]
pub fn foo<F>(cb: F, data: u32) where F: FnMut(u32) {
bar(cb, data);
pub fn backtrace_with_foo_in_it<F>(cb: F, data: u32) where F: FnMut(u32) {
backtrace_with_bar_in_it(cb, data);
}

pub fn capture_backtrace() -> std::backtrace::Backtrace {
let mut bt = None;
foo(|_| bt = Some(std::backtrace::Backtrace::capture()), 42);
backtrace_with_foo_in_it(|_| bt = Some(std::backtrace::Backtrace::capture()), 42);
bt.unwrap()
}
37 changes: 26 additions & 11 deletions tests/ui/backtrace/line-tables-only.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
//@ ignore-visionos needs the `.dSYM` files to be moved to the device
//@ needs-unwind
//@ aux-build: line-tables-only-helper.rs

//@ edition: 2021
#![feature(backtrace_frames)]

extern crate line_tables_only_helper;

Expand All @@ -30,13 +31,27 @@ fn assert_contains(
expected_file: &str,
expected_line: u32,
) {
// FIXME(jieyouxu): fix this ugly fragile test when `BacktraceFrame` has accessors like...
// `symbols()`.
let backtrace = format!("{:#?}", backtrace);
eprintln!("{}", backtrace);
assert!(backtrace.contains(expected_name), "backtrace does not contain expected name {}", expected_name);
assert!(backtrace.contains(expected_file), "backtrace does not contain expected file {}", expected_file);
assert!(backtrace.contains(&expected_line.to_string()), "backtrace does not contain expected line {}", expected_line);
// The formatted frames look like this:
// `{ fn: "backtrace_with_baz_in_it", file: ".../tests/ui/backtrace/auxiliary/line-tables-only-helper.rs", line: 5 }`
// or this:
// `{ 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 },`
// Make sure we match the right part when searching for the function name and line number.
let expected_line_str = format!("line: {expected_line} ");
eprintln!("{:#?}", backtrace);
for frame in backtrace.frames() {
// FIXME: we use string matching. Replace this by getting the actual data out of the frame,
// once that is possible.
let frame = format!("{:#?}", frame);
if frame.contains(expected_name)
&& frame.contains(expected_file)
&& frame.contains(&expected_line_str)
{
return;
}
}
panic!(
"backtrace does not contain expected frame with name={expected_name}, file={expected_file}, line={expected_line}"
);
}

fn main() {
Expand All @@ -48,8 +63,8 @@ fn main() {
// And with #143208 we also lost `bar` in the line tables.
#[cfg(not(all(target_pointer_width = "32", target_env = "msvc")))]
{
assert_contains(&backtrace, "foo", "line-tables-only-helper.rs", 5);
assert_contains(&backtrace, "bar", "line-tables-only-helper.rs", 10);
assert_contains(&backtrace, "backtrace_with_foo_in_it", "line-tables-only-helper.rs", 15);
assert_contains(&backtrace, "backtrace_with_bar_in_it", "line-tables-only-helper.rs", 10);
}
assert_contains(&backtrace, "baz", "line-tables-only-helper.rs", 5);
assert_contains(&backtrace, "backtrace_with_baz_in_it", "line-tables-only-helper.rs", 5);
}
Loading