pub fn dump_allocs(&self, mut allocs: Vec<AllocId>) {
        if !log_enabled!(::log::Level::Trace) {
            return;
        }
        use std::fmt::Write;
        allocs.sort();
        allocs.dedup();
        let mut allocs_to_print = VecDeque::from(allocs);
        let mut allocs_seen = FxHashSet::default();

        while let Some(id) = allocs_to_print.pop_front() {
            let mut msg = format!("Alloc {:<5} ", format!("{}:", id));
            let prefix_len = msg.len();
            let mut relocations = vec![];

            let (alloc, immutable) =
                // normal alloc?
                match self.alloc_map.get(&id) {
                    Some(a) => (a, match self.alloc_kind[&id] {
                        MemoryKind::Stack => " (stack)".to_owned(),
                        MemoryKind::Machine(m) => format!(" ({:?})", m),
                    }),
                    None => {
                        // static alloc?
                        match self.tcx.alloc_map.lock().get(id) {
                            Some(AllocType::Memory(a)) => (a, "(immutable)".to_owned()),
                            Some(AllocType::Function(func)) => {
                                trace!("{} {}", msg, func);
                                continue;
                            }
                            Some(AllocType::Static(did)) => {
                                trace!("{} {:?}", msg, did);
                                continue;
                            }
                            None => {
                                trace!("{} (deallocated)", msg);
                                continue;
                            }
                        }
                    },
                };

            for i in 0..(alloc.bytes.len() as u64) {
                let i = Size::from_bytes(i);
                if let Some(&target_id) = alloc.relocations.get(&i) {
                    if allocs_seen.insert(target_id) {
                        allocs_to_print.push_back(target_id);
                    }
                    relocations.push((i, target_id));
                }
                if alloc.undef_mask.is_range_defined(i, i + Size::from_bytes(1)) {
                    // this `as usize` is fine, since `i` came from a `usize`
                    write!(msg, "{:02x} ", alloc.bytes[i.bytes() as usize]).unwrap();
                } else {
                    msg.push_str("__ ");
                }
            }

            trace!(
                "{}({} bytes, alignment {}){}",
                msg,
                alloc.bytes.len(),
                alloc.align.abi(),
                immutable
            );

            if !relocations.is_empty() {
                msg.clear();
                write!(msg, "{:1$}", "", prefix_len).unwrap(); // Print spaces.
                let mut pos = Size::ZERO;
                let relocation_width = (self.pointer_size().bytes() - 1) * 3;
                for (i, target_id) in relocations {
                    // this `as usize` is fine, since we can't print more chars than `usize::MAX`
                    write!(msg, "{:1$}", "", ((i - pos) * 3).bytes() as usize).unwrap();
                    let target = format!("({})", target_id);
                    // this `as usize` is fine, since we can't print more chars than `usize::MAX`
                    write!(msg, "└{0:─^1$}┘ ", target, relocation_width as usize).unwrap();
                    pos = i + self.pointer_size();
                }
                trace!("{}", msg);
            }
        }
    }
/// For debugging, print a list of allocations and all allocations they point to, recursively.
For debugging, print a list of allocations and all allocations they point to, recursively.
For debugging print a list of allocations and all allocations they point to recursively .
pub fn dump_allocs(&self, mut allocs: Vec<AllocId>) {
        if !log_enabled!(::log::Level::Trace) {
            return;
        }
        use std::fmt::Write;
        allocs.sort();
        allocs.dedup();
        let mut allocs_to_print = VecDeque::from(allocs);
        let mut allocs_seen = FxHashSet::default();
        while let Some(id) = allocs_to_print.pop_front() {
            let mut msg = format!("Alloc {:<5} ", format!("{}:", id));
            let prefix_len = msg.len();
            let mut relocations = vec![];
            let (alloc, immutable) =
                // normal alloc?
                match self.alloc_map.get(&id) {
                    Some(a) => (a, match self.alloc_kind[&id] {
                        MemoryKind::Stack => " (stack)".to_owned(),
                        MemoryKind::Machine(m) => format!(" ({:?})", m),
                    }),
                    None => {
                        // static alloc?
                        match self.tcx.alloc_map.lock().get(id) {
                            Some(AllocType::Memory(a)) => (a, "(immutable)".to_owned()),
                            Some(AllocType::Function(func)) => {
                                trace!("{} {}", msg, func);
                                continue;
                            }
                            Some(AllocType::Static(did)) => {
                                trace!("{} {:?}", msg, did);
                                continue;
                            }
                            None => {
                                trace!("{} (deallocated)", msg);
                                continue;
                            }
                        }
                    },
                };
            for i in 0..(alloc.bytes.len() as u64) {
                let i = Size::from_bytes(i);
                if let Some(&target_id) = alloc.relocations.get(&i) {
                    if allocs_seen.insert(target_id) {
                        allocs_to_print.push_back(target_id);
                    }
                    relocations.push((i, target_id));
                }
                if alloc.undef_mask.is_range_defined(i, i + Size::from_bytes(1)) {
                    // this `as usize` is fine, since `i` came from a `usize`
                    write!(msg, "{:02x} ", alloc.bytes[i.bytes() as usize]).unwrap();
                } else {
                    msg.push_str("__ ");
                }
            }
            trace!(
                "{}({} bytes, alignment {}){}",
                msg,
                alloc.bytes.len(),
                alloc.align.abi(),
                immutable
            );
            if !relocations.is_empty() {
                msg.clear();
                write!(msg, "{:1$}", "", prefix_len).unwrap(); // Print spaces.
                let mut pos = Size::ZERO;
                let relocation_width = (self.pointer_size().bytes() - 1) * 3;
                for (i, target_id) in relocations {
                    // this `as usize` is fine, since we can't print more chars than `usize::MAX`
                    write!(msg, "{:1$}", "", ((i - pos) * 3).bytes() as usize).unwrap();
                    let target = format!("({})", target_id);
                    // this `as usize` is fine, since we can't print more chars than `usize::MAX`
                    write!(msg, "└{0:─^1$}┘ ", target, relocation_width as usize).unwrap();
                    pos = i + self.pointer_size();
                }
                trace!("{}", msg);
            }
        }
    }
pub fn dump_allocs ( & self , mut allocs : Vec < AllocId > ) { if ! log_enabled ! ( log Level Trace ) { return ; } use std :: fmt :: Write ; allocs . sort ( ) ; allocs . dedup ( ) ; let mut allocs_to_print = VecDeque :: from ( allocs ) ; let mut allocs_seen = FxHashSet :: default ( ) ; while let Some ( id ) = allocs_to_print . pop_front ( ) { let mut msg = format ! ( " " format ( " " id ) ) ; let prefix_len = msg . len ( ) ; let mut relocations = vec ! [ ] ; let ( alloc , immutable ) = // normal alloc? match self . alloc_map . get ( & id ) { Some ( a ) => ( a , match self . alloc_kind [ & id ] { MemoryKind :: Stack => " " . to_owned ( ) , MemoryKind :: Machine ( m ) => format ! ( " " m ) , } ) , None => { // static alloc? match self . tcx . alloc_map . lock ( ) . get ( id ) { Some ( AllocType :: Memory ( a ) ) => ( a , " " . to_owned ( ) ) , Some ( AllocType :: Function ( func ) ) => { trace ! ( " " msg func ) ; continue ; } Some ( AllocType :: Static ( did ) ) => { trace ! ( " " msg did ) ; continue ; } None => { trace ! ( " " msg ) ; continue ; } } } , } ; for i in 0 .. ( alloc . bytes . len ( ) as u64 ) { let i = Size :: from_bytes ( i ) ; if let Some ( & target_id ) = alloc . relocations . get ( & i ) { if allocs_seen . insert ( target_id ) { allocs_to_print . push_back ( target_id ) ; } relocations . push ( ( i , target_id ) ) ; } if alloc . undef_mask . is_range_defined ( i , i + Size :: from_bytes ( 1 ) ) { // this `as usize` is fine, since `i` came from a `usize` write ! ( msg " " alloc bytes [ i bytes ( ) as usize ] ) . unwrap ( ) ; } else { msg . push_str ( " " ) ; } } trace ! ( " " msg alloc bytes len ( ) alloc align abi ( ) immutable ) ; if ! relocations . is_empty ( ) { msg . clear ( ) ; write ! ( msg " " " " prefix_len ) . unwrap ( ) ; // Print spaces. let mut pos = Size :: ZERO ; let relocation_width = ( self . pointer_size ( ) . bytes ( ) - 1 ) * 3 ; for ( i , target_id ) in relocations { // this `as usize` is fine, since we can't print more chars than `usize::MAX` write ! ( msg " " " " ( ( i pos ) 3 ) bytes ( ) as usize ) . unwrap ( ) ; let target = format ! ( " " target_id ) ; // this `as usize` is fine, since we can't print more chars than `usize::MAX` write ! ( msg " g , relo tion_width as us ze .unwr a p (); pos = i + self . pointer_size ( ) ; } trace ! ( " " msg ) ; } } }
For debugging, print a list of allocations and all allocations they point to, recursively.
For debugging print a list of allocations and all allocations they point to recursively .
&self
allocs
Vec<AllocId>