33
44//! This file contains functionality that makes RMC easier to debug
55
6+ use super :: metadata:: * ;
7+ use rustc_middle:: mir:: Body ;
8+ use rustc_middle:: ty:: print:: with_no_trimmed_paths;
9+ use rustc_middle:: ty:: Instance ;
10+ use std:: cell:: RefCell ;
11+ use std:: lazy:: SyncLazy ;
12+ use std:: panic;
13+ use tracing:: debug;
14+
615// Use a thread-local global variable to track the current codegen item for debugging.
716// If RMC panics during codegen, we can grab this item to include the problematic
817// codegen item in the panic trace.
@@ -12,43 +21,43 @@ thread_local!(static CURRENT_CODEGEN_ITEM: RefCell<Option<String>> = RefCell::ne
1221const BUG_REPORT_URL : & str =
1322 "https://github.com/model-checking/rmc/issues/new?labels=bug&template=bug_report.md" ;
1423
15- // Custom panic hook.
16- static DEFAULT_HOOK : SyncLazy < Box < dyn Fn ( & panic:: PanicInfo < ' _ > ) + Sync + Send + ' static > > =
17- SyncLazy :: new ( || {
18- let hook = panic:: take_hook ( ) ;
19- panic:: set_hook ( Box :: new ( |info| {
20- // Invoke the default handler, which prints the actual panic message and
21- // optionally a backtrace. This also prints Rustc's "file a bug here" message:
22- // it seems like the only way to remove that is to use rustc_driver::report_ice;
23- // however, adding that dependency to this crate causes a circular dependency.
24- // For now, just print our message after the Rust one and explicitly point to
25- // our bug template form.
26- ( * DEFAULT_HOOK ) ( info) ;
24+ // Custom panic hook.
25+ pub static DEFAULT_HOOK : SyncLazy < Box < dyn Fn ( & panic:: PanicInfo < ' _ > ) + Sync + Send + ' static > > =
26+ SyncLazy :: new ( || {
27+ let hook = panic:: take_hook ( ) ;
28+ panic:: set_hook ( Box :: new ( |info| {
29+ // Invoke the default handler, which prints the actual panic message and
30+ // optionally a backtrace. This also prints Rustc's "file a bug here" message:
31+ // it seems like the only way to remove that is to use rustc_driver::report_ice;
32+ // however, adding that dependency to this crate causes a circular dependency.
33+ // For now, just print our message after the Rust one and explicitly point to
34+ // our bug template form.
35+ ( * DEFAULT_HOOK ) ( info) ;
2736
28- // Separate the output with an empty line
29- eprintln ! ( ) ;
37+ // Separate the output with an empty line
38+ eprintln ! ( ) ;
3039
31- // Print the current function if available
32- CURRENT_CODEGEN_ITEM . with ( |cell| {
33- if let Some ( current_item) = cell. borrow ( ) . clone ( ) {
34- eprintln ! ( "[RMC] current codegen item: {}" , current_item) ;
35- } else {
36- eprintln ! ( "[RMC] no current codegen item." ) ;
37- }
38- } ) ;
40+ // Print the current function if available
41+ CURRENT_CODEGEN_ITEM . with ( |cell| {
42+ if let Some ( current_item) = cell. borrow ( ) . clone ( ) {
43+ eprintln ! ( "[RMC] current codegen item: {}" , current_item) ;
44+ } else {
45+ eprintln ! ( "[RMC] no current codegen item." ) ;
46+ }
47+ } ) ;
3948
40- // Separate the output with an empty line
41- eprintln ! ( ) ;
49+ // Separate the output with an empty line
50+ eprintln ! ( ) ;
4251
43- // Print the RMC message
44- eprintln ! ( "RMC unexpectedly panicked during code generation.\n " ) ;
45- eprintln ! (
46- "If you are seeing this message, please file an issue here instead of on the Rust compiler: {}" ,
47- BUG_REPORT_URL
48- ) ;
49- } ) ) ;
50- hook
51- } ) ;
52+ // Print the RMC message
53+ eprintln ! ( "RMC unexpectedly panicked during code generation.\n " ) ;
54+ eprintln ! (
55+ "If you are seeing this message, please file an issue here instead of on the Rust compiler: {}" ,
56+ BUG_REPORT_URL
57+ ) ;
58+ } ) ) ;
59+ hook
60+ } ) ;
5261
5362impl < ' tcx > GotocCtx < ' tcx > {
5463 // Calls the closure while updating the tracked global variable marking the
@@ -65,7 +74,7 @@ impl<'tcx> GotocCtx<'tcx> {
6574 } ) ;
6675 }
6776
68- fn print_instance ( & self , instance : Instance < ' _ > , mir : & ' tcx Body < ' tcx > ) {
77+ pub fn print_instance ( & self , instance : Instance < ' _ > , mir : & ' tcx Body < ' tcx > ) {
6978 if cfg ! ( debug_assertions) {
7079 debug ! (
7180 "handling {}, {}" ,
@@ -85,5 +94,4 @@ impl<'tcx> GotocCtx<'tcx> {
8594 }
8695 }
8796 }
88-
8997}
0 commit comments