@@ -345,25 +345,26 @@ impl<'a, 'tcx> Memory<'a, 'tcx> {
345
345
346
346
/// Print an allocation and all allocations it points to, recursively.
347
347
pub fn dump ( & self , id : AllocId ) {
348
+ use std:: fmt:: Write ;
348
349
let mut allocs_seen = HashSet :: new ( ) ;
349
350
let mut allocs_to_print = VecDeque :: new ( ) ;
350
351
allocs_to_print. push_back ( id) ;
351
352
352
353
while let Some ( id) = allocs_to_print. pop_front ( ) {
353
354
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 ( ) ;
356
357
let mut relocations = vec ! [ ] ;
357
358
358
359
let alloc = match ( self . alloc_map . get ( & id) , self . functions . get ( & id) ) {
359
360
( Some ( a) , None ) => a,
360
361
( None , Some ( _) ) => {
361
362
// FIXME: print function name
362
- println ! ( "function pointer" ) ;
363
+ trace ! ( "{} function pointer" , msg ) ;
363
364
continue ;
364
365
} ,
365
366
( None , None ) => {
366
- println ! ( "(deallocated)" ) ;
367
+ trace ! ( "{} (deallocated)" , msg ) ;
367
368
continue ;
368
369
} ,
369
370
( 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> {
377
378
relocations. push ( ( i, target_id) ) ;
378
379
}
379
380
if alloc. undef_mask . is_range_defined ( i, i + 1 ) {
380
- print ! ( "{:02x} " , alloc. bytes[ i] ) ;
381
+ write ! ( msg , "{:02x} " , alloc. bytes[ i] ) . unwrap ( ) ;
381
382
} else {
382
- print ! ( "__ " ) ;
383
+ msg . push_str ( "__ " ) ;
383
384
}
384
385
}
385
386
386
387
let immutable = if alloc. immutable { " (immutable)" } else { "" } ;
387
- println ! ( "({} bytes){}" , alloc. bytes. len( ) , immutable) ;
388
+ trace ! ( "{} ({} bytes){}" , msg , alloc. bytes. len( ) , immutable) ;
388
389
389
390
if !relocations. is_empty ( ) {
390
- print ! ( "{:1$}" , "" , prefix. len( ) ) ; // Print spaces.
391
+ msg. clear ( ) ;
392
+ write ! ( msg, "{:1$}" , "" , prefix_len) . unwrap ( ) ; // Print spaces.
391
393
let mut pos = 0 ;
392
394
let relocation_width = ( self . pointer_size ( ) - 1 ) * 3 ;
393
395
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 ( ) ;
396
398
pos = i + self . pointer_size ( ) ;
397
399
}
398
- println ! ( "" ) ;
400
+ trace ! ( "{}" , msg ) ;
399
401
}
400
402
}
401
403
}
0 commit comments