mirror of
https://github.com/rust-lang/rust.git
synced 2026-06-02 06:28:20 +03:00
make the new option actually do something
This commit is contained in:
@@ -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=<id>` shows a backtrace when the given allocation is
|
||||
being allocated. This helps in debugging memory leaks.
|
||||
|
||||
Moreover, Miri recognizes some environment variables:
|
||||
|
||||
|
||||
+5
-1
@@ -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);
|
||||
}
|
||||
|
||||
@@ -334,6 +334,10 @@ fn init_allocation_extra<'b>(
|
||||
alloc: Cow<'b, Allocation>,
|
||||
kind: Option<MemoryKind<Self::MemoryKinds>>,
|
||||
) -> (Cow<'b, Allocation<Self::PointerTag, Self::AllocExtra>>, 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) =
|
||||
|
||||
Reference in New Issue
Block a user