about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorJane Lusby <jlusby@yaah.dev>2020-02-10 11:47:26 -0800
committerJane Lusby <jlusby@yaah.dev>2020-02-10 14:28:31 -0800
commitb637c0e84a9dbb5883130e0ea1e5ee9e8acf3bc1 (patch)
treed0d1cb822aa4746d593229c2d1154144f695b58c /src/libstd
parente6ec0d125eba4074122b187032474b4174fb9d31 (diff)
downloadrust-b637c0e84a9dbb5883130e0ea1e5ee9e8acf3bc1.tar.gz
rust-b637c0e84a9dbb5883130e0ea1e5ee9e8acf3bc1.zip
Add initial debug fmt for Backtrace
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/backtrace.rs25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/libstd/backtrace.rs b/src/libstd/backtrace.rs
index 5ba1c940251..6b4ae77cec7 100644
--- a/src/libstd/backtrace.rs
+++ b/src/libstd/backtrace.rs
@@ -106,6 +106,7 @@ use backtrace_rs as backtrace;
 /// previous point in time. In some instances the `Backtrace` type may
 /// internally be empty due to configuration. For more information see
 /// `Backtrace::capture`.
+#[derive(Debug)]
 pub struct Backtrace {
     inner: Inner,
 }
@@ -126,12 +127,14 @@ pub enum BacktraceStatus {
     Captured,
 }
 
+#[derive(Debug)]
 enum Inner {
     Unsupported,
     Disabled,
     Captured(Mutex<Capture>),
 }
 
+#[derive(Debug)]
 struct Capture {
     actual_start: usize,
     resolved: bool,
@@ -143,11 +146,13 @@ fn _assert_send_sync() {
     _assert::<Backtrace>();
 }
 
+#[derive(Debug)]
 struct BacktraceFrame {
     frame: backtrace::Frame,
     symbols: Vec<BacktraceSymbol>,
 }
 
+#[derive(Debug)]
 struct BacktraceSymbol {
     name: Option<Vec<u8>>,
     filename: Option<BytesOrWide>,
@@ -159,6 +164,20 @@ enum BytesOrWide {
     Wide(Vec<u16>),
 }
 
+impl fmt::Debug for BytesOrWide {
+    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
+        output_filename(
+            fmt,
+            match self {
+                BytesOrWide::Bytes(w) => BytesOrWideString::Bytes(w),
+                BytesOrWide::Wide(w) => BytesOrWideString::Wide(w),
+            },
+            backtrace::PrintFmt::Full,
+            crate::env::current_dir().as_ref().ok(),
+        )
+    }
+}
+
 impl Backtrace {
     /// Returns whether backtrace captures are enabled through environment
     /// variables.
@@ -268,12 +287,6 @@ impl Backtrace {
 
 impl fmt::Display for Backtrace {
     fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
-        fmt::Debug::fmt(self, fmt)
-    }
-}
-
-impl fmt::Debug for Backtrace {
-    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
         let mut capture = match &self.inner {
             Inner::Unsupported => return fmt.write_str("unsupported backtrace"),
             Inner::Disabled => return fmt.write_str("disabled backtrace"),