]> git.lizzy.rs Git - rust.git/commitdiff
add new version of backtrace api using flags=1
authorDrMeepster <19316085+DrMeepster@users.noreply.github.com>
Fri, 25 Feb 2022 06:11:20 +0000 (22:11 -0800)
committerDrMeepster <19316085+DrMeepster@users.noreply.github.com>
Sun, 20 Mar 2022 01:14:11 +0000 (18:14 -0700)
17 files changed:
README.md
src/shims/backtrace.rs
src/shims/foreign_items.rs
tests/compile-fail/backtrace/bad-backtrace-flags.rs [new file with mode: 0644]
tests/compile-fail/backtrace/bad-backtrace-resolve-flags.rs [new file with mode: 0644]
tests/compile-fail/backtrace/bad-backtrace-resolve-names-flags.rs [new file with mode: 0644]
tests/compile-fail/backtrace/bad-backtrace-size-flags.rs [new file with mode: 0644]
tests/compile-fail/backtrace/bad-backtrace-version.rs [deleted file]
tests/run-pass/backtrace-api-v0.rs [new file with mode: 0644]
tests/run-pass/backtrace-api-v0.stderr [new file with mode: 0644]
tests/run-pass/backtrace-api-v0.stdout [new file with mode: 0644]
tests/run-pass/backtrace-api-v1.rs [new file with mode: 0644]
tests/run-pass/backtrace-api-v1.stderr [new file with mode: 0644]
tests/run-pass/backtrace-api-v1.stdout [new file with mode: 0644]
tests/run-pass/backtrace-api.rs [deleted file]
tests/run-pass/backtrace-api.stderr [deleted file]
tests/run-pass/backtrace-api.stdout [deleted file]

