Skip to content

Commit 30c1b56

Browse files
committed
Implement a crude stack printing mechanism
1 parent 963f08b commit 30c1b56

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-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
@@ -366,6 +366,19 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
366366
// shim, add it to the corresponding submodule.
367367
match link_name.as_str() {
368368
// Miri-specific extern functions
369+
"miri_get_alloc_id" => {
370+
let [ptr] = this.check_shim(abi, Abi::Rust, link_name, args)?;
371+
let ptr = this.read_pointer(ptr)?;
372+
let (alloc_id, _, _) = this.ptr_get_alloc_id(ptr)?;
373+
this.write_scalar(Scalar::from_u64(alloc_id.0.get()), dest)?;
374+
}
375+
"miri_print_stacks" => {
376+
let [id] = this.check_shim(abi, Abi::Rust, link_name, args)?;
377+
let id = this.read_scalar(id)?.to_u64()?;
378+
if let Some(id) = std::num::NonZeroU64::new(id) {
379+
this.print_stacks(AllocId(id))?;
380+
}
381+
}
369382
"miri_static_root" => {
370383
let [ptr] = this.check_shim(abi, Abi::Rust, link_name, args)?;
371384
let ptr = this.read_pointer(ptr)?;

src/stacked_borrows/mod.rs

+14
Original file line numberDiff line numberDiff line change
@@ -1149,4 +1149,18 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
11491149
}
11501150
Ok(())
11511151
}
1152+
1153+
fn print_stacks(&mut self, alloc_id: AllocId) -> InterpResult<'tcx> {
1154+
let this = self.eval_context_mut();
1155+
let alloc_extra = this.get_alloc_extra(alloc_id)?;
1156+
let stacks = alloc_extra.stacked_borrows.as_ref().unwrap().borrow();
1157+
for (range, stack) in stacks.stacks.iter_all() {
1158+
print!("{:?}:", range);
1159+
for i in 0..stack.len() {
1160+
print!(" {:?}", stack.get(i).unwrap());
1161+
}
1162+
println!();
1163+
}
1164+
Ok(())
1165+
}
11521166
}

0 commit comments

Comments
 (0)