Skip to content

Commit 648d5bc

Browse files
authored
Rollup merge of rust-lang#96160 - RalfJung:interpret-debug, r=oli-obk
Miri/interpreter debugging tweaks Some changes I made to make debugging Miri with trace logging less terrible. r? `@oli-obk`
2 parents 20b927a + f3bdcfb commit 648d5bc

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

compiler/rustc_const_eval/src/interpret/eval_context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
679679
return_place: Option<&PlaceTy<'tcx, M::PointerTag>>,
680680
return_to_block: StackPopCleanup,
681681
) -> InterpResult<'tcx> {
682-
debug!("body: {:#?}", body);
682+
trace!("body: {:#?}", body);
683683
// first push a stack frame so we have access to the local substs
684684
let pre_frame = Frame {
685685
body,
@@ -836,7 +836,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
836836
return Ok(());
837837
}
838838

839-
debug!("locals: {:#?}", frame.locals);
839+
trace!("locals: {:#?}", frame.locals);
840840

841841
// Cleanup: deallocate all locals that are backed by an allocation.
842842
for local in &frame.locals {

compiler/rustc_const_eval/src/interpret/memory.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -870,9 +870,17 @@ impl<'tcx, 'a, Tag: Provenance, Extra> AllocRefMut<'a, 'tcx, Tag, Extra> {
870870
range: AllocRange,
871871
val: ScalarMaybeUninit<Tag>,
872872
) -> InterpResult<'tcx> {
873+
let range = self.range.subrange(range);
874+
debug!(
875+
"write_scalar in {} at {:#x}, size {}: {:?}",
876+
self.alloc_id,
877+
range.start.bytes(),
878+
range.size.bytes(),
879+
val
880+
);
873881
Ok(self
874882
.alloc
875-
.write_scalar(&self.tcx, self.range.subrange(range), val)
883+
.write_scalar(&self.tcx, range, val)
876884
.map_err(|e| e.to_interp_error(self.alloc_id))?)
877885
}
878886

@@ -895,10 +903,19 @@ impl<'tcx, 'a, Tag: Provenance, Extra> AllocRefMut<'a, 'tcx, Tag, Extra> {
895903

896904
impl<'tcx, 'a, Tag: Provenance, Extra> AllocRef<'a, 'tcx, Tag, Extra> {
897905
pub fn read_scalar(&self, range: AllocRange) -> InterpResult<'tcx, ScalarMaybeUninit<Tag>> {
898-
Ok(self
906+
let range = self.range.subrange(range);
907+
let res = self
899908
.alloc
900-
.read_scalar(&self.tcx, self.range.subrange(range))
901-
.map_err(|e| e.to_interp_error(self.alloc_id))?)
909+
.read_scalar(&self.tcx, range)
910+
.map_err(|e| e.to_interp_error(self.alloc_id))?;
911+
debug!(
912+
"read_scalar in {} at {:#x}, size {}: {:?}",
913+
self.alloc_id,
914+
range.start.bytes(),
915+
range.size.bytes(),
916+
res
917+
);
918+
Ok(res)
902919
}
903920

904921
pub fn read_ptr_sized(&self, offset: Size) -> InterpResult<'tcx, ScalarMaybeUninit<Tag>> {

compiler/rustc_middle/src/mir/interpret/allocation.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,9 @@ impl<Tag: Copy, Extra> Allocation<Tag, Extra> {
515515
if Tag::ERR_ON_PARTIAL_PTR_OVERWRITE {
516516
return Err(AllocError::PartialPointerOverwrite(first));
517517
}
518+
warn!(
519+
"Partial pointer overwrite! De-initializing memory at offsets {first:?}..{start:?}."
520+
);
518521
self.init_mask.set_range(first, start, false);
519522
}
520523
if last > end {
@@ -523,10 +526,15 @@ impl<Tag: Copy, Extra> Allocation<Tag, Extra> {
523526
last - cx.data_layout().pointer_size,
524527
));
525528
}
529+
warn!(
530+
"Partial pointer overwrite! De-initializing memory at offsets {end:?}..{last:?}."
531+
);
526532
self.init_mask.set_range(end, last, false);
527533
}
528534

529535
// Forget all the relocations.
536+
// Since relocations do not overlap, we know that removing until `last` (exclusive) is fine,
537+
// i.e., this will not remove any other relocations just after the ones we care about.
530538
self.relocations.0.remove_range(first..last);
531539

532540
Ok(())

0 commit comments

Comments
 (0)