Skip to content

Commit 7e0783f

Browse files
committed
alloc access tracking: print accessed range
1 parent 8fef16e commit 7e0783f

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

src/tools/miri/src/diagnostics.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ pub enum NonHaltingDiagnostic {
128128
PoppedPointerTag(Item, String),
129129
TrackingAlloc(AllocId, Size, Align),
130130
FreedAlloc(AllocId),
131-
AccessedAlloc(AllocId, AccessKind),
131+
AccessedAlloc(AllocId, AllocRange, AccessKind),
132132
RejectedIsolatedOp(String),
133133
ProgressReport {
134134
block_count: u64, // how many basic blocks have been run so far
@@ -673,15 +673,15 @@ impl<'tcx> MiriMachine<'tcx> {
673673
"created tag {tag:?} with {perm} at {alloc_id:?}{range:?} derived from {orig_tag:?}"
674674
),
675675
PoppedPointerTag(item, cause) => format!("popped tracked tag for item {item:?}{cause}"),
676-
TrackingAlloc(AllocId(id), size, align) =>
676+
TrackingAlloc(id, size, align) =>
677677
format!(
678-
"now tracking allocation of {size} bytes (alignment {align} bytes) with id {id}",
678+
"now tracking allocation {id:?} of {size} bytes (alignment {align} bytes)",
679679
size = size.bytes(),
680680
align = align.bytes(),
681681
),
682-
AccessedAlloc(AllocId(id), access_kind) =>
683-
format!("{access_kind} to allocation with id {id}"),
684-
FreedAlloc(AllocId(id)) => format!("freed allocation with id {id}"),
682+
AccessedAlloc(id, range, access_kind) =>
683+
format!("{access_kind} at {id:?}[{}..{}]", range.start.bytes(), range.end().bytes()),
684+
FreedAlloc(id) => format!("freed allocation {id:?}"),
685685
RejectedIsolatedOp(op) => format!("{op} was made to return an error due to isolation"),
686686
ProgressReport { .. } =>
687687
format!("progress report: current operation being executed is here"),

src/tools/miri/src/machine.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,8 +1523,11 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
15231523
range: AllocRange,
15241524
) -> InterpResult<'tcx> {
15251525
if machine.track_alloc_accesses && machine.tracked_alloc_ids.contains(&alloc_id) {
1526-
machine
1527-
.emit_diagnostic(NonHaltingDiagnostic::AccessedAlloc(alloc_id, AccessKind::Read));
1526+
machine.emit_diagnostic(NonHaltingDiagnostic::AccessedAlloc(
1527+
alloc_id,
1528+
range,
1529+
AccessKind::Read,
1530+
));
15281531
}
15291532
// The order of checks is deliberate, to prefer reporting a data race over a borrow tracker error.
15301533
match &machine.data_race {
@@ -1559,8 +1562,11 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
15591562
range: AllocRange,
15601563
) -> InterpResult<'tcx> {
15611564
if machine.track_alloc_accesses && machine.tracked_alloc_ids.contains(&alloc_id) {
1562-
machine
1563-
.emit_diagnostic(NonHaltingDiagnostic::AccessedAlloc(alloc_id, AccessKind::Write));
1565+
machine.emit_diagnostic(NonHaltingDiagnostic::AccessedAlloc(
1566+
alloc_id,
1567+
range,
1568+
AccessKind::Write,
1569+
));
15641570
}
15651571
match &machine.data_race {
15661572
GlobalDataRaceHandler::None => {}

src/tools/miri/tests/pass/alloc-access-tracking.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
note: now tracking allocation of 123 bytes (alignment ALIGN bytes) with id $ALLOC
1+
note: now tracking allocation ALLOC of 123 bytes (alignment ALIGN bytes)
22
--> tests/pass/alloc-access-tracking.rs:LL:CC
33
|
44
LL | utils::miri_track_alloc(ptr);
@@ -7,7 +7,7 @@ LL | utils::miri_track_alloc(ptr);
77
= note: BACKTRACE:
88
= note: inside `main` at tests/pass/alloc-access-tracking.rs:LL:CC
99

10-
note: write access to allocation with id $ALLOC
10+
note: write access at ALLOC[0..1]
1111
--> tests/pass/alloc-access-tracking.rs:LL:CC
1212
|
1313
LL | *ptr = 42; // Crucially, only a write is printed here, no read!
@@ -16,7 +16,7 @@ LL | *ptr = 42; // Crucially, only a write is printed here, no read!
1616
= note: BACKTRACE:
1717
= note: inside `main` at tests/pass/alloc-access-tracking.rs:LL:CC
1818

19-
note: read access to allocation with id $ALLOC
19+
note: read access at ALLOC[0..1]
2020
--> tests/pass/alloc-access-tracking.rs:LL:CC
2121
|
2222
LL | assert_eq!(*ptr, 42);
@@ -26,7 +26,7 @@ LL | assert_eq!(*ptr, 42);
2626
= note: inside `main` at RUSTLIB/core/src/macros/mod.rs:LL:CC
2727
= note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
2828

29-
note: freed allocation with id $ALLOC
29+
note: freed allocation ALLOC
3030
--> RUSTLIB/alloc/src/boxed.rs:LL:CC
3131
|
3232
LL | self.1.deallocate(From::from(ptr.cast()), layout);

0 commit comments

Comments
 (0)