From 8a057ba15978c7ca25d4f819cf8f08dc3232a970 Mon Sep 17 00:00:00 2001 From: Michel Heily Date: Thu, 27 Jun 2019 00:41:54 +0300 Subject: [PATCH] debugger: Remember last command --- src/debugger/mod.rs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/debugger/mod.rs b/src/debugger/mod.rs index 7cf47c6..1f04599 100644 --- a/src/debugger/mod.rs +++ b/src/debugger/mod.rs @@ -30,7 +30,7 @@ impl From for DebuggerError { type DebuggerResult = Result; -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Clone)] pub enum Command { Info, SingleStep, @@ -95,8 +95,6 @@ impl Command { for line in disass { println!("{}", line) } - - debugger.next_disass_addr = Some(addr + (4 * n as u32)); } Quit => { print!("Quitting!"); @@ -132,7 +130,7 @@ pub struct Debugger { sysbus: SysBus, running: bool, breakpoints: Vec, - next_disass_addr: Option, + previous_command: Option, } impl Debugger { @@ -142,7 +140,7 @@ impl Debugger { sysbus: sysbus, breakpoints: Vec::new(), running: false, - next_disass_addr: None, + previous_command: None } } @@ -226,7 +224,13 @@ impl Debugger { (addr, 10) } - 0 => (self.next_disass_addr.unwrap_or(self.cpu.get_reg(15)), 10), + 0 => { + if let Some(Command::Disass(addr, n)) = self.previous_command { + (addr + (4 * n as u32), 10) + } else { + (self.cpu.get_reg(15), 10) + } + } _ => { return Err(DebuggerError::InvalidCommandFormat( "disass [addr] [n]".to_string(), @@ -264,7 +268,10 @@ impl Debugger { fn eval_expr(&mut self, expr: Expr) { match expr { Expr::Command(c, a) => match self.eval_command(c, a) { - Ok(cmd) => cmd.run(self), + Ok(cmd) => { + self.previous_command = Some(cmd.clone()); + cmd.run(self) + }, Err(DebuggerError::InvalidCommand(c)) => { println!("{}: {:?}", "invalid command".red(), c) } @@ -297,6 +304,7 @@ impl Debugger { match readline { Ok(line) => { if line.is_empty() { + self.previous_command = None; continue; } rl.add_history_entry(line.as_str());