From 923032f8cf4301efd47d21e7f4b18b27e6f2930a Mon Sep 17 00:00:00 2001 From: Michel Heily Date: Thu, 4 Jul 2019 01:37:47 +0300 Subject: [PATCH] REPL UI changes Former-commit-id: 6852b86541f967785dbffb6833fc2c11fa5dbef3 --- src/arm7tdmi/cpu.rs | 6 ++-- src/debugger/command.rs | 61 +++++++++++++++++++++++++++-------------- 2 files changed, 43 insertions(+), 24 deletions(-) diff --git a/src/arm7tdmi/cpu.rs b/src/arm7tdmi/cpu.rs index 575e503..d168e0c 100644 --- a/src/arm7tdmi/cpu.rs +++ b/src/arm7tdmi/cpu.rs @@ -342,7 +342,7 @@ impl fmt::Display for Core { writeln!(f, "\tCPSR: {}", self.cpsr)?; writeln!(f, "\tGeneral Purpose Registers:")?; let reg_normal_style = Style::new().bold(); - let reg_dirty_style = Colour::Green.bold().on(Colour::Yellow); + let reg_dirty_style = Colour::Black.bold().on(Colour::Yellow); let gpr = self.get_registers(); for i in 0..15 { let mut reg_name = reg_string(i).to_string(); @@ -354,7 +354,7 @@ impl fmt::Display for Core { ®_normal_style }; - let entry = format!("\t{}\t= 0x{:08x}", reg_name, gpr[i]); + let entry = format!("\t{:-3} = 0x{:08x}", reg_name, gpr[i]); write!( f, @@ -363,7 +363,7 @@ impl fmt::Display for Core { if (i + 1) % 4 == 0 { "\n" } else { "" } )?; } - let pc = format!("\tPC\t= 0x{:08x}", self.pc); + let pc = format!("\tPC = 0x{:08x}", self.get_next_pc()); writeln!(f, "{}", reg_normal_style.paint(pc)) } } diff --git a/src/debugger/command.rs b/src/debugger/command.rs index 30e5944..f5ebb51 100644 --- a/src/debugger/command.rs +++ b/src/debugger/command.rs @@ -18,7 +18,7 @@ pub enum DisassMode { #[derive(Debug, PartialEq, Clone)] pub enum Command { Info, - SingleStep(bool), + Step(usize), Continue, HexDump(Addr, usize), Disass(DisassMode, Addr, usize), @@ -35,27 +35,36 @@ impl Command { use Command::*; match *self { Info => println!("{}", debugger.cpu), - SingleStep(_cycle) => { - if let Some(bp) = debugger.check_breakpoint() { - println!("hit breakpoint #0x{:08x}!", bp); - debugger.delete_breakpoint(bp); - } else { - match debugger.cpu.step_debugger(&mut debugger.sysbus) { - Ok(insn) => { - println!("{}\n", debugger.cpu); - println!( - "Executed at @0x{:08x}:\t{}", - insn.get_pc(), - Colour::Yellow.italic().paint(format!("{} ", insn)) - ); - println!("Next instruction at @0x{:08x}", debugger.cpu.get_next_pc()) - } - Err(e) => { - println!("{}: {}", "cpu encountered an error".red(), e); - println!("cpu: {:x?}", debugger.cpu) + Step(count) => { + for _ in 0..count { + if let Some(bp) = debugger.check_breakpoint() { + println!("hit breakpoint #0x{:08x}!", bp); + debugger.delete_breakpoint(bp); + } else { + match debugger.cpu.step_debugger(&mut debugger.sysbus) { + Ok(insn) => { + print!( + "{}\t{}", + Colour::Black + .bold() + .italic() + .on(Colour::White) + .paint(format!("Executed at @0x{:08x}:", insn.get_pc(),)), + insn + ); + println!("{}", Colour::Purple.dimmed().italic().paint(format!( + "\t\t/// Next instruction at @0x{:08x}", + debugger.cpu.get_next_pc() + ))) + } + Err(e) => { + println!("{}: {}", "cpu encountered an error".red(), e); + println!("cpu: {:x?}", debugger.cpu) + } } } } + println!("{}\n", debugger.cpu); } Continue => loop { if let Some(bp) = debugger.check_breakpoint() { @@ -171,8 +180,18 @@ impl Debugger { match command.as_ref() { "i" | "info" => Ok(Command::Info), - "s" | "step" => Ok(Command::SingleStep(false)), - "sc" | "stepcycle" => Ok(Command::SingleStep(true)), + "s" | "step" => { + let count = match args.len() { + 0 => 1, + 1 => self.val_number(&args[0])?, + _ => { + return Err(DebuggerError::InvalidCommandFormat( + "step [count]".to_string(), + )) + } + }; + Ok(Command::Step(count as usize)) + } "c" | "continue" => Ok(Command::Continue), "x" | "hexdump" => { let (addr, n) = match args.len() {