Skip to content

Commit 0690a26

Browse files
committed
make Memory::dump use trace! instead of println!
1 parent 0f578f0 commit 0690a26

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/memory.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -345,25 +345,26 @@ impl<'a, 'tcx> Memory<'a, 'tcx> {
345345

346346
/// Print an allocation and all allocations it points to, recursively.
347347
pub fn dump(&self, id: AllocId) {
348+
use std::fmt::Write;
348349
let mut allocs_seen = HashSet::new();
349350
let mut allocs_to_print = VecDeque::new();
350351
allocs_to_print.push_back(id);
351352

352353
while let Some(id) = allocs_to_print.pop_front() {
353354
allocs_seen.insert(id);
354-
let prefix = format!("Alloc {:<5} ", format!("{}:", id));
355-
print!("{}", prefix);
355+
let mut msg = format!("Alloc {:<5} ", format!("{}:", id));
356+
let prefix_len = msg.len();
356357
let mut relocations = vec![];
357358

358359
let alloc = match (self.alloc_map.get(&id), self.functions.get(&id)) {
359360
(Some(a), None) => a,
360361
(None, Some(_)) => {
361362
// FIXME: print function name
362-
println!("function pointer");
363+
trace!("{} function pointer", msg);
363364
continue;
364365
},
365366
(None, None) => {
366-
println!("(deallocated)");
367+
trace!("{} (deallocated)", msg);
367368
continue;
368369
},
369370
(Some(_), Some(_)) => bug!("miri invariant broken: an allocation id exists that points to both a function and a memory location"),
@@ -377,25 +378,26 @@ impl<'a, 'tcx> Memory<'a, 'tcx> {
377378
relocations.push((i, target_id));
378379
}
379380
if alloc.undef_mask.is_range_defined(i, i + 1) {
380-
print!("{:02x} ", alloc.bytes[i]);
381+
write!(msg, "{:02x} ", alloc.bytes[i]).unwrap();
381382
} else {
382-
print!("__ ");
383+
msg.push_str("__ ");
383384
}
384385
}
385386

386387
let immutable = if alloc.immutable { " (immutable)" } else { "" };
387-
println!("({} bytes){}", alloc.bytes.len(), immutable);
388+
trace!("{}({} bytes){}", msg, alloc.bytes.len(), immutable);
388389

389390
if !relocations.is_empty() {
390-
print!("{:1$}", "", prefix.len()); // Print spaces.
391+
msg.clear();
392+
write!(msg, "{:1$}", "", prefix_len).unwrap(); // Print spaces.
391393
let mut pos = 0;
392394
let relocation_width = (self.pointer_size() - 1) * 3;
393395
for (i, target_id) in relocations {
394-
print!("{:1$}", "", (i - pos) * 3);
395-
print!("└{0:─^1$}┘ ", format!("({})", target_id), relocation_width);
396+
write!(msg, "{:1$}", "", (i - pos) * 3).unwrap();
397+
write!(msg, "└{0:─^1$}┘ ", format!("({})", target_id), relocation_width).unwrap();
396398
pos = i + self.pointer_size();
397399
}
398-
println!("");
400+
trace!("{}", msg);
399401
}
400402
}
401403
}

0 commit comments

Comments
 (0)