@@ -283,6 +283,32 @@ impl<'mir, 'tcx, Prov: Provenance, Extra> Frame<'mir, 'tcx, Prov, Extra> {
283283 pub ( super ) fn locals_addr ( & self ) -> usize {
284284 self . locals . raw . as_ptr ( ) . addr ( )
285285 }
286+
287+ #[ must_use]
288+ pub fn generate_stacktrace_from_stack ( stack : & [ Self ] ) -> Vec < FrameInfo < ' tcx > > {
289+ let mut frames = Vec :: new ( ) ;
290+ // This deliberately does *not* honor `requires_caller_location` since it is used for much
291+ // more than just panics.
292+ for frame in stack. iter ( ) . rev ( ) {
293+ let span = match frame. loc {
294+ Left ( loc) => {
295+ // If the stacktrace passes through MIR-inlined source scopes, add them.
296+ let mir:: SourceInfo { mut span, scope } = * frame. body . source_info ( loc) ;
297+ let mut scope_data = & frame. body . source_scopes [ scope] ;
298+ while let Some ( ( instance, call_span) ) = scope_data. inlined {
299+ frames. push ( FrameInfo { span, instance } ) ;
300+ span = call_span;
301+ scope_data = & frame. body . source_scopes [ scope_data. parent_scope . unwrap ( ) ] ;
302+ }
303+ span
304+ }
305+ Right ( span) => span,
306+ } ;
307+ frames. push ( FrameInfo { span, instance : frame. instance } ) ;
308+ }
309+ trace ! ( "generate stacktrace: {:#?}" , frames) ;
310+ frames
311+ }
286312}
287313
288314// FIXME: only used by miri, should be removed once translatable.
@@ -1170,37 +1196,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
11701196 PlacePrinter { ecx : self , place : * place. place ( ) }
11711197 }
11721198
1173- #[ must_use]
1174- pub fn generate_stacktrace_from_stack (
1175- stack : & [ Frame < ' mir , ' tcx , M :: Provenance , M :: FrameExtra > ] ,
1176- ) -> Vec < FrameInfo < ' tcx > > {
1177- let mut frames = Vec :: new ( ) ;
1178- // This deliberately does *not* honor `requires_caller_location` since it is used for much
1179- // more than just panics.
1180- for frame in stack. iter ( ) . rev ( ) {
1181- let span = match frame. loc {
1182- Left ( loc) => {
1183- // If the stacktrace passes through MIR-inlined source scopes, add them.
1184- let mir:: SourceInfo { mut span, scope } = * frame. body . source_info ( loc) ;
1185- let mut scope_data = & frame. body . source_scopes [ scope] ;
1186- while let Some ( ( instance, call_span) ) = scope_data. inlined {
1187- frames. push ( FrameInfo { span, instance } ) ;
1188- span = call_span;
1189- scope_data = & frame. body . source_scopes [ scope_data. parent_scope . unwrap ( ) ] ;
1190- }
1191- span
1192- }
1193- Right ( span) => span,
1194- } ;
1195- frames. push ( FrameInfo { span, instance : frame. instance } ) ;
1196- }
1197- trace ! ( "generate stacktrace: {:#?}" , frames) ;
1198- frames
1199- }
1200-
12011199 #[ must_use]
12021200 pub fn generate_stacktrace ( & self ) -> Vec < FrameInfo < ' tcx > > {
1203- Self :: generate_stacktrace_from_stack ( self . stack ( ) )
1201+ Frame :: generate_stacktrace_from_stack ( self . stack ( ) )
12041202 }
12051203}
12061204
0 commit comments