@@ -20,6 +20,7 @@ use super::{
2020 AllocId , AllocMap , Allocation , AllocationExtra , CheckInAllocMsg , ErrorHandled , GlobalAlloc ,
2121 GlobalId , InterpResult , Machine , MayLeak , Pointer , PointerArithmetic , Scalar ,
2222} ;
23+ use crate :: util:: pretty;
2324
2425#[ derive( Debug , PartialEq , Copy , Clone ) ]
2526pub enum MemoryKind < T > {
@@ -644,22 +645,22 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
644645 self . dump_allocs ( vec ! [ id] ) ;
645646 }
646647
647- fn dump_alloc_helper < Tag , Extra > (
648- & self ,
649- allocs_to_print : & mut VecDeque < AllocId > ,
650- alloc : & Allocation < Tag , Extra > ,
651- ) {
652- for & ( _, target_id) in alloc. relocations ( ) . values ( ) {
653- allocs_to_print. push_back ( target_id) ;
654- }
655- crate :: util:: pretty:: write_allocation ( self . tcx . tcx , alloc, & mut std:: io:: stderr ( ) , "" )
656- . unwrap ( ) ;
657- }
658-
659648 /// Print a list of allocations and all allocations they point to, recursively.
660649 /// This prints directly to stderr, ignoring RUSTC_LOG! It is up to the caller to
661650 /// control for this.
662651 pub fn dump_allocs ( & self , mut allocs : Vec < AllocId > ) {
652+ // Cannot be a closure because it is generic in `Tag`, `Extra`.
653+ fn write_allocation_track_relocs < ' tcx , Tag , Extra > (
654+ tcx : TyCtxtAt < ' tcx > ,
655+ allocs_to_print : & mut VecDeque < AllocId > ,
656+ alloc : & Allocation < Tag , Extra > ,
657+ ) {
658+ for & ( _, target_id) in alloc. relocations ( ) . values ( ) {
659+ allocs_to_print. push_back ( target_id) ;
660+ }
661+ pretty:: write_allocation ( tcx. tcx , alloc, & mut std:: io:: stderr ( ) ) . unwrap ( ) ;
662+ }
663+
663664 allocs. sort ( ) ;
664665 allocs. dedup ( ) ;
665666 let mut allocs_to_print = VecDeque :: from ( allocs) ;
@@ -671,46 +672,42 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
671672 // Already printed, so skip this.
672673 continue ;
673674 }
674- eprint ! ( "Alloc {:<5}: " , id) ;
675- fn msg < Tag , Extra > ( alloc : & Allocation < Tag , Extra > , extra : & str ) {
676- eprintln ! (
677- "({} bytes, alignment {}){}" ,
678- alloc. size. bytes( ) ,
679- alloc. align. bytes( ) ,
680- extra
681- )
682- } ;
683675
684- // normal alloc?
685- match self . alloc_map . get_or ( id, || Err ( ( ) ) ) {
686- Ok ( ( kind, alloc) ) => {
676+ eprint ! ( "{}" , id) ;
677+ match self . alloc_map . get ( id) {
678+ Some ( & ( kind, ref alloc) ) => {
679+ // normal alloc
687680 match kind {
688- MemoryKind :: Stack => msg ( alloc, " (stack)" ) ,
689- MemoryKind :: Vtable => msg ( alloc, " (vtable)" ) ,
690- MemoryKind :: CallerLocation => msg ( alloc, " (caller_location)" ) ,
691- MemoryKind :: Machine ( m) => msg ( alloc, & format ! ( " ({:?})" , m) ) ,
681+ MemoryKind :: Stack => eprint ! ( " (stack variable, " ) ,
682+ MemoryKind :: Vtable => eprint ! ( " (vtable, " ) ,
683+ MemoryKind :: CallerLocation => eprint ! ( " (caller_location, " ) ,
684+ MemoryKind :: Machine ( m) if Some ( m) == M :: GLOBAL_KIND => {
685+ eprint ! ( " (global, " )
686+ }
687+ MemoryKind :: Machine ( m) => eprint ! ( " ({:?}, " , m) ,
692688 } ;
693- self . dump_alloc_helper ( & mut allocs_to_print, alloc) ;
689+ write_allocation_track_relocs ( self . tcx , & mut allocs_to_print, alloc) ;
694690 }
695- Err ( ( ) ) => {
696- // global alloc?
691+ None => {
692+ // global alloc
697693 match self . tcx . alloc_map . lock ( ) . get ( id) {
698694 Some ( GlobalAlloc :: Memory ( alloc) ) => {
699- msg ( alloc , " (immutable) " ) ;
700- self . dump_alloc_helper ( & mut allocs_to_print, alloc) ;
695+ eprint ! ( " (global, " ) ;
696+ write_allocation_track_relocs ( self . tcx , & mut allocs_to_print, alloc) ;
701697 }
702698 Some ( GlobalAlloc :: Function ( func) ) => {
703- eprintln ! ( "{} " , func) ;
699+ eprint ! ( " (fn: {}) " , func) ;
704700 }
705701 Some ( GlobalAlloc :: Static ( did) ) => {
706- eprintln ! ( "{:?} " , did) ;
702+ eprint ! ( " (static: {}) " , self . tcx . def_path_str ( did) ) ;
707703 }
708704 None => {
709- eprintln ! ( "(deallocated)" ) ;
705+ eprint ! ( " (deallocated)" ) ;
710706 }
711707 }
712708 }
713- } ;
709+ }
710+ eprintln ! ( ) ;
714711 }
715712 }
716713
0 commit comments