Skip to content

Commit 8630d86

Browse files
committed
Added support for multiple tracked pointers
- Changed arg parsing to handle comma seperated list of `u64`. - Changed type and field names of config and global state to hold a set of tracked ids. - Adjusted Readme
1 parent 598ae74 commit 8630d86

File tree

5 files changed

+28
-24
lines changed

5 files changed

+28
-24
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ environment variable:
320320
* `-Zmiri-track-call-id=<id>` shows a backtrace when the given call id is
321321
assigned to a stack frame. This helps in debugging UB related to Stacked
322322
Borrows "protectors".
323-
* `-Zmiri-track-pointer-tag=<tag>` shows a backtrace when the given pointer tag
323+
* `-Zmiri-track-pointer-tag=<tag-list>` shows a backtrace when a given pointer tag
324324
is popped from a borrow stack (which is where the tag becomes invalid and any
325325
future use of it will error). This helps you in finding out why UB is
326326
happening and where in your code would be a good place to look for it.

src/bin/miri.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -397,19 +397,20 @@ fn main() {
397397
.push(arg.strip_prefix("-Zmiri-env-forward=").unwrap().to_owned());
398398
}
399399
arg if arg.starts_with("-Zmiri-track-pointer-tag=") => {
400-
let id: u64 =
401-
match arg.strip_prefix("-Zmiri-track-pointer-tag=").unwrap().parse() {
402-
Ok(id) => id,
403-
Err(err) =>
404-
panic!(
405-
"-Zmiri-track-pointer-tag requires a valid `u64` argument: {}",
406-
err
407-
),
408-
};
409-
if let Some(id) = miri::PtrId::new(id) {
410-
miri_config.tracked_pointer_tag = Some(id);
411-
} else {
412-
panic!("-Zmiri-track-pointer-tag requires a nonzero argument");
400+
let ids: Vec<u64> = match arg.strip_prefix("-Zmiri-track-pointer-tag=").unwrap().split(',').map(|id| id.parse::<u64>()).collect() {
401+
Ok(ids) => ids,
402+
Err(err) =>
403+
panic!(
404+
"-Zmiri-track-pointer-tag requires a comma seperated list of valid `u64` arguments: {}",
405+
err
406+
),
407+
};
408+
for id in ids.into_iter().map(miri::PtrId::new) {
409+
if let Some(id) = id {
410+
miri_config.tracked_pointer_tags.insert(id);
411+
} else {
412+
panic!("-Zmiri-track-pointer-tag requires nonzero arguments");
413+
}
413414
}
414415
}
415416
arg if arg.starts_with("-Zmiri-track-call-id=") => {

src/eval.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ use rustc_target::spec::abi::Abi;
1515

1616
use rustc_session::config::EntryFnType;
1717

18+
use std::collections::HashSet;
19+
1820
use crate::*;
1921

2022
#[derive(Copy, Clone, Debug, PartialEq)]
@@ -91,8 +93,8 @@ pub struct MiriConfig {
9193
pub args: Vec<String>,
9294
/// The seed to use when non-determinism or randomness are required (e.g. ptr-to-int cast, `getrandom()`).
9395
pub seed: Option<u64>,
94-
/// The stacked borrows pointer id to report about
95-
pub tracked_pointer_tag: Option<PtrId>,
96+
/// The stacked borrows pointer ids to report about
97+
pub tracked_pointer_tags: HashSet<PtrId>,
9698
/// The stacked borrows call ID to report about
9799
pub tracked_call_id: Option<CallId>,
98100
/// The allocation id to report about.
@@ -130,7 +132,7 @@ impl Default for MiriConfig {
130132
forwarded_env_vars: vec![],
131133
args: vec![],
132134
seed: None,
133-
tracked_pointer_tag: None,
135+
tracked_pointer_tags: Default::default(),
134136
tracked_call_id: None,
135137
tracked_alloc_id: None,
136138
tag_raw: false,

src/machine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ impl<'mir, 'tcx> Evaluator<'mir, 'tcx> {
303303
let rng = StdRng::seed_from_u64(config.seed.unwrap_or(0));
304304
let stacked_borrows = if config.stacked_borrows {
305305
Some(RefCell::new(stacked_borrows::GlobalStateInner::new(
306-
config.tracked_pointer_tag,
306+
config.tracked_pointer_tags.clone(),
307307
config.tracked_call_id,
308308
config.tag_raw,
309309
)))

src/stacked_borrows.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use rustc_middle::ty::{
1515
};
1616
use rustc_span::DUMMY_SP;
1717
use rustc_target::abi::Size;
18+
use std::collections::HashSet;
1819

1920
use crate::*;
2021

@@ -104,8 +105,8 @@ pub struct GlobalStateInner {
104105
next_call_id: CallId,
105106
/// Those call IDs corresponding to functions that are still running.
106107
active_calls: FxHashSet<CallId>,
107-
/// The pointer id to trace
108-
tracked_pointer_tag: Option<PtrId>,
108+
/// The pointer ids to trace
109+
tracked_pointer_tags: HashSet<PtrId>,
109110
/// The call id to trace
110111
tracked_call_id: Option<CallId>,
111112
/// Whether to track raw pointers.
@@ -158,7 +159,7 @@ impl fmt::Display for RefKind {
158159
/// Utilities for initialization and ID generation
159160
impl GlobalStateInner {
160161
pub fn new(
161-
tracked_pointer_tag: Option<PtrId>,
162+
tracked_pointer_tags: HashSet<PtrId>,
162163
tracked_call_id: Option<CallId>,
163164
tag_raw: bool,
164165
) -> Self {
@@ -167,15 +168,15 @@ impl GlobalStateInner {
167168
base_ptr_ids: FxHashMap::default(),
168169
next_call_id: NonZeroU64::new(1).unwrap(),
169170
active_calls: FxHashSet::default(),
170-
tracked_pointer_tag,
171+
tracked_pointer_tags,
171172
tracked_call_id,
172173
tag_raw,
173174
}
174175
}
175176

176177
fn new_ptr(&mut self) -> PtrId {
177178
let id = self.next_ptr_id;
178-
if Some(id) == self.tracked_pointer_tag {
179+
if self.tracked_pointer_tags.contains(&id) {
179180
register_diagnostic(NonHaltingDiagnostic::CreatedPointerTag(id));
180181
}
181182
self.next_ptr_id = NonZeroU64::new(id.get() + 1).unwrap();
@@ -311,7 +312,7 @@ impl<'tcx> Stack {
311312
global: &GlobalStateInner,
312313
) -> InterpResult<'tcx> {
313314
if let SbTag::Tagged(id) = item.tag {
314-
if Some(id) == global.tracked_pointer_tag {
315+
if global.tracked_pointer_tags.contains(&id) {
315316
register_diagnostic(NonHaltingDiagnostic::PoppedPointerTag(
316317
item.clone(),
317318
provoking_access,

0 commit comments

Comments
 (0)