2019-12-02 20:15:58 -06:00
|
|
|
// normalize-stderr-test ".*rustlib" -> "RUSTLIB"
|
2020-09-22 09:58:18 -05:00
|
|
|
// normalize-stderr-test "RUSTLIB/(.*):\d+:\d+ "-> "RUSTLIB/$1:LL:COL "
|
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)]
|
|
|
|
struct MiriFrame {
|
|
|
|
name: Box<[u8]>,
|
|
|
|
filename: Box<[u8]>,
|
|
|
|
lineno: u32,
|
|
|
|
colno: u32
|
|
|
|
}
|
|
|
|
|
2020-09-24 14:05:50 -05:00
|
|
|
fn func_a() -> Box<[*mut ()]> { func_b::<u8>() }
|
|
|
|
fn func_b<T>() -> Box<[*mut ()]> { func_c() }
|
2020-09-24 17:52:17 -05:00
|
|
|
fn func_c() -> 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
|
|
|
}
|
|
|
|
}
|