Skip to content

Commit 6379b42

Browse files
committed
multiboot2: Implement Debug and PartialEq for packed structs
1 parent 122fc9c commit 6379b42

File tree

3 files changed

+57
-3
lines changed

3 files changed

+57
-3
lines changed

multiboot2/src/elf_sections.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const METADATA_SIZE: usize = size_of::<TagTypeId>() + 4 * size_of::<u32>();
1212
/// This tag contains section header table from an ELF kernel.
1313
///
1414
/// The sections iterator is provided via the `sections` method.
15-
#[derive(Debug, ptr_meta::Pointee)]
15+
#[derive(ptr_meta::Pointee)]
1616
#[repr(C, packed)]
1717
pub struct ElfSectionsTag {
1818
typ: TagTypeId,
@@ -83,6 +83,19 @@ impl StructAsBytes for ElfSectionsTag {
8383
}
8484
}
8585

86+
impl Debug for ElfSectionsTag {
87+
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
88+
f.debug_struct("ElfSectionsTag")
89+
.field("typ", &{ self.typ })
90+
.field("size", &{ self.size })
91+
.field("number_of_sections", &{ self.number_of_sections })
92+
.field("entry_size", &{ self.entry_size })
93+
.field("shndx", &{ self.shndx })
94+
.field("sections", &self.sections(0))
95+
.finish()
96+
}
97+
}
98+
8699
/// An iterator over some ELF sections.
87100
#[derive(Clone)]
88101
pub struct ElfSectionIter {

multiboot2/src/framebuffer.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::{Reader, Tag, TagTrait, TagType, TagTypeId};
22

3+
use core::fmt::Debug;
34
use core::mem::size_of;
45
use core::slice;
56
use derive_more::Display;
@@ -17,7 +18,7 @@ const METADATA_SIZE: usize = size_of::<TagTypeId>()
1718
+ 2 * size_of::<u8>();
1819

1920
/// The VBE Framebuffer information Tag.
20-
#[derive(Debug, PartialEq, Eq, ptr_meta::Pointee)]
21+
#[derive(Eq, ptr_meta::Pointee)]
2122
#[repr(C, packed)]
2223
pub struct FramebufferTag {
2324
typ: TagTypeId,
@@ -156,6 +157,35 @@ impl StructAsBytes for FramebufferTag {
156157
}
157158
}
158159

160+
impl Debug for FramebufferTag {
161+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
162+
f.debug_struct("FramebufferTag")
163+
.field("typ", &{ self.typ })
164+
.field("size", &{ self.size })
165+
.field("buffer_type", &self.buffer_type())
166+
.field("address", &{ self.address })
167+
.field("pitch", &{ self.pitch })
168+
.field("width", &{ self.width })
169+
.field("height", &{ self.height })
170+
.field("bpp", &self.bpp)
171+
.finish()
172+
}
173+
}
174+
175+
impl PartialEq for FramebufferTag {
176+
fn eq(&self, other: &Self) -> bool {
177+
({ self.typ } == { other.typ }
178+
&& { self.size } == { other.size }
179+
&& { self.address } == { other.address }
180+
&& { self.pitch } == { other.pitch }
181+
&& { self.width } == { other.width }
182+
&& { self.height } == { other.height }
183+
&& { self.bpp } == { other.bpp }
184+
&& { self.type_no } == { other.type_no }
185+
&& self.buffer == other.buffer)
186+
}
187+
}
188+
159189
/// Helper struct for [`FramebufferType`].
160190
#[derive(Debug, PartialEq, Eq)]
161191
#[repr(u8)]

multiboot2/src/memory_map.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::{Tag, TagTrait, TagType, TagTypeId};
22

33
use core::convert::TryInto;
4+
use core::fmt::Debug;
45
use core::marker::PhantomData;
56
use core::mem;
67

@@ -187,7 +188,6 @@ impl<'a> Iterator for MemoryAreaIter<'a> {
187188
/// (which had a 24-bit address bus) could use, historically.
188189
/// Nowadays, much bigger chunks of continuous memory are available at higher
189190
/// addresses, but the Multiboot standard still references those two terms.
190-
#[derive(Debug)]
191191
#[repr(C, packed)]
192192
pub struct BasicMemoryInfoTag {
193193
typ: TagTypeId,
@@ -222,6 +222,17 @@ impl StructAsBytes for BasicMemoryInfoTag {
222222
}
223223
}
224224

225+
impl Debug for BasicMemoryInfoTag {
226+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
227+
f.debug_struct("BasicMemoryInfoTag")
228+
.field("typ", &{ self.typ })
229+
.field("size", &{ self.size })
230+
.field("memory_lower", &{ self.memory_lower })
231+
.field("memory_upper", &{ self.memory_upper })
232+
.finish()
233+
}
234+
}
235+
225236
/// EFI memory map as per EFI specification.
226237
#[derive(Debug)]
227238
#[repr(C)]

0 commit comments

Comments
 (0)