@@ -283,6 +283,32 @@ impl<'mir, 'tcx, Prov: Provenance, Extra> Frame<'mir, 'tcx, Prov, Extra> {
283
283
pub ( super ) fn locals_addr ( & self ) -> usize {
284
284
self . locals . raw . as_ptr ( ) . addr ( )
285
285
}
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
+ }
286
312
}
287
313
288
314
// 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> {
1170
1196
PlacePrinter { ecx : self , place : * place. place ( ) }
1171
1197
}
1172
1198
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
-
1201
1199
#[ must_use]
1202
1200
pub fn generate_stacktrace ( & self ) -> Vec < FrameInfo < ' tcx > > {
1203
- Self :: generate_stacktrace_from_stack ( self . stack ( ) )
1201
+ Frame :: generate_stacktrace_from_stack ( self . stack ( ) )
1204
1202
}
1205
1203
}
1206
1204
0 commit comments