Skip to content

Commit 5cf7ed1

Browse files
committed
show where the interpreter was interpreting when an ICE occurs
1 parent 9dba78a commit 5cf7ed1

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

src/diagnostics.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,4 +505,22 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
505505
}
506506
});
507507
}
508+
509+
/// We had a panic in Miri itself, try to print something useful.
510+
fn handle_ice(&self) {
511+
eprintln!();
512+
eprintln!(
513+
"Miri caused an ICE during evaluation. Here's the interpreter backtrace at the time of the panic:"
514+
);
515+
let this = self.eval_context_ref();
516+
let stacktrace = this.generate_stacktrace();
517+
report_msg(
518+
this,
519+
DiagLevel::Note,
520+
"the place in the program where the ICE was triggered",
521+
vec![],
522+
vec![],
523+
&stacktrace,
524+
);
525+
}
508526
}

src/eval.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
//! Main evaluator loop and setting up the initial stack frame.
22
3+
use std::collections::HashSet;
34
use std::ffi::OsStr;
45
use std::iter;
6+
use std::panic::{self, AssertUnwindSafe};
7+
use std::thread;
58

69
use log::info;
710

@@ -15,8 +18,6 @@ use rustc_target::spec::abi::Abi;
1518

1619
use rustc_session::config::EntryFnType;
1720

18-
use std::collections::HashSet;
19-
2021
use crate::*;
2122

2223
#[derive(Copy, Clone, Debug, PartialEq)]
@@ -332,7 +333,7 @@ pub fn eval_entry<'tcx>(
332333
};
333334

334335
// Perform the main execution.
335-
let res: InterpResult<'_, i64> = (|| {
336+
let res: thread::Result<InterpResult<'_, i64>> = panic::catch_unwind(AssertUnwindSafe(|| {
336337
// Main loop.
337338
loop {
338339
let info = ecx.preprocess_diagnostics();
@@ -362,7 +363,11 @@ pub fn eval_entry<'tcx>(
362363
}
363364
let return_code = ecx.read_scalar(&ret_place.into())?.to_machine_isize(&ecx)?;
364365
Ok(return_code)
365-
})();
366+
}));
367+
let res = res.unwrap_or_else(|panic_payload| {
368+
ecx.handle_ice();
369+
panic::resume_unwind(panic_payload)
370+
});
366371

367372
// Machine cleanup.
368373
// Execution of the program has halted so any memory access we do here

0 commit comments

Comments
 (0)