Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit b637c0e

Browse files
committed
Add initial debug fmt for Backtrace
1 parent e6ec0d1 commit b637c0e

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

src/libstd/backtrace.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ use backtrace_rs as backtrace;
106106
/// previous point in time. In some instances the `Backtrace` type may
107107
/// internally be empty due to configuration. For more information see
108108
/// `Backtrace::capture`.
109+
#[derive(Debug)]
109110
pub struct Backtrace {
110111
inner: Inner,
111112
}
@@ -126,12 +127,14 @@ pub enum BacktraceStatus {
126127
Captured,
127128
}
128129

130+
#[derive(Debug)]
129131
enum Inner {
130132
Unsupported,
131133
Disabled,
132134
Captured(Mutex<Capture>),
133135
}
134136

137+
#[derive(Debug)]
135138
struct Capture {
136139
actual_start: usize,
137140
resolved: bool,
@@ -143,11 +146,13 @@ fn _assert_send_sync() {
143146
_assert::<Backtrace>();
144147
}
145148

149+
#[derive(Debug)]
146150
struct BacktraceFrame {
147151
frame: backtrace::Frame,
148152
symbols: Vec<BacktraceSymbol>,
149153
}
150154

155+
#[derive(Debug)]
151156
struct BacktraceSymbol {
152157
name: Option<Vec<u8>>,
153158
filename: Option<BytesOrWide>,
@@ -159,6 +164,20 @@ enum BytesOrWide {
159164
Wide(Vec<u16>),
160165
}
161166

167+
impl fmt::Debug for BytesOrWide {
168+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
169+
output_filename(
170+
fmt,
171+
match self {
172+
BytesOrWide::Bytes(w) => BytesOrWideString::Bytes(w),
173+
BytesOrWide::Wide(w) => BytesOrWideString::Wide(w),
174+
},
175+
backtrace::PrintFmt::Full,
176+
crate::env::current_dir().as_ref().ok(),
177+
)
178+
}
179+
}
180+
162181
impl Backtrace {
163182
/// Returns whether backtrace captures are enabled through environment
164183
/// variables.
@@ -267,12 +286,6 @@ impl Backtrace {
267286
}
268287

269288
impl fmt::Display for Backtrace {
270-
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
271-
fmt::Debug::fmt(self, fmt)
272-
}
273-
}
274-
275-
impl fmt::Debug for Backtrace {
276289
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
277290
let mut capture = match &self.inner {
278291
Inner::Unsupported => return fmt.write_str("unsupported backtrace"),

0 commit comments

Comments
 (0)