diff --git a/ostd/src/mm/frame/meta.rs b/ostd/src/mm/frame/meta.rs index c7a4f7d7..48639b75 100644 --- a/ostd/src/mm/frame/meta.rs +++ b/ostd/src/mm/frame/meta.rs @@ -147,7 +147,7 @@ const_assert!(size_of::() == META_SLOT_SIZE); /// /// If `on_drop` reads the page using the provided `VmReader`, the /// implementer must ensure that the frame is safe to read. -pub unsafe trait AnyFrameMeta: Any + Send + Sync + Debug + 'static { +pub unsafe trait AnyFrameMeta: Any + Send + Sync { /// Called when the last handle to the frame is dropped. fn on_drop(&mut self, _reader: &mut VmReader) {} diff --git a/ostd/src/mm/frame/mod.rs b/ostd/src/mm/frame/mod.rs index 9cfa1d56..407dbd64 100644 --- a/ostd/src/mm/frame/mod.rs +++ b/ostd/src/mm/frame/mod.rs @@ -62,7 +62,6 @@ static MAX_PADDR: AtomicUsize = AtomicUsize::new(0); /// Frames are associated with metadata. The type of the metadata `M` is /// determines the kind of the frame. If `M` implements [`AnyUFrameMeta`], the /// frame is a untyped frame. Otherwise, it is a typed frame. -#[derive(Debug)] #[repr(transparent)] pub struct Frame { ptr: *const MetaSlot, @@ -73,6 +72,12 @@ unsafe impl Send for Frame {} unsafe impl Sync for Frame {} +impl core::fmt::Debug for Frame { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + write!(f, "Frame({:#x})", self.start_paddr()) + } +} + impl Frame { /// Gets a [`Frame`] with a specific usage from a raw, unused page. /// diff --git a/ostd/src/mm/frame/segment.rs b/ostd/src/mm/frame/segment.rs index 077ac9db..038c924a 100644 --- a/ostd/src/mm/frame/segment.rs +++ b/ostd/src/mm/frame/segment.rs @@ -2,7 +2,7 @@ //! A contiguous range of frames. -use core::{mem::ManuallyDrop, ops::Range, sync::atomic::Ordering}; +use core::{fmt::Debug, mem::ManuallyDrop, ops::Range, sync::atomic::Ordering}; use super::{ inc_frame_ref_count, @@ -23,13 +23,18 @@ use crate::mm::{AnyUFrameMeta, Paddr, PAGE_SIZE}; /// /// All the metadata of the frames are homogeneous, i.e., they are of the same /// type. -#[derive(Debug)] #[repr(transparent)] pub struct Segment { range: Range, _marker: core::marker::PhantomData, } +impl Debug for Segment { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + write!(f, "Segment({:#x}..{:#x})", self.range.start, self.range.end) + } +} + /// A contiguous range of homogeneous untyped physical memory frames that have any metadata. /// /// In other words, the metadata of the frames are of the same type, and they diff --git a/ostd/src/mm/frame/unique.rs b/ostd/src/mm/frame/unique.rs index 99d52dd6..4edaebf7 100644 --- a/ostd/src/mm/frame/unique.rs +++ b/ostd/src/mm/frame/unique.rs @@ -14,7 +14,6 @@ use crate::mm::{frame::mapping, Paddr, PagingConsts, PagingLevel, PAGE_SIZE}; /// /// Unlike [`Frame`], the frame pointed to by this pointer is not shared with /// others. So a mutable reference to the metadata is available for the frame. -#[derive(Debug)] #[repr(transparent)] pub struct UniqueFrame { ptr: *const MetaSlot, @@ -25,6 +24,12 @@ unsafe impl Send for UniqueFrame {} unsafe impl Sync for UniqueFrame {} +impl core::fmt::Debug for UniqueFrame { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + write!(f, "UniqueFrame({:#x})", self.start_paddr()) + } +} + impl UniqueFrame { /// Gets a [`UniqueFrame`] with a specific usage from a raw, unused page. ///