@@ -159,6 +159,69 @@ enum BytesOrWide {
159
159
Wide ( Vec < u16 > ) ,
160
160
}
161
161
162
+ impl fmt:: Debug for Backtrace {
163
+ fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
164
+ let mut capture = match & self . inner {
165
+ Inner :: Unsupported => return fmt. write_str ( "unsupported backtrace" ) ,
166
+ Inner :: Disabled => return fmt. write_str ( "disabled backtrace" ) ,
167
+ Inner :: Captured ( c) => c. lock ( ) . unwrap ( ) ,
168
+ } ;
169
+ capture. resolve ( ) ;
170
+
171
+ let frames = & capture. frames [ capture. actual_start ..] ;
172
+
173
+ write ! ( fmt, "Backtrace " ) ?;
174
+
175
+ let mut dbg = fmt. debug_list ( ) ;
176
+
177
+ for frame in frames {
178
+ if frame. frame . ip ( ) . is_null ( ) {
179
+ continue ;
180
+ }
181
+
182
+ dbg. entries ( & frame. symbols ) ;
183
+ }
184
+
185
+ dbg. finish ( )
186
+ }
187
+ }
188
+
189
+ impl fmt:: Debug for BacktraceSymbol {
190
+ fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
191
+ write ! ( fmt, "{{ " ) ?;
192
+
193
+ if let Some ( fn_name) = self . name . as_ref ( ) . map ( |b| backtrace:: SymbolName :: new ( b) ) {
194
+ write ! ( fmt, "fn: \" {:#}\" " , fn_name) ?;
195
+ } else {
196
+ write ! ( fmt, "fn: \" <unknown>\" " ) ?;
197
+ }
198
+
199
+ if let Some ( fname) = self . filename . as_ref ( ) {
200
+ write ! ( fmt, ", file: {:?}" , fname) ?;
201
+ }
202
+
203
+ if let Some ( line) = self . lineno . as_ref ( ) {
204
+ write ! ( fmt, ", line: {:?}" , line) ?;
205
+ }
206
+
207
+ write ! ( fmt, " }}" )
208
+ }
209
+ }
210
+
211
+ impl fmt:: Debug for BytesOrWide {
212
+ fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
213
+ output_filename (
214
+ fmt,
215
+ match self {
216
+ BytesOrWide :: Bytes ( w) => BytesOrWideString :: Bytes ( w) ,
217
+ BytesOrWide :: Wide ( w) => BytesOrWideString :: Wide ( w) ,
218
+ } ,
219
+ backtrace:: PrintFmt :: Short ,
220
+ crate :: env:: current_dir ( ) . as_ref ( ) . ok ( ) ,
221
+ )
222
+ }
223
+ }
224
+
162
225
impl Backtrace {
163
226
/// Returns whether backtrace captures are enabled through environment
164
227
/// variables.
@@ -267,12 +330,6 @@ impl Backtrace {
267
330
}
268
331
269
332
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 {
276
333
fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
277
334
let mut capture = match & self . inner {
278
335
Inner :: Unsupported => return fmt. write_str ( "unsupported backtrace" ) ,
0 commit comments