From ade4c4e7331fcff40643c1666ca89078b84b125a Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 6 Mar 2020 09:11:41 +0100 Subject: [PATCH] make the new option actually do something --- README.md | 2 ++ src/diagnostics.rs | 6 +++++- src/machine.rs | 4 ++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f18a5d668c3..839facef096 100644 --- a/README.md +++ b/README.md @@ -180,6 +180,8 @@ Several `-Z` flags are relevant for Miri: is popped from a borrow stack (which is where the tag becomes invalid and any future use of it will error). This helps you in finding out why UB is happening and where in your code would be a good place to look for it. +* `-Zmiri-track-alloc-id=` shows a backtrace when the given allocation is + being allocated. This helps in debugging memory leaks. Moreover, Miri recognizes some environment variables: diff --git a/src/diagnostics.rs b/src/diagnostics.rs index e68dfad1b9f..fb6598495af 100644 --- a/src/diagnostics.rs +++ b/src/diagnostics.rs @@ -6,6 +6,7 @@ /// Miri specific diagnostics pub enum NonHaltingDiagnostic { PoppedTrackedPointerTag(Item), + CreatedAlloc(AllocId), } /// Emit a custom diagnostic without going through the miri-engine machinery @@ -97,9 +98,12 @@ fn process_diagnostics(&self) { let this = self.eval_context_ref(); DIAGNOSTICS.with(|diagnostics| { for e in diagnostics.borrow_mut().drain(..) { + use NonHaltingDiagnostic::*; let msg = match e { - NonHaltingDiagnostic::PoppedTrackedPointerTag(item) => + PoppedTrackedPointerTag(item) => format!("popped tracked tag for item {:?}", item), + CreatedAlloc(AllocId(id)) => + format!("created allocation with id {}", id), }; report_msg(this, msg, false); } diff --git a/src/machine.rs b/src/machine.rs index 07885148e1f..d15e290cbfd 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -334,6 +334,10 @@ fn init_allocation_extra<'b>( alloc: Cow<'b, Allocation>, kind: Option>, ) -> (Cow<'b, Allocation>, Self::PointerTag) { + if Some(id) == memory_extra.tracked_alloc_id { + register_diagnostic(NonHaltingDiagnostic::CreatedAlloc(id)); + } + let kind = kind.expect("we set our STATIC_KIND so this cannot be None"); let alloc = alloc.into_owned(); let (stacks, base_tag) = -- 2.44.0