From 4c43e9290f160e24f8c91640780ffce2bc8b0513 Mon Sep 17 00:00:00 2001 From: VegOwOtenks Date: Sun, 3 Nov 2024 13:43:09 +0100 Subject: [PATCH] Prettified the debug output --- src/jvm.rs | 2 +- src/stackframe.rs | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/jvm.rs b/src/jvm.rs index 2cde5af..e3b7c36 100644 --- a/src/jvm.rs +++ b/src/jvm.rs @@ -669,7 +669,7 @@ impl JVM { //println!("{} locals: {:?}", " ".repeat(frame_index), frame.locals); println!("{} stack: {:?}", " ".repeat(frame_index), frame.operand_stack); - println!("{}{:25}.{:15}:{:<10}{instruction:?}\n", " ".repeat(frame_index), class.get_classname().unwrap(), method.name, frame.instruction_pointer); + println!("{}{}.{}:{:<10}{instruction:?}\n", " ".repeat(frame_index), class.get_classname().unwrap(), method.name, frame.instruction_pointer); match instruction { diff --git a/src/stackframe.rs b/src/stackframe.rs index f3a1ee2..8ef95c0 100644 --- a/src/stackframe.rs +++ b/src/stackframe.rs @@ -1,3 +1,4 @@ +use core::fmt::Debug; use crate::accessmasks::MethodAccessFlag; use crate::classfile::{ AttributeData, JavaClassFile }; use crate::heap_area::{ ObjectReference, FieldValue }; @@ -19,12 +20,19 @@ pub enum StackValue { Empty(), } -#[derive(Debug)] pub struct OperandStack { stack: Box<[StackValue]>, depth: u16, } +impl Debug for OperandStack { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_list() + .entries(self.stack.iter().take(self.depth as usize)) + .finish() + } +} + #[derive(Debug)] pub enum Error { PushError(String),