Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start working on proof of concept for exposing Backtrace in core #77384

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions library/core/src/backtrace.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//! hi
#![unstable(feature = "core_backtrace", issue = "74465")]
use crate::fmt;

// perma(?)-unstable
#[unstable(feature = "core_backtrace", issue = "74465")]
///
pub trait RawBacktraceImpl: fmt::Debug + fmt::Display + 'static {
///
unsafe fn drop_and_free(self: *mut Self);
}

#[unstable(feature = "core_backtrace", issue = "74465")]
///
pub struct Backtrace {
inner: *mut dyn RawBacktraceImpl,
}

#[unstable(feature = "core_backtrace", issue = "74465")]
unsafe impl Send for Backtrace {}

#[unstable(feature = "core_backtrace", issue = "74465")]
unsafe impl Sync for Backtrace {}

#[unstable(feature = "core_backtrace", issue = "74465")]
impl Drop for Backtrace {
fn drop(&mut self) {
unsafe { RawBacktraceImpl::drop_and_free(self.inner) }
}
}

#[unstable(feature = "core_backtrace", issue = "74465")]
impl fmt::Debug for Backtrace {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
let imp: &dyn RawBacktraceImpl = unsafe { &*self.inner };
fmt::Debug::fmt(imp, fmt)
}
}

#[unstable(feature = "core_backtrace", issue = "74465")]
impl fmt::Display for Backtrace {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
let imp: &dyn RawBacktraceImpl = unsafe { &*self.inner };
fmt::Display::fmt(imp, fmt)
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: missing trailing newline

1 change: 1 addition & 0 deletions library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ pub mod ops;
pub mod any;
pub mod array;
pub mod ascii;
pub mod backtrace;
pub mod cell;
pub mod char;
pub mod ffi;
Expand Down
10 changes: 7 additions & 3 deletions library/std/src/backtrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,20 @@ use crate::sync::Once;
use crate::sys_common::backtrace::{lock, output_filename};
use crate::vec::Vec;

pub use core::backtrace::Backtrace;

/// A captured OS thread stack backtrace.
///
/// This type represents a stack backtrace for an OS thread captured at a
/// previous point in time. In some instances the `Backtrace` type may
/// internally be empty due to configuration. For more information see
/// `Backtrace::capture`.
pub struct Backtrace {
struct BacktraceImpl {
inner: Inner,
}

impl core::backtrace::RawBacktraceImpl for BacktraceImpl {}

/// The current status of a backtrace, indicating whether it was captured or
/// whether it is empty for some other reason.
#[non_exhaustive]
Expand Down Expand Up @@ -173,7 +177,7 @@ enum BytesOrWide {
Wide(Vec<u16>),
}

impl fmt::Debug for Backtrace {
impl fmt::Debug for BacktraceImpl {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
let capture = match &self.inner {
Inner::Unsupported => return fmt.write_str("<unsupported>"),
Expand Down Expand Up @@ -372,7 +376,7 @@ impl<'a> Backtrace {
}
}

impl fmt::Display for Backtrace {
impl fmt::Display for BacktraceImpl {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
let capture = match &self.inner {
Inner::Unsupported => return fmt.write_str("unsupported backtrace"),
Expand Down
1 change: 1 addition & 0 deletions library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@
#![feature(const_raw_ptr_deref)]
#![feature(const_ipv4)]
#![feature(container_error_extra)]
#![feature(core_backtrace)]
#![feature(core_intrinsics)]
#![feature(custom_test_frameworks)]
#![feature(decl_macro)]
Expand Down