2020-09-30 02:59:28 -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
|
|
|
|
|
|
|
extern "Rust" {
|
2020-09-24 17:52:17 -05:00
|
|
|
fn miri_get_backtrace(flags: u64) -> Box<[*mut ()]>;
|
2020-09-24 13:18:47 -05:00
|
|
|
fn miri_resolve_frame(ptr: *mut (), flags: u64) -> MiriFrame;
|
2019-12-02 20:15:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
2020-09-26 13:40:41 -05:00
|
|
|
#[repr(C)]
|
2019-12-02 20:15:58 -06:00
|
|
|
struct MiriFrame {
|
|
|
|
name: Box<[u8]>,
|
|
|
|
filename: Box<[u8]>,
|
|
|
|
lineno: u32,
|
|
|
|
colno: u32
|
|
|
|
}
|
|
|
|
|
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!() }
|
|
|
|
#[inline(never)] fn func_d() -> Box<[*mut ()]> { unsafe { miri_get_backtrace(0) } }
|
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() {
|
2020-09-24 13:18:47 -05:00
|
|
|
let miri_frame = unsafe { miri_resolve_frame(*frame, 0) };
|
2019-12-02 20:15:58 -06:00
|
|
|
let name = String::from_utf8(miri_frame.name.into()).unwrap();
|
|
|
|
let filename = String::from_utf8(miri_frame.filename.into()).unwrap();
|
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
|
|
|
}
|
|
|
|
}
|