Auto merge of #2295 - RalfJung:better-alloc-tracking, r=RalfJung
allocation tracking: also print size, alignment, kind of the allocation
This commit is contained in:
commit
f9e0cf4951
@ -6,6 +6,7 @@
|
||||
|
||||
use rustc_middle::ty;
|
||||
use rustc_span::{source_map::DUMMY_SP, Span, SpanData, Symbol};
|
||||
use rustc_target::abi::{Align, Size};
|
||||
|
||||
use crate::helpers::HexRange;
|
||||
use crate::stacked_borrows::{diagnostics::TagHistory, AccessKind};
|
||||
@ -71,7 +72,7 @@ pub enum NonHaltingDiagnostic {
|
||||
/// a deallocation when the second argument is `None`.
|
||||
PoppedPointerTag(Item, Option<(SbTagExtra, AccessKind)>),
|
||||
CreatedCallId(CallId),
|
||||
CreatedAlloc(AllocId),
|
||||
CreatedAlloc(AllocId, Size, Align, MemoryKind<MiriMemoryKind>),
|
||||
FreedAlloc(AllocId),
|
||||
RejectedIsolatedOp(String),
|
||||
ProgressReport,
|
||||
@ -463,7 +464,8 @@ fn process_diagnostics(&self, info: TopFrameInfo<'tcx>) {
|
||||
}
|
||||
},
|
||||
CreatedCallId(id) => format!("function call with id {id}"),
|
||||
CreatedAlloc(AllocId(id)) => format!("created allocation with id {id}"),
|
||||
CreatedAlloc(AllocId(id), size, align, kind) =>
|
||||
format!("created {kind} allocation of {} bytes (alignment {} bytes) with id {id}", size.bytes(), align.bytes()),
|
||||
FreedAlloc(AllocId(id)) => format!("freed allocation with id {id}"),
|
||||
RejectedIsolatedOp(ref op) =>
|
||||
format!("{op} was made to return an error due to isolation"),
|
||||
|
@ -624,11 +624,16 @@ fn init_allocation_extra<'b>(
|
||||
alloc: Cow<'b, Allocation>,
|
||||
kind: Option<MemoryKind<Self::MemoryKind>>,
|
||||
) -> InterpResult<'tcx, Cow<'b, Allocation<Self::PointerTag, Self::AllocExtra>>> {
|
||||
let kind = kind.expect("we set our STATIC_KIND so this cannot be None");
|
||||
if ecx.machine.tracked_alloc_ids.contains(&id) {
|
||||
register_diagnostic(NonHaltingDiagnostic::CreatedAlloc(id));
|
||||
register_diagnostic(NonHaltingDiagnostic::CreatedAlloc(
|
||||
id,
|
||||
alloc.size(),
|
||||
alloc.align,
|
||||
kind,
|
||||
));
|
||||
}
|
||||
|
||||
let kind = kind.expect("we set our STATIC_KIND so this cannot be None");
|
||||
let alloc = alloc.into_owned();
|
||||
let stacks = if let Some(stacked_borrows) = &ecx.machine.stacked_borrows {
|
||||
Some(Stacks::new_allocation(
|
||||
|
@ -2,4 +2,5 @@
|
||||
// Early allocations are probably part of the runtime and therefore uninteresting, but they
|
||||
// shouldn't cause a crash.
|
||||
// compile-flags: -Zmiri-track-alloc-id=1
|
||||
// normalize-stderr-test: "[48] bytes" -> "SIZE bytes"
|
||||
fn main() {}
|
||||
|
@ -1,5 +1,5 @@
|
||||
note: tracking was triggered
|
||||
|
|
||||
= note: created allocation with id 1
|
||||
= note: created extern static allocation of SIZE bytes (alignment ALIGN bytes) with id 1
|
||||
= note: (no span available)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user