Skip to content

Commit a401a45

Browse files
committed
Print a backtrace in const eval if interrupted
1 parent 9ad2f34 commit a401a45

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

src/bin/miri.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,10 @@ fn main() {
344344
let args = rustc_driver::args::raw_args(&early_dcx)
345345
.unwrap_or_else(|_| std::process::exit(rustc_driver::EXIT_FAILURE));
346346

347+
// Install the ctrlc handler that sets `rustc_const_eval::CTRL_C_RECEIVED`, even if
348+
// MIRI_BE_RUSTC is set.
349+
rustc_driver::install_ctrlc_handler();
350+
347351
// If the environment asks us to actually be rustc, then do that.
348352
if let Some(crate_kind) = env::var_os("MIRI_BE_RUSTC") {
349353
// Earliest rustc setup.

src/concurrency/thread.rs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
use std::cell::RefCell;
44
use std::collections::hash_map::Entry;
55
use std::num::TryFromIntError;
6-
use std::sync::atomic::{AtomicBool, Ordering::Relaxed};
6+
use std::sync::atomic::Ordering::Relaxed;
77
use std::task::Poll;
88
use std::time::{Duration, SystemTime};
99

1010
use either::Either;
1111

12+
use rustc_const_eval::CTRL_C_RECEIVED;
1213
use rustc_data_structures::fx::FxHashMap;
1314
use rustc_hir::def_id::DefId;
1415
use rustc_index::{Idx, IndexVec};
@@ -1045,21 +1046,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
10451046
/// Run the core interpreter loop. Returns only when an interrupt occurs (an error or program
10461047
/// termination).
10471048
fn run_threads(&mut self) -> InterpResult<'tcx, !> {
1048-
static SIGNALED: AtomicBool = AtomicBool::new(false);
1049-
ctrlc::set_handler(move || {
1050-
// Indicate that we have ben signaled to stop. If we were already signaled, exit
1051-
// immediately. In our interpreter loop we try to consult this value often, but if for
1052-
// whatever reason we don't get to that check or the cleanup we do upon finding that
1053-
// this bool has become true takes a long time, the exit here will promptly exit the
1054-
// process on the second Ctrl-C.
1055-
if SIGNALED.swap(true, Relaxed) {
1056-
std::process::exit(1);
1057-
}
1058-
})
1059-
.unwrap();
1060-
let this = self.eval_context_mut();
1049+
let this = self.eval_context_mut();
10611050
loop {
1062-
if SIGNALED.load(Relaxed) {
1051+
if CTRL_C_RECEIVED.load(Relaxed) {
10631052
this.machine.handle_abnormal_termination();
10641053
std::process::exit(1);
10651054
}

0 commit comments

Comments
 (0)