Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7091be5

Browse files
committedAug 28, 2022
Implement a crude stack printing mechanism
1 parent fec1c7a commit 7091be5

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed
 

‎src/range_map.rs

+4
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ impl<T> RangeMap<T> {
9191
self.v.iter_mut().map(|elem| &mut elem.data)
9292
}
9393

94+
pub fn iter_all(&self) -> impl Iterator<Item = (ops::Range<u64>, &T)> {
95+
self.v.iter().map(|elem| (elem.range.clone(), &elem.data))
96+
}
97+
9498
// Splits the element situated at the given `index`, such that the 2nd one starts at offset
9599
// `split_offset`. Do nothing if the element already starts there.
96100
// Returns whether a split was necessary.

‎src/shims/foreign_items.rs

+13
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,19 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
416416
// shim, add it to the corresponding submodule.
417417
match link_name.as_str() {
418418
// Miri-specific extern functions
419+
"miri_get_alloc_id" => {
420+
let [ptr] = this.check_shim(abi, Abi::Rust, link_name, args)?;
421+
let ptr = this.read_pointer(ptr)?;
422+
let (alloc_id, _, _) = this.ptr_get_alloc_id(ptr)?;
423+
this.write_scalar(Scalar::from_u64(alloc_id.0.get()), dest)?;
424+
}
425+
"miri_print_stacks" => {
426+
let [id] = this.check_shim(abi, Abi::Rust, link_name, args)?;
427+
let id = this.read_scalar(id)?.to_u64()?;
428+
if let Some(id) = std::num::NonZeroU64::new(id) {
429+
this.print_stacks(AllocId(id))?;
430+
}
431+
}
419432
"miri_static_root" => {
420433
let [ptr] = this.check_shim(abi, Abi::Rust, link_name, args)?;
421434
let ptr = this.read_pointer(ptr)?;

‎src/stacked_borrows/mod.rs

+15
Original file line numberDiff line numberDiff line change
@@ -1050,4 +1050,19 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
10501050
}
10511051
Ok(())
10521052
}
1053+
1054+
fn print_stacks(&mut self, alloc_id: AllocId) -> InterpResult<'tcx> {
1055+
let this = self.eval_context_mut();
1056+
let alloc_extra = this.get_alloc_extra(alloc_id)?;
1057+
let stacks = alloc_extra.stacked_borrows.as_ref().unwrap().borrow();
1058+
for (range, stack) in stacks.stacks.iter_all() {
1059+
print!("{:?}: [", range);
1060+
for i in 0..stack.len() {
1061+
let item = stack.get(i).unwrap();
1062+
print!(" {:?}{:?}", item.perm(), item.tag());
1063+
}
1064+
println!(" ]");
1065+
}
1066+
Ok(())
1067+
}
10531068
}

0 commit comments

Comments
 (0)
Please sign in to comment.