Skip to content

Commit

Permalink
fix(hal-x86_64): nicer Debug output for Idt (#375)
Browse files Browse the repository at this point in the history
This improves the `Idt` type's `fmt::Debug` output, including fixing a
potential panic when trying to format a null descriptor. Since the IDT
is sparse and many descriptors may be null, only the present descriptors
are printed, along with their indices.
  • Loading branch information
hawkw committed Dec 1, 2022
1 parent c156e8c commit 8ba3273
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions hal-x86_64/src/interrupt/idt.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use super::apic::IoApic;
use crate::{cpu, segment};
use core::fmt;
use mycelium_util::bits;
use crate::{
cpu::{self, DescriptorTable},
segment,
};
use mycelium_util::{bits, fmt};

#[repr(C)]
#[repr(align(16))]
Expand Down Expand Up @@ -205,7 +207,12 @@ impl Idt {
impl fmt::Debug for Idt {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let Self { descriptors } = self;
f.debug_list().entries(descriptors[..].iter()).finish()
let descriptors = descriptors[..]
.iter()
.filter(|&descr| descr != &Descriptor::null())
.enumerate()
.map(|(i, descr)| (fmt::hex(i), descr));
f.debug_map().entries(descriptors).finish()
}
}

Expand Down

0 comments on commit 8ba3273

Please sign in to comment.