index fb9a5566990307e81912622ff65b66ef67e220d9..086ed1b0efa8e230f626bb7c982fd0c990ba535b 100644 (file)
--- a/README.md
+++ b/README.md
@@ -358,23 +358,28 @@ extern "Rust" {
     /// `ptr` has to point to the beginning of an allocated block.
     fn miri_static_root(ptr: *const u8);
 
+    // Miri-provided extern function to get the amount of frames in the current backtrace.
+    // The `flags` argument must be `0`.
+    fn miri_backtrace_size(flags: u64) -> usize;
+
     /// Miri-provided extern function to obtain a backtrace of the current call stack.
-    /// This returns a boxed slice of pointers - each pointer is an opaque value
-    /// that is only useful when passed to `miri_resolve_frame`
-    /// The `flags` argument must be `0`.
-    fn miri_get_backtrace(flags: u64) -> Box<[*mut ()]>;
+    /// This writes a slice of pointers into `buf` - each pointer is an opaque value
+    /// that is only useful when passed to `miri_resolve_frame`.
+    /// `buf` must have `miri_backtrace_size(0) * pointer_size` bytes of space.
+    /// The `flags` argument must be `1`.
+    fn miri_get_backtrace(flags: u64, buf: *mut *mut ());
 
     /// Miri-provided extern function to resolve a frame pointer obtained
-    /// from `miri_get_backtrace`. The `flags` argument must be `0`,
+    /// from `miri_get_backtrace`. The `flags` argument must be `1`,
     /// and `MiriFrame` should be declared as follows:
     ///
     /// ```rust
     /// #[repr(C)]
     /// struct MiriFrame {
-    ///     // The name of the function being executed, encoded in UTF-8
-    ///     name: Box<[u8]>,
-    ///     // The filename of the function being executed, encoded in UTF-8
-    ///     filename: Box<[u8]>,
+    ///     // The size of the name of the function being executed, encoded in UTF-8
+    ///     name_len: usize,
+    ///     // The size of filename of the function being executed, encoded in UTF-8
+    ///     filename_len: usize,
     ///     // The line number currently being executed in `filename`, starting from '1'.
     ///     lineno: u32,
     ///     // The column number currently being executed in `filename`, starting from '1'.
@@ -390,6 +395,11 @@ extern "Rust" {
     /// This function can be called on any thread (not just the one which obtained `frame`).
     fn miri_resolve_frame(frame: *mut (), flags: u64) -> MiriFrame;
 
+    /// Miri-provided extern function to get the name and filename of the frame provided by `miri_resolve_frame`.
+    /// `name_buf` and `filename_buf` should be allocated with the `name_len` and `filename_len` fields of `MiriFrame`.
+    /// The flags argument must be `0`.
+    fn miri_resolve_frame_names(ptr: *mut (), flags: u64, name_buf: *mut u8, filename_buf: *mut u8);
+
     /// Miri-provided extern function to begin unwinding with the given payload.
     ///
     /// This is internal and unstable and should not be used; we give it here
index eb25cfd9935fff7592ce5be953591e3ee8f67bb2..52a8ac98f2de9d90eb918fb59113df8b20852609 100644 (file)
@@ -1,14 +1,14 @@
 use crate::*;
 use rustc_ast::ast::Mutability;
 use rustc_middle::ty::layout::LayoutOf as _;
-use rustc_middle::ty::{self, TypeAndMut};
-use rustc_span::{BytePos, Symbol};
+use rustc_middle::ty::{self, Instance, TypeAndMut};
+use rustc_span::{BytePos, Loc, Symbol};
 use rustc_target::{abi::Size, spec::abi::Abi};
 use std::convert::TryInto as _;
 
 impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}
 pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx> {
-    fn handle_miri_get_backtrace(
+    fn handle_miri_backtrace_size(
         &mut self,
         abi: Abi,
         link_name: Symbol,
@@ -16,14 +16,34 @@ fn handle_miri_get_backtrace(
         dest: &PlaceTy<'tcx, Tag>,
     ) -> InterpResult<'tcx> {
         let this = self.eval_context_mut();
-        let tcx = this.tcx;
         let &[ref flags] = this.check_shim(abi, Abi::Rust, link_name, args)?;
 
         let flags = this.read_scalar(flags)?.to_u64()?;
         if flags != 0 {
-            throw_unsup_format!("unknown `miri_get_backtrace` flags {}", flags);
+            throw_unsup_format!("unknown `miri_backtrace_size` flags {}", flags);
         }
 
+        let frame_count = this.active_thread_stack().len();
+
+        this.write_scalar(Scalar::from_machine_usize(frame_count.try_into().unwrap(), this), dest)
+    }
+
+    fn handle_miri_get_backtrace(
+        &mut self,
+        abi: Abi,
+        link_name: Symbol,
+        args: &[OpTy<'tcx, Tag>],
+        dest: &PlaceTy<'tcx, Tag>,
+    ) -> InterpResult<'tcx> {
+        let this = self.eval_context_mut();
+        let tcx = this.tcx;
+
+        let flags = if let Some(flags_op) = args.get(0) {
+            this.read_scalar(flags_op)?.to_u64()?
+        } else {
+            throw_ub_format!("expected at least 1 argument")
+        };
+
         let mut data = Vec::new();
         for frame in this.active_thread_stack().iter().rev() {
             let mut span = frame.current_span();
@@ -49,46 +69,60 @@ fn handle_miri_get_backtrace(
             })
             .collect();
 
-        let len = ptrs.len();
+        let len: u64 = ptrs.len().try_into().unwrap();
 
         let ptr_ty = tcx.mk_ptr(TypeAndMut { ty: tcx.types.unit, mutbl: Mutability::Mut });
 
-        let array_ty = tcx.mk_array(ptr_ty, ptrs.len().try_into().unwrap());
+        let array_layout = this.layout_of(tcx.mk_array(ptr_ty, len)).unwrap();
 
-        // Write pointers into array
-        let alloc =
-            this.allocate(this.layout_of(array_ty).unwrap(), MiriMemoryKind::Rust.into())?;
-        for (i, ptr) in ptrs.into_iter().enumerate() {
-            let place = this.mplace_index(&alloc, i as u64)?;
-            this.write_pointer(ptr, &place.into())?;
-        }
+        match flags {
+            // storage for pointers is allocated by miri
+            // deallocating the slice is undefined behavior with a custom global allocator
+            0 => {
+                let &[_flags] = this.check_shim(abi, Abi::Rust, link_name, args)?;
+
+                let alloc = this.allocate(array_layout, MiriMemoryKind::Rust.into())?;
+
+                // Write pointers into array
+                for (i, ptr) in ptrs.into_iter().enumerate() {
+                    let place = this.mplace_index(&alloc, i as u64)?;
+
+                    this.write_pointer(ptr, &place.into())?;
+                }
+
+                this.write_immediate(
+                    Immediate::new_slice(Scalar::from_maybe_pointer(alloc.ptr, this), len, this),
+                    dest,
+                )?;
+            }
+            // storage for pointers is allocated by the caller
+            1 => {
+                let &[_flags, ref buf] = this.check_shim(abi, Abi::Rust, link_name, args)?;
+
+                let buf_place = this.deref_operand(buf)?;
+
+                let ptr_layout = this.layout_of(ptr_ty)?;
+
+                for (i, ptr) in ptrs.into_iter().enumerate() {
+                    let offset = ptr_layout.size * i.try_into().unwrap();
+
+                    let op_place =
+                        buf_place.offset(offset, MemPlaceMeta::None, ptr_layout, this)?;
+
+                    this.write_pointer(ptr, &op_place.into())?;
+                }
+            }
+            _ => throw_unsup_format!("unknown `miri_get_backtrace` flags {}", flags),
+        };
 
-        this.write_immediate(
-            Immediate::new_slice(
-                Scalar::from_maybe_pointer(alloc.ptr, this),
-                len.try_into().unwrap(),
-                this,
-            ),
-            dest,
-        )?;
         Ok(())
     }
 
-    fn handle_miri_resolve_frame(
+    fn resolve_frame_pointer(
         &mut self,
-        abi: Abi,
-        link_name: Symbol,
-        args: &[OpTy<'tcx, Tag>],
-        dest: &PlaceTy<'tcx, Tag>,
-    ) -> InterpResult<'tcx> {
+        ptr: &OpTy<'tcx, Tag>,
+    ) -> InterpResult<'tcx, (Instance<'tcx>, Loc, String, String)> {
         let this = self.eval_context_mut();
-        let tcx = this.tcx;
-        let &[ref ptr, ref flags] = this.check_shim(abi, Abi::Rust, link_name, args)?;
-
-        let flags = this.read_scalar(flags)?.to_u64()?;
-        if flags != 0 {
-            throw_unsup_format!("unknown `miri_resolve_frame` flags {}", flags);
-        }
 
         let ptr = this.read_pointer(ptr)?;
         // Take apart the pointer, we need its pieces.
@@ -101,6 +135,29 @@ fn handle_miri_resolve_frame(
                 throw_ub_format!("expected function pointer, found {:?}", ptr);
             };
 
+        let lo =
+            this.tcx.sess.source_map().lookup_char_pos(BytePos(offset.bytes().try_into().unwrap()));
+
+        let name = fn_instance.to_string();
+        let filename = lo.file.name.prefer_remapped().to_string();
+
+        Ok((fn_instance, lo, name, filename))
+    }
+
+    fn handle_miri_resolve_frame(
+        &mut self,
+        abi: Abi,
+        link_name: Symbol,
+        args: &[OpTy<'tcx, Tag>],
+        dest: &PlaceTy<'tcx, Tag>,
+    ) -> InterpResult<'tcx> {
+        let this = self.eval_context_mut();
+        let &[ref ptr, ref flags] = this.check_shim(abi, Abi::Rust, link_name, args)?;
+
+        let flags = this.read_scalar(flags)?.to_u64()?;
+
+        let (fn_instance, lo, name, filename) = this.resolve_frame_pointer(ptr)?;
+
         // Reconstruct the original function pointer,
         // which we pass to user code.
         let fn_ptr = this.memory.create_fn_alloc(FnVal::Instance(fn_instance));
@@ -115,23 +172,10 @@ fn handle_miri_resolve_frame(
             );
         }
 
-        let pos = BytePos(offset.bytes().try_into().unwrap());
-        let name = fn_instance.to_string();
-
-        let lo = tcx.sess.source_map().lookup_char_pos(pos);
-
-        let filename = lo.file.name.prefer_remapped().to_string();
         let lineno: u32 = lo.line as u32;
         // `lo.col` is 0-based - add 1 to make it 1-based for the caller.
         let colno: u32 = lo.col.0 as u32 + 1;
 
-        // These are "mutable" allocations as we consider them to be owned by the callee.
-        let name_alloc = this.allocate_str(&name, MiriMemoryKind::Rust.into(), Mutability::Mut);
-        let filename_alloc =
-            this.allocate_str(&filename, MiriMemoryKind::Rust.into(), Mutability::Mut);
-        let lineno_alloc = Scalar::from_u32(lineno);
-        let colno_alloc = Scalar::from_u32(colno);
-
         let dest = this.force_allocation(dest)?;
         if let ty::Adt(adt, _) = dest.layout.ty.kind() {
             if !adt.repr.c() {
@@ -141,10 +185,38 @@ fn handle_miri_resolve_frame(
             }
         }
 
-        this.write_immediate(name_alloc.to_ref(this), &this.mplace_field(&dest, 0)?.into())?;
-        this.write_immediate(filename_alloc.to_ref(this), &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())?;
+        match flags {
+            0 => {
+                // These are "mutable" allocations as we consider them to be owned by the callee.
+                let name_alloc =
+                    this.allocate_str(&name, MiriMemoryKind::Rust.into(), Mutability::Mut);
+                let filename_alloc =
+                    this.allocate_str(&filename, MiriMemoryKind::Rust.into(), Mutability::Mut);
+
+                this.write_immediate(
+                    name_alloc.to_ref(this),
+                    &this.mplace_field(&dest, 0)?.into(),
+                )?;
+                this.write_immediate(
+                    filename_alloc.to_ref(this),
+                    &this.mplace_field(&dest, 1)?.into(),
+                )?;
+            }
+            1 => {
+                this.write_scalar(
+                    Scalar::from_machine_usize(name.len().try_into().unwrap(), this),
+                    &this.mplace_field(&dest, 0)?.into(),
+                )?;
+                this.write_scalar(
+                    Scalar::from_machine_usize(filename.len().try_into().unwrap(), this),
+                    &this.mplace_field(&dest, 1)?.into(),
+                )?;
+            }
+            _ => throw_unsup_format!("unknown `miri_resolve_frame` flags {}", flags),
+        }
+
+        this.write_scalar(Scalar::from_u32(lineno), &this.mplace_field(&dest, 2)?.into())?;
+        this.write_scalar(Scalar::from_u32(colno), &this.mplace_field(&dest, 3)?.into())?;
 
         // Support a 4-field struct for now - this is deprecated
         // and slated for removal.
@@ -154,4 +226,28 @@ fn handle_miri_resolve_frame(
 
         Ok(())
     }
+
+    fn handle_miri_resolve_frame_names(
+        &mut self,
+        abi: Abi,
+        link_name: Symbol,
+        args: &[OpTy<'tcx, Tag>],
+    ) -> InterpResult<'tcx> {
+        let this = self.eval_context_mut();
+
+        let &[ref ptr, ref flags, ref name_ptr, ref filename_ptr] =
+            this.check_shim(abi, Abi::Rust, link_name, args)?;
+
+        let flags = this.read_scalar(flags)?.to_u64()?;
+        if flags != 0 {
+            throw_unsup_format!("unknown `miri_resolve_frame_names` flags {}", flags);
+        }
+
+        let (_, _, name, filename) = this.resolve_frame_pointer(ptr)?;
+
+        this.memory.write_bytes(this.read_pointer(name_ptr)?, name.bytes())?;
+        this.memory.write_bytes(this.read_pointer(filename_ptr)?, filename.bytes())?;
+
+        Ok(())
+    }
 }
index b07db9535129fed93853e6762b4afa060fed1906..ecffd310de5698c410f1f6d7c374fc86f89b77ef 100644 (file)
@@ -380,6 +380,11 @@ fn emulate_foreign_item_by_name(
                 this.machine.static_roots.push(alloc_id);
             }
 
+            // Obtains the size of a Miri backtrace. See the README for details.
+            "miri_backtrace_size" => {
+                this.handle_miri_backtrace_size(abi, link_name, args, dest)?;
+            }
+
             // Obtains a Miri backtrace. See the README for details.
             "miri_get_backtrace" => {
                 // `check_shim` happens inside `handle_miri_get_backtrace`.
@@ -392,6 +397,10 @@ fn emulate_foreign_item_by_name(
                 this.handle_miri_resolve_frame(abi, link_name, args, dest)?;
             }
 
+            // Writes the function and file names of a Miri backtrace frame into a user provided buffer. See the README for details.
+            "miri_resolve_frame_names" => {
+                this.handle_miri_resolve_frame_names(abi, link_name, args)?;
+            }
 
             // Standard C allocation
             "malloc" => {
diff --git a/tests/compile-fail/backtrace/bad-backtrace-flags.rs b/tests/compile-fail/backtrace/bad-backtrace-flags.rs
new file mode 100644 (file)
index 0000000..5f30513
--- /dev/null
@@ -0,0 +1,9 @@
+extern "Rust" {
+    fn miri_get_backtrace(flags: u64, buf: *mut *mut ());
+}
+
+fn main() {
+    unsafe {
+        miri_get_backtrace(2, 0 as *mut _); //~ ERROR  unsupported operation: unknown `miri_get_backtrace` flags 2
+    }
+}
diff --git a/tests/compile-fail/backtrace/bad-backtrace-resolve-flags.rs b/tests/compile-fail/backtrace/bad-backtrace-resolve-flags.rs
new file mode 100644 (file)
index 0000000..5a30253
--- /dev/null
@@ -0,0 +1,25 @@
+#[repr(C)]
+struct MiriFrame {
+    name_len: usize,
+    filename_len: usize,
+    lineno: u32,
+    colno: u32,
+    fn_ptr: *mut (),
+}
+
+extern "Rust" {
+    fn miri_backtrace_size(flags: u64) -> usize;
+    fn miri_get_backtrace(flags: u64, buf: *mut *mut ());
+    fn miri_resolve_frame(ptr: *mut (), flags: u64) -> MiriFrame;
+}
+
+fn main() {
+    unsafe {
+        let mut buf = vec![0 as *mut _; miri_backtrace_size(0)];
+
+        miri_get_backtrace(1, buf.as_mut_ptr());
+
+        // miri_resolve_frame will error from an invalid backtrace before it will from invalid flags
+        miri_resolve_frame(buf[0], 2); //~ ERROR  unsupported operation: unknown `miri_resolve_frame` flags 2
+    }
+}
diff --git a/tests/compile-fail/backtrace/bad-backtrace-resolve-names-flags.rs b/tests/compile-fail/backtrace/bad-backtrace-resolve-names-flags.rs
new file mode 100644 (file)
index 0000000..8e69a27
--- /dev/null
@@ -0,0 +1,16 @@
+extern "Rust" {
+    fn miri_backtrace_size(flags: u64) -> usize;
+    fn miri_get_backtrace(flags: u64, buf: *mut *mut ());
+    fn miri_resolve_frame_names(ptr: *mut (), flags: u64, name_buf: *mut u8, filename_buf: *mut u8);
+}
+
+fn main() {
+    unsafe {
+        let mut buf = vec![0 as *mut _; miri_backtrace_size(0)];
+
+        miri_get_backtrace(1, buf.as_mut_ptr());
+
+        // miri_resolve_frame_names will error from an invalid backtrace before it will from invalid flags
+        miri_resolve_frame_names(buf[0], 2, 0 as *mut _, 0 as *mut _); //~ ERROR  unsupported operation: unknown `miri_resolve_frame_names` flags 2
+    }
+}
diff --git a/tests/compile-fail/backtrace/bad-backtrace-size-flags.rs b/tests/compile-fail/backtrace/bad-backtrace-size-flags.rs
new file mode 100644 (file)
index 0000000..25eded9
--- /dev/null
@@ -0,0 +1,9 @@
+extern "Rust" {
+    fn miri_backtrace_size(flags: u64) -> usize;
+}
+
+fn main() {
+    unsafe {
+        miri_backtrace_size(2); //~ ERROR  unsupported operation: unknown `miri_backtrace_size` flags 2
+    }
+}
diff --git a/tests/compile-fail/backtrace/bad-backtrace-version.rs b/tests/compile-fail/backtrace/bad-backtrace-version.rs
deleted file mode 100644 (file)
index 4579b5d..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-extern "Rust" {
-    fn miri_resolve_frame(ptr: *mut (), flags: u64);
-}
-
-fn main() {
-    unsafe {
-        miri_resolve_frame(0 as *mut _, 1); //~ ERROR  unsupported operation: unknown `miri_resolve_frame` flags 1
-    }
-}
diff --git a/tests/run-pass/backtrace-api-v0.rs b/tests/run-pass/backtrace-api-v0.rs
new file mode 100644 (file)
index 0000000..cb3706e
--- /dev/null
@@ -0,0 +1,56 @@
+// normalize-stderr-test ".*/(rust[^/]*|checkout)/library/" -> "RUSTLIB/"
+// normalize-stderr-test "RUSTLIB/(.*):\d+:\d+ "-> "RUSTLIB/$1:LL:COL "
+// normalize-stderr-test "::<.*>" -> ""
+
+#[inline(never)] fn func_a() -> Box<[*mut ()]> { func_b::<u8>() }
+#[inline(never)] fn func_b<T>() -> Box<[*mut ()]> { func_c() }
+
+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) } }
+
+fn main() {
+    let mut seen_main = false;
+    let frames = func_a();
+    for frame in frames.into_iter() {
+        let miri_frame = unsafe { miri_resolve_frame(*frame, 0) };
+        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);
+        // 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";
+        }
+    }
+}
+
+// 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 (),
+}
+
diff --git a/tests/run-pass/backtrace-api-v0.stderr b/tests/run-pass/backtrace-api-v0.stderr
new file mode 100644 (file)
index 0000000..8a697a4
--- /dev/null
@@ -0,0 +1,18 @@
+$DIR/backtrace-api-v0.rs:13:59 (func_d)
+$DIR/backtrace-api-v0.rs:12:50 (func_c)
+$DIR/backtrace-api-v0.rs:6:53 (func_b)
+$DIR/backtrace-api-v0.rs:5:50 (func_a)
+$DIR/backtrace-api-v0.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})
+RUSTLIB/core/src/ops/function.rs:LL:COL (std::ops::function::impls::call_once)
+RUSTLIB/std/src/panicking.rs:LL:COL (std::panicking::r#try::do_call)
+RUSTLIB/std/src/panicking.rs:LL:COL (std::panicking::r#try)
+RUSTLIB/std/src/panic.rs:LL:COL (std::panic::catch_unwind)
+RUSTLIB/std/src/rt.rs:LL:COL (std::rt::lang_start_internal::{closure#2})
+RUSTLIB/std/src/panicking.rs:LL:COL (std::panicking::r#try::do_call)
+RUSTLIB/std/src/panicking.rs:LL:COL (std::panicking::r#try)
+RUSTLIB/std/src/panic.rs:LL:COL (std::panic::catch_unwind)
+RUSTLIB/std/src/rt.rs:LL:COL (std::rt::lang_start_internal)
+RUSTLIB/std/src/rt.rs:LL:COL (std::rt::lang_start)
diff --git a/tests/run-pass/backtrace-api-v0.stdout b/tests/run-pass/backtrace-api-v0.stdout
new file mode 100644 (file)
index 0000000..c80a3f3
--- /dev/null
@@ -0,0 +1,5 @@
+$DIR/backtrace-api-v0.rs:13:59 (func_d)
+$DIR/backtrace-api-v0.rs:12:50 (func_c)
+$DIR/backtrace-api-v0.rs:6:53 (func_b::<u8>)
+$DIR/backtrace-api-v0.rs:5:50 (func_a)
+$DIR/backtrace-api-v0.rs:17:18 (main)
diff --git a/tests/run-pass/backtrace-api-v1.rs b/tests/run-pass/backtrace-api-v1.rs
new file mode 100644 (file)
index 0000000..7b72c85
--- /dev/null
@@ -0,0 +1,65 @@
+// normalize-stderr-test ".*/(rust[^/]*|checkout)/library/" -> "RUSTLIB/"
+// normalize-stderr-test "RUSTLIB/(.*):\d+:\d+ "-> "RUSTLIB/$1:LL:COL "
+// normalize-stderr-test "::<.*>" -> ""
+
+#[inline(never)] fn func_a() -> Box<[*mut ()]> { func_b::<u8>() }
+#[inline(never)] fn func_b<T>() -> Box<[*mut ()]> { func_c() }
+
+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 { 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() } }
+
+fn main() {
+    let mut seen_main = false;
+    let frames = func_a();
+    for frame in frames.into_iter() {
+        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();
+
+        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);
+        // 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";
+        }
+    }
+}
+
+// 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_backtrace_size(flags: u64) -> usize;
+    fn miri_get_backtrace(flags: u64, buf: *mut *mut ());
+    fn miri_resolve_frame(ptr: *mut (), flags: u64) -> MiriFrame;
+    fn miri_resolve_frame_names(ptr: *mut (), flags: u64, name_buf: *mut u8, filename_buf: *mut u8);
+}
+
+#[derive(Debug)]
+#[repr(C)]
+struct MiriFrame {
+    name_len: usize,
+    filename_len: usize,
+    lineno: u32,
+    colno: u32,
+    fn_ptr: *mut (),
+}
\ No newline at end of file
diff --git a/tests/run-pass/backtrace-api-v1.stderr b/tests/run-pass/backtrace-api-v1.stderr
new file mode 100644 (file)
index 0000000..806a1c6
--- /dev/null
@@ -0,0 +1,18 @@
+$DIR/backtrace-api-v1.rs:13:144 (func_d)
+$DIR/backtrace-api-v1.rs:12:50 (func_c)
+$DIR/backtrace-api-v1.rs:6:53 (func_b)
+$DIR/backtrace-api-v1.rs:5:50 (func_a)
+$DIR/backtrace-api-v1.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})
+RUSTLIB/core/src/ops/function.rs:LL:COL (std::ops::function::impls::call_once)
+RUSTLIB/std/src/panicking.rs:LL:COL (std::panicking::r#try::do_call)
+RUSTLIB/std/src/panicking.rs:LL:COL (std::panicking::r#try)
+RUSTLIB/std/src/panic.rs:LL:COL (std::panic::catch_unwind)
+RUSTLIB/std/src/rt.rs:LL:COL (std::rt::lang_start_internal::{closure#2})
+RUSTLIB/std/src/panicking.rs:LL:COL (std::panicking::r#try::do_call)
+RUSTLIB/std/src/panicking.rs:LL:COL (std::panicking::r#try)
+RUSTLIB/std/src/panic.rs:LL:COL (std::panic::catch_unwind)
+RUSTLIB/std/src/rt.rs:LL:COL (std::rt::lang_start_internal)
+RUSTLIB/std/src/rt.rs:LL:COL (std::rt::lang_start)
diff --git a/tests/run-pass/backtrace-api-v1.stdout b/tests/run-pass/backtrace-api-v1.stdout
new file mode 100644 (file)
index 0000000..2670d56
--- /dev/null
@@ -0,0 +1,5 @@
+$DIR/backtrace-api-v1.rs:13:144 (func_d)
+$DIR/backtrace-api-v1.rs:12:50 (func_c)
+$DIR/backtrace-api-v1.rs:6:53 (func_b::<u8>)
+$DIR/backtrace-api-v1.rs:5:50 (func_a)
+$DIR/backtrace-api-v1.rs:17:18 (main)
diff --git a/tests/run-pass/backtrace-api.rs b/tests/run-pass/backtrace-api.rs
deleted file mode 100644 (file)
index cb3706e..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-// normalize-stderr-test ".*/(rust[^/]*|checkout)/library/" -> "RUSTLIB/"
-// normalize-stderr-test "RUSTLIB/(.*):\d+:\d+ "-> "RUSTLIB/$1:LL:COL "
-// normalize-stderr-test "::<.*>" -> ""
-
-#[inline(never)] fn func_a() -> Box<[*mut ()]> { func_b::<u8>() }
-#[inline(never)] fn func_b<T>() -> Box<[*mut ()]> { func_c() }
-
-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) } }
-
-fn main() {
-    let mut seen_main = false;
-    let frames = func_a();
-    for frame in frames.into_iter() {
-        let miri_frame = unsafe { miri_resolve_frame(*frame, 0) };
-        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);
-        // 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";
-        }
-    }
-}
-
-// 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 (),
-}
-
diff --git a/tests/run-pass/backtrace-api.stderr b/tests/run-pass/backtrace-api.stderr
deleted file mode 100644 (file)
index bd5908b..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-$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})
-RUSTLIB/core/src/ops/function.rs:LL:COL (std::ops::function::impls::call_once)
-RUSTLIB/std/src/panicking.rs:LL:COL (std::panicking::r#try::do_call)
-RUSTLIB/std/src/panicking.rs:LL:COL (std::panicking::r#try)
-RUSTLIB/std/src/panic.rs:LL:COL (std::panic::catch_unwind)
-RUSTLIB/std/src/rt.rs:LL:COL (std::rt::lang_start_internal::{closure#2})
-RUSTLIB/std/src/panicking.rs:LL:COL (std::panicking::r#try::do_call)
-RUSTLIB/std/src/panicking.rs:LL:COL (std::panicking::r#try)
-RUSTLIB/std/src/panic.rs:LL:COL (std::panic::catch_unwind)
-RUSTLIB/std/src/rt.rs:LL:COL (std::rt::lang_start_internal)
-RUSTLIB/std/src/rt.rs:LL:COL (std::rt::lang_start)
diff --git a/tests/run-pass/backtrace-api.stdout b/tests/run-pass/backtrace-api.stdout
deleted file mode 100644 (file)
index 175ff3b..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-$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)