Skip to content

Commit f51f923

Browse files
committed
Auto merge of rust-lang#3348 - RalfJung:miri-thread-logging, r=RalfJung
log when we change the active thread, and fix logging for concurrency Also avoid relying on the incorrect scope exit logging produced by tracing (Cc rust-lang/miri#2266)
2 parents 639fab7 + 983c2c5 commit f51f923

File tree

3 files changed

+32
-14
lines changed

3 files changed

+32
-14
lines changed

src/tools/miri/src/bin/miri.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,16 +202,12 @@ fn rustc_logger_config() -> rustc_log::LoggerConfig {
202202
// rustc traced, but you can also do `MIRI_LOG=miri=trace,rustc_const_eval::interpret=debug`.
203203
if tracing::Level::from_str(&var).is_ok() {
204204
cfg.filter = Ok(format!(
205-
"rustc_middle::mir::interpret={var},rustc_const_eval::interpret={var}"
205+
"rustc_middle::mir::interpret={var},rustc_const_eval::interpret={var},miri={var}"
206206
));
207207
} else {
208208
cfg.filter = Ok(var);
209209
}
210210
}
211-
// Enable verbose entry/exit logging by default if MIRI_LOG is set.
212-
if matches!(cfg.verbose_entry_exit, Err(VarError::NotPresent)) {
213-
cfg.verbose_entry_exit = Ok(format!("1"));
214-
}
215211
}
216212

217213
cfg

src/tools/miri/src/concurrency/thread.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -445,10 +445,13 @@ impl<'mir, 'tcx: 'mir> ThreadManager<'mir, 'tcx> {
445445

446446
/// Set an active thread and return the id of the thread that was active before.
447447
fn set_active_thread_id(&mut self, id: ThreadId) -> ThreadId {
448-
let active_thread_id = self.active_thread;
449-
self.active_thread = id;
450-
assert!(self.active_thread.index() < self.threads.len());
451-
active_thread_id
448+
assert!(id.index() < self.threads.len());
449+
info!(
450+
"---------- Now executing on thread `{}` (previous: `{}`) ----------------------------------------",
451+
self.get_thread_display_name(id),
452+
self.get_thread_display_name(self.active_thread)
453+
);
454+
std::mem::replace(&mut self.active_thread, id)
452455
}
453456

454457
/// Get the id of the currently active thread.
@@ -735,6 +738,11 @@ impl<'mir, 'tcx: 'mir> ThreadManager<'mir, 'tcx> {
735738
for (id, thread) in threads {
736739
debug_assert_ne!(self.active_thread, id);
737740
if thread.state == ThreadState::Enabled {
741+
info!(
742+
"---------- Now executing on thread `{}` (previous: `{}`) ----------------------------------------",
743+
self.get_thread_display_name(id),
744+
self.get_thread_display_name(self.active_thread)
745+
);
738746
self.active_thread = id;
739747
break;
740748
}

src/tools/miri/src/machine.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,13 +1454,17 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
14541454
if ecx.machine.borrow_tracker.is_some() {
14551455
ecx.on_stack_pop(frame)?;
14561456
}
1457+
// tracing-tree can autoamtically annotate scope changes, but it gets very confused by our
1458+
// concurrency and what it prints is just plain wrong. So we print our own information
1459+
// instead. (Cc https://github.com/rust-lang/miri/issues/2266)
1460+
info!("Leaving {}", ecx.frame().instance);
14571461
Ok(())
14581462
}
14591463

14601464
#[inline(always)]
14611465
fn after_stack_pop(
14621466
ecx: &mut InterpCx<'mir, 'tcx, Self>,
1463-
mut frame: Frame<'mir, 'tcx, Provenance, FrameExtra<'tcx>>,
1467+
frame: Frame<'mir, 'tcx, Provenance, FrameExtra<'tcx>>,
14641468
unwinding: bool,
14651469
) -> InterpResult<'tcx, StackPopJump> {
14661470
if frame.extra.is_user_relevant {
@@ -1470,10 +1474,20 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
14701474
// user-relevant frame and restore that here.)
14711475
ecx.active_thread_mut().recompute_top_user_relevant_frame();
14721476
}
1473-
let timing = frame.extra.timing.take();
1474-
let res = ecx.handle_stack_pop_unwind(frame.extra, unwinding);
1475-
if let Some(profiler) = ecx.machine.profiler.as_ref() {
1476-
profiler.finish_recording_interval_event(timing.unwrap());
1477+
let res = {
1478+
// Move `frame`` into a sub-scope so we control when it will be dropped.
1479+
let mut frame = frame;
1480+
let timing = frame.extra.timing.take();
1481+
let res = ecx.handle_stack_pop_unwind(frame.extra, unwinding);
1482+
if let Some(profiler) = ecx.machine.profiler.as_ref() {
1483+
profiler.finish_recording_interval_event(timing.unwrap());
1484+
}
1485+
res
1486+
};
1487+
// Needs to be done after dropping frame to show up on the right nesting level.
1488+
// (Cc https://github.com/rust-lang/miri/issues/2266)
1489+
if !ecx.active_thread_stack().is_empty() {
1490+
info!("Continuing in {}", ecx.frame().instance);
14771491
}
14781492
res
14791493
}

0 commit comments

Comments
 (0)