2020-10-31 07:47:42 -05:00
|
|
|
// normalize-stderr-test ".*/(rust[^/]*|checkout)/library/" -> "RUSTLIB/"
|
2020-09-22 09:58:18 -05:00
|
|
|
// normalize-stderr-test "RUSTLIB/(.*):\d+:\d+ "-> "RUSTLIB/$1:LL:COL "
|
2020-09-28 12:55:23 -05:00
|
|
|
// normalize-stderr-test "::<.*>" -> ""
|
2019-12-02 20:15:58 -06:00
|
|
|
|
2020-09-24 22:00:32 -05:00
|
|
|
#[inline(never)] fn func_a() -> Box<[*mut ()]> { func_b::<u8>() }
|
|
|
|
#[inline(never)] fn func_b<T>() -> Box<[*mut ()]> { func_c() }
|
2020-10-05 16:29:55 -05:00
|
|
|
|
|
|
|
macro_rules! invoke_func_d {
|
|
|
|
() => { func_d() }
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline(never)] fn func_c() -> Box<[*mut ()]> { invoke_func_d!() }
|
2022-02-25 00:11:20 -06:00
|
|
|
#[inline(never)] fn func_d() -> Box<[*mut ()]> { unsafe { let count = miri_backtrace_size(0); let mut buf = vec![std::ptr::null_mut(); count]; miri_get_backtrace(1, buf.as_mut_ptr()); buf.into() } }
|
2020-09-24 14:05:50 -05:00
|
|
|
|
2019-12-02 20:15:58 -06:00
|
|
|
fn main() {
|
2020-09-24 14:05:50 -05:00
|
|
|
let mut seen_main = false;
|
|
|
|
let frames = func_a();
|
2019-12-02 20:15:58 -06:00
|
|
|
for frame in frames.into_iter() {
|
2022-02-25 00:11:20 -06:00
|
|
|
let miri_frame = unsafe { miri_resolve_frame(*frame, 1) };
|
|
|
|
|
|
|
|
let mut name = vec![0; miri_frame.name_len];
|
|
|
|
let mut filename = vec![0; miri_frame.filename_len];
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
miri_resolve_frame_names(*frame, 0, name.as_mut_ptr(), filename.as_mut_ptr());
|
|
|
|
}
|
|
|
|
|
|
|
|
let name = String::from_utf8(name).unwrap();
|
|
|
|
let filename = String::from_utf8(filename).unwrap();
|
2020-09-24 14:05:50 -05:00
|
|
|
|
2020-10-10 12:07:57 -05:00
|
|
|
if name == "func_a" {
|
|
|
|
assert_eq!(func_a as *mut (), miri_frame.fn_ptr);
|
|
|
|
}
|
|
|
|
|
2020-09-24 14:05:50 -05:00
|
|
|
// Print every frame to stderr.
|
|
|
|
let out = format!("{}:{}:{} ({})", filename, miri_frame.lineno, miri_frame.colno, name);
|
|
|
|
eprintln!("{}", out);
|
|
|
|
// Print the 'main' frame (and everything before it) to stdout, skipping
|
|
|
|
// the printing of internal (and possibly fragile) libstd frames.
|
|
|
|
if !seen_main {
|
|
|
|
println!("{}", out);
|
|
|
|
seen_main = name == "main";
|
|
|
|
}
|
2019-12-02 20:15:58 -06:00
|
|
|
}
|
|
|
|
}
|
2020-10-10 12:07:57 -05:00
|
|
|
|
|
|
|
// This goes at the bottom of the file so that we can change it
|
|
|
|
// without disturbing line numbers of the functions in the backtrace.
|
|
|
|
|
|
|
|
extern "Rust" {
|
2022-02-25 00:11:20 -06:00
|
|
|
fn miri_backtrace_size(flags: u64) -> usize;
|
|
|
|
fn miri_get_backtrace(flags: u64, buf: *mut *mut ());
|
2020-10-10 12:07:57 -05:00
|
|
|
fn miri_resolve_frame(ptr: *mut (), flags: u64) -> MiriFrame;
|
2022-02-25 00:11:20 -06:00
|
|
|
fn miri_resolve_frame_names(ptr: *mut (), flags: u64, name_buf: *mut u8, filename_buf: *mut u8);
|
2020-10-10 12:07:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
#[repr(C)]
|
|
|
|
struct MiriFrame {
|
2022-02-25 00:11:20 -06:00
|
|
|
name_len: usize,
|
|
|
|
filename_len: usize,
|
2020-10-10 12:07:57 -05:00
|
|
|
lineno: u32,
|
|
|
|
colno: u32,
|
|
|
|
fn_ptr: *mut (),
|
2022-02-25 00:11:20 -06:00
|
|
|
}
|