44//! This file contains functionality that makes RMC easier to debug
55
66use crate :: GotocCtx ;
7+ use cbmc:: goto_program:: Location ;
78use rustc_middle:: mir:: Body ;
89use rustc_middle:: ty:: print:: with_no_trimmed_paths;
910use rustc_middle:: ty:: Instance ;
11+ use rustc_span:: def_id:: DefId ;
1012use std:: cell:: RefCell ;
1113use std:: lazy:: SyncLazy ;
1214use std:: panic;
@@ -15,7 +17,7 @@ use tracing::debug;
1517// Use a thread-local global variable to track the current codegen item for debugging.
1618// If RMC panics during codegen, we can grab this item to include the problematic
1719// codegen item in the panic trace.
18- thread_local ! ( static CURRENT_CODEGEN_ITEM : RefCell <Option <String >> = RefCell :: new( None ) ) ;
20+ thread_local ! ( static CURRENT_CODEGEN_ITEM : RefCell <( Option <String >, Option < Location > ) > = RefCell :: new( ( None , None ) ) ) ;
1921
2022// Include RMC's bug reporting URL in our panics.
2123const BUG_REPORT_URL : & str =
@@ -44,11 +46,17 @@ static DEFAULT_HOOK: SyncLazy<Box<dyn Fn(&panic::PanicInfo<'_>) + Sync + Send +
4446
4547 // Print the current function if available
4648 CURRENT_CODEGEN_ITEM . with ( |cell| {
47- if let Some ( current_item) = cell. borrow ( ) . clone ( ) {
49+ let t = cell. borrow ( ) . clone ( ) ;
50+ if let Some ( current_item) = t. 0 {
4851 eprintln ! ( "[RMC] current codegen item: {}" , current_item) ;
4952 } else {
5053 eprintln ! ( "[RMC] no current codegen item." ) ;
5154 }
55+ if let Some ( current_loc) = t. 1 {
56+ eprintln ! ( "[RMC] current codegen location: {:?}" , current_loc) ;
57+ } else {
58+ eprintln ! ( "[RMC] no current codegen location." ) ;
59+ }
5260 } ) ;
5361
5462 // Separate the output with an empty line
@@ -71,11 +79,13 @@ impl<'tcx> GotocCtx<'tcx> {
7179 & mut self ,
7280 call : F ,
7381 panic_debug : String ,
82+ def_id : DefId ,
7483 ) {
7584 CURRENT_CODEGEN_ITEM . with ( |odb_cell| {
76- odb_cell. replace ( Some ( panic_debug) ) ;
85+ odb_cell
86+ . replace ( ( Some ( panic_debug) , Some ( self . codegen_span ( & self . tcx . def_span ( def_id) ) ) ) ) ;
7787 call ( self ) ;
78- odb_cell. replace ( None ) ;
88+ odb_cell. replace ( ( None , None ) ) ;
7989 } ) ;
8090 }
8191
0 commit comments