@@ -159,6 +159,69 @@ enum BytesOrWide {
159159 Wide ( Vec < u16 > ) ,
160160}
161161
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+
162225impl Backtrace {
163226 /// Returns whether backtrace captures are enabled through environment
164227 /// variables.
@@ -267,12 +330,6 @@ impl Backtrace {
267330}
268331
269332impl 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 {
276333 fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
277334 let mut capture = match & self . inner {
278335 Inner :: Unsupported => return fmt. write_str ( "unsupported backtrace" ) ,
0 commit comments