Skip to content

Commit 2c87be3

Browse files
authored
Merge pull request #67 from dlrobertson/debug-fmt
core: improve readability of fmt::Debug output
2 parents 95da2c9 + 335ef98 commit 2c87be3

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

mythril_core/src/device/mod.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -413,11 +413,18 @@ impl<'a> fmt::Display for PortWriteRequest<'a> {
413413
}
414414
}
415415

416-
#[derive(Debug)]
417416
pub struct MemWriteRequest<'a> {
418417
data: &'a [u8],
419418
}
420419

420+
impl fmt::Debug for MemWriteRequest<'_> {
421+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
422+
f.debug_struct("MemWriteRequest")
423+
.field("data", &format_args!("{:02x?}", self.data))
424+
.finish()
425+
}
426+
}
427+
421428
impl<'a> MemWriteRequest<'a> {
422429
pub fn new(data: &'a [u8]) -> Self {
423430
Self { data }

mythril_core/src/memory.rs

+21-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use alloc::vec::Vec;
55
use bitflags::bitflags;
66
use core::borrow::{Borrow, BorrowMut};
77
use core::default::Default;
8+
use core::fmt;
89
use core::ops::{Add, Deref, Index, IndexMut};
910
use derive_try_from_primitive::TryFromPrimitive;
1011
use ux;
@@ -142,8 +143,9 @@ impl Add<usize> for Guest4LevelPagingAddr {
142143
}
143144
}
144145

145-
#[derive(PartialEq, Eq, PartialOrd, Ord, Copy, Clone, Debug)]
146+
#[derive(PartialEq, Eq, PartialOrd, Ord, Copy, Clone)]
146147
pub struct GuestPhysAddr(u64);
148+
147149
impl GuestPhysAddr {
148150
pub fn new(addr: u64) -> Self {
149151
Self(addr)
@@ -182,8 +184,17 @@ impl Add<usize> for GuestPhysAddr {
182184
}
183185
}
184186

185-
#[derive(PartialEq, Eq, PartialOrd, Ord, Copy, Clone, Debug)]
187+
impl fmt::Debug for GuestPhysAddr {
188+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
189+
f.debug_tuple("GuestPhysAddr")
190+
.field(&format_args!("0x{:x}", self.0))
191+
.finish()
192+
}
193+
}
194+
195+
#[derive(PartialEq, Eq, PartialOrd, Ord, Copy, Clone)]
186196
pub struct HostPhysAddr(u64);
197+
187198
impl HostPhysAddr {
188199
pub fn new(addr: u64) -> Self {
189200
Self(addr)
@@ -198,6 +209,14 @@ impl HostPhysAddr {
198209
}
199210
}
200211

212+
impl fmt::Debug for HostPhysAddr {
213+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
214+
f.debug_tuple("HostPhysAddr")
215+
.field(&format_args!("0x{:x}", self.0))
216+
.finish()
217+
}
218+
}
219+
201220
#[derive(PartialEq, Eq, PartialOrd, Ord, Copy, Clone, Debug)]
202221
pub struct HostPhysFrame(HostPhysAddr);
203222
impl HostPhysFrame {

0 commit comments

Comments
 (0)