diff --git a/core/src/arm7tdmi/cpu.rs b/core/src/arm7tdmi/cpu.rs index 826484f..5126412 100644 --- a/core/src/arm7tdmi/cpu.rs +++ b/core/src/arm7tdmi/cpu.rs @@ -87,20 +87,20 @@ pub struct SavedCpuState { #[derive(Clone, Debug)] #[cfg(feature = "debugger")] -struct DebuggerInfo { - last_executed: Option, +pub struct DebuggerState { + pub last_executed: Option, /// store the gpr before executing an instruction to show diff in the Display impl - gpr_previous: [u32; 15], - breakpoints: Vec, - verbose: bool, - trace_opcodes: bool, - trace_exceptions: bool, + pub gpr_previous: [u32; 15], + pub breakpoints: Vec, + pub verbose: bool, + pub trace_opcodes: bool, + pub trace_exceptions: bool, } #[cfg(feature = "debugger")] -impl Default for DebuggerInfo { - fn default() -> DebuggerInfo { - DebuggerInfo { +impl Default for DebuggerState { + fn default() -> DebuggerState { + DebuggerState { last_executed: None, gpr_previous: [0; 15], breakpoints: Vec::new(), @@ -126,7 +126,7 @@ pub struct Core { pub(super) banks: BankedRegisters, #[cfg(feature = "debugger")] - pub dbg_info: DebuggerInfo, + pub dbg: DebuggerState, } impl Core { @@ -143,7 +143,7 @@ impl Core { banks: BankedRegisters::default(), #[cfg(feature = "debugger")] - dbg_info: DebuggerInfo::default(), + dbg: DebuggerState::default(), } } @@ -166,7 +166,7 @@ impl Core { // savestate does not keep debugger related information, so just reinitialize to default #[cfg(feature = "debugger")] - dbg_info: DebuggerInfo::default(), + dbg: DebuggerState::default(), } } @@ -198,7 +198,7 @@ impl Core { #[cfg(feature = "debugger")] pub fn set_verbose(&mut self, v: bool) { - self.verbose = v; + self.dbg.verbose = v; } pub fn get_reg(&self, r: usize) -> u32 { @@ -360,8 +360,8 @@ impl Core { #[cfg(feature = "debugger")] fn debugger_record_step(&mut self, d: DecodedInstruction) { - self.gpr_previous = self.get_registers(); - self.last_executed = Some(d); + self.dbg.gpr_previous = self.get_registers(); + self.dbg.last_executed = Some(d); } cfg_if! { @@ -538,7 +538,7 @@ impl fmt::Display for Core { let mut reg_name = reg_string(i).to_string(); reg_name.make_ascii_uppercase(); - let style = if gpr[i] != self.gpr_previous[i] { + let style = if gpr[i] != self.dbg.gpr_previous[i] { ®_dirty_style } else { ®_normal_style diff --git a/core/src/debugger/command.rs b/core/src/debugger/command.rs index 0677794..8636ab7 100644 --- a/core/src/debugger/command.rs +++ b/core/src/debugger/command.rs @@ -114,10 +114,10 @@ impl Debugger { Step(count) => { for _ in 0..count { self.gba.step_debugger(); - while self.gba.cpu.last_executed.is_none() { + while self.gba.cpu.dbg.last_executed.is_none() { self.gba.step_debugger(); } - if let Some(last_executed) = &self.gba.cpu.last_executed { + if let Some(last_executed) = &self.gba.cpu.dbg.last_executed { let pc = last_executed.get_pc(); let symbol = self.symbols @@ -208,10 +208,10 @@ impl Debugger { None => println!("Breakpint already exists."), }, DelBreakpoint(addr) => self.delete_breakpoint(addr), - ClearBreakpoints => self.gba.cpu.breakpoints.clear(), + ClearBreakpoints => self.gba.cpu.dbg.breakpoints.clear(), ListBreakpoints => { println!("breakpoint list:"); - for (i, b) in self.gba.cpu.breakpoints.iter().enumerate() { + for (i, b) in self.gba.cpu.dbg.breakpoints.iter().enumerate() { println!("[{}] 0x{:08x}", i, b) } } @@ -224,10 +224,10 @@ impl Debugger { } TraceToggle(flags) => { if flags.contains(TraceFlags::TRACE_OPCODE) { - self.gba.cpu.trace_opcodes = !self.gba.cpu.trace_opcodes; + self.gba.cpu.dbg.trace_opcodes = !self.gba.cpu.dbg.trace_opcodes; println!( "[*] opcode tracing {}", - if self.gba.cpu.trace_opcodes { + if self.gba.cpu.dbg.trace_opcodes { "on" } else { "off" @@ -235,10 +235,10 @@ impl Debugger { ) } if flags.contains(TraceFlags::TRACE_EXCEPTIONS) { - self.gba.cpu.trace_exceptions = !self.gba.cpu.trace_exceptions; + self.gba.cpu.dbg.trace_exceptions = !self.gba.cpu.dbg.trace_exceptions; println!( "[*] exception tracing {}", - if self.gba.cpu.trace_exceptions { + if self.gba.cpu.dbg.trace_exceptions { "on" } else { "off" diff --git a/core/src/debugger/mod.rs b/core/src/debugger/mod.rs index 729709f..3c6e1d0 100644 --- a/core/src/debugger/mod.rs +++ b/core/src/debugger/mod.rs @@ -55,7 +55,7 @@ impl Debugger { pub fn check_breakpoint(&self) -> Option { let next_pc = self.gba.cpu.get_next_pc(); - for bp in &self.gba.cpu.breakpoints { + for bp in &self.gba.cpu.dbg.breakpoints { if *bp == next_pc { return Some(next_pc); } @@ -65,7 +65,7 @@ impl Debugger { } pub fn delete_breakpoint(&mut self, addr: u32) { - self.gba.cpu.breakpoints.retain(|&a| a != addr); + self.gba.cpu.dbg.breakpoints.retain(|&a| a != addr); } fn decode_reg(&self, s: &str) -> DebuggerResult { diff --git a/core/src/gba.rs b/core/src/gba.rs index dc7e280..2245a20 100644 --- a/core/src/gba.rs +++ b/core/src/gba.rs @@ -325,9 +325,10 @@ impl GameBoyAdvance { #[cfg(feature = "debugger")] pub fn add_breakpoint(&mut self, addr: u32) -> Option { - if !self.cpu.breakpoints.contains(&addr) { - let new_index = self.cpu.breakpoints.len(); - self.cpu.breakpoints.push(addr); + let breakpoints = &mut self.cpu.dbg.breakpoints; + if !breakpoints.contains(&addr) { + let new_index = breakpoints.len(); + breakpoints.push(addr); Some(new_index) } else { None @@ -337,7 +338,7 @@ impl GameBoyAdvance { #[cfg(feature = "debugger")] pub fn check_breakpoint(&self) -> Option { let next_pc = self.cpu.get_next_pc(); - for bp in &self.cpu.breakpoints { + for bp in &self.cpu.dbg.breakpoints { if (*bp & !1) == next_pc { return Some(*bp); }