/// lineno: u32,
/// // The column number currently being executed in `filename`, starting from '1'.
/// colno: u32,
+ /// // The function pointer to the function currently being executed.
+ /// // This can be compared against function pointers obtained by
+ /// // casting a function (e.g. `my_fn as *mut ()`)
+ /// fn_ptr: *mut ()
/// }
/// ```
///
throw_ub_format!("expected function pointer, found {:?}", ptr);
};
- if dest.layout.layout.fields.count() != 4 {
- throw_ub_format!("bad declaration of miri_resolve_frame - should return a struct with 4 fields");
+ // Reconstruct the original function pointer,
+ // which we pass to user code.
+ let mut fn_ptr = ptr;
+ fn_ptr.offset = Size::from_bytes(0);
+ let fn_ptr = Scalar::Ptr(fn_ptr);
+
+ let num_fields = dest.layout.layout.fields.count();
+
+ if num_fields != 4 && num_fields != 5 {
+ // Always mention 5 fields, since the 4-field struct is only supported
+ // for backwards compatiblity. New code should declare 5 fields
+ throw_ub_format!("bad declaration of miri_resolve_frame - should return a struct with 5 fields");
}
let pos = BytePos(ptr.offset.bytes().try_into().unwrap());
this.write_immediate(filename_alloc.to_ref(), this.mplace_field(dest, 1)?.into())?;
this.write_scalar(lineno_alloc, this.mplace_field(dest, 2)?.into())?;
this.write_scalar(colno_alloc, this.mplace_field(dest, 3)?.into())?;
+
+ if num_fields == 5 {
+ this.write_scalar(fn_ptr, this.mplace_field(dest, 4)?.into())?;
+ }
+
Ok(())
}
}
let frames = unsafe { miri_get_backtrace(0) };
for frame in frames.into_iter() {
unsafe {
- miri_resolve_frame(*frame, 0); //~ ERROR Undefined Behavior: bad declaration of miri_resolve_frame - should return a struct with 4 fields
+ miri_resolve_frame(*frame, 0); //~ ERROR Undefined Behavior: bad declaration of miri_resolve_frame - should return a struct with 5 fields
}
}
}
// normalize-stderr-test "RUSTLIB/(.*):\d+:\d+ "-> "RUSTLIB/$1:LL:COL "
// normalize-stderr-test "::<.*>" -> ""
-extern "Rust" {
- fn miri_get_backtrace(flags: u64) -> Box<[*mut ()]>;
- fn miri_resolve_frame(ptr: *mut (), flags: u64) -> MiriFrame;
-}
-
-#[derive(Debug)]
-#[repr(C)]
-struct MiriFrame {
- name: Box<[u8]>,
- filename: Box<[u8]>,
- lineno: u32,
- colno: u32
-}
-
#[inline(never)] fn func_a() -> Box<[*mut ()]> { func_b::<u8>() }
#[inline(never)] fn func_b<T>() -> Box<[*mut ()]> { func_c() }
let name = String::from_utf8(miri_frame.name.into()).unwrap();
let filename = String::from_utf8(miri_frame.filename.into()).unwrap();
+ if name == "func_a" {
+ assert_eq!(func_a as *mut (), miri_frame.fn_ptr);
+ }
+
// Print every frame to stderr.
let out = format!("{}:{}:{} ({})", filename, miri_frame.lineno, miri_frame.colno, name);
eprintln!("{}", out);
}
}
}
+
+// 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" {
+ fn miri_get_backtrace(flags: u64) -> Box<[*mut ()]>;
+ fn miri_resolve_frame(ptr: *mut (), flags: u64) -> MiriFrame;
+}
+
+#[derive(Debug)]
+#[repr(C)]
+struct MiriFrame {
+ name: Box<[u8]>,
+ filename: Box<[u8]>,
+ lineno: u32,
+ colno: u32,
+ fn_ptr: *mut (),
+}
+
-$DIR/backtrace-api.rs:27:59 (func_d)
-$DIR/backtrace-api.rs:26:50 (func_c)
-$DIR/backtrace-api.rs:20:53 (func_b)
-$DIR/backtrace-api.rs:19:50 (func_a)
-$DIR/backtrace-api.rs:31:18 (main)
+$DIR/backtrace-api.rs:13:59 (func_d)
+$DIR/backtrace-api.rs:12:50 (func_c)
+$DIR/backtrace-api.rs:6:53 (func_b)
+$DIR/backtrace-api.rs:5:50 (func_a)
+$DIR/backtrace-api.rs:17:18 (main)
RUSTLIB/core/src/ops/function.rs:LL:COL (<fn() as std::ops::FnOnce<()>>::call_once - shim(fn()))
RUSTLIB/std/src/sys_common/backtrace.rs:LL:COL (std::sys_common::backtrace::__rust_begin_short_backtrace)
RUSTLIB/std/src/rt.rs:LL:COL (std::rt::lang_start::{closure#0})
-$DIR/backtrace-api.rs:27:59 (func_d)
-$DIR/backtrace-api.rs:26:50 (func_c)
-$DIR/backtrace-api.rs:20:53 (func_b::<u8>)
-$DIR/backtrace-api.rs:19:50 (func_a)
-$DIR/backtrace-api.rs:31:18 (main)
+$DIR/backtrace-api.rs:13:59 (func_d)
+$DIR/backtrace-api.rs:12:50 (func_c)
+$DIR/backtrace-api.rs:6:53 (func_b::<u8>)
+$DIR/backtrace-api.rs:5:50 (func_a)
+$DIR/backtrace-api.rs:17:18 (main)