Skip to content

Commit 5beefe1

Browse files
committed
Implement a crude stack printing mechanism
1 parent 78e6286 commit 5beefe1

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

src/stacked_borrows/mod.rs

+15
Original file line numberDiff line numberDiff line change
@@ -1123,4 +1123,19 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
11231123
}
11241124
Ok(())
11251125
}
1126+
1127+
fn print_stacks(&mut self, alloc_id: AllocId) -> InterpResult<'tcx> {
1128+
let this = self.eval_context_mut();
1129+
let alloc_extra = this.get_alloc_extra(alloc_id)?;
1130+
let stacks = alloc_extra.stacked_borrows.as_ref().unwrap().borrow();
1131+
for (range, stack) in stacks.stacks.iter_all() {
1132+
print!("{:?}: [", range);
1133+
for i in 0..stack.len() {
1134+
let item = stack.get(i).unwrap();
1135+
print!(" {:?}{:?}", item.perm(), item.tag());
1136+
}
1137+
println!(" ]");
1138+
}
1139+
Ok(())
1140+
}
11261141
}

0 commit comments

Comments
 (0)