From 8ba3273b9fe2e56c18c33fb60feaaf6a65abe268 Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Thu, 1 Dec 2022 09:40:19 -0800 Subject: [PATCH] fix(hal-x86_64): nicer `Debug` output for `Idt` (#375) 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. --- hal-x86_64/src/interrupt/idt.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/hal-x86_64/src/interrupt/idt.rs b/hal-x86_64/src/interrupt/idt.rs index f63e57c5..0ca0454b 100644 --- a/hal-x86_64/src/interrupt/idt.rs +++ b/hal-x86_64/src/interrupt/idt.rs @@ -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))] @@ -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() } }