core: Fix broken debugger build

Former-commit-id: 0dcdb6d758e463eecc02faf5a0e7eff6c8c08899
Former-commit-id: 5e9d842158d573b10dc1ddb4c3621056282351ed
This commit is contained in:
Michel Heily 2021-06-09 01:08:42 +03:00
parent 2ec52fb722
commit f140e0f83b
4 changed files with 32 additions and 31 deletions

View file

@ -87,20 +87,20 @@ pub struct SavedCpuState {
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
#[cfg(feature = "debugger")] #[cfg(feature = "debugger")]
struct DebuggerInfo { pub struct DebuggerState {
last_executed: Option<DecodedInstruction>, pub last_executed: Option<DecodedInstruction>,
/// store the gpr before executing an instruction to show diff in the Display impl /// store the gpr before executing an instruction to show diff in the Display impl
gpr_previous: [u32; 15], pub gpr_previous: [u32; 15],
breakpoints: Vec<u32>, pub breakpoints: Vec<u32>,
verbose: bool, pub verbose: bool,
trace_opcodes: bool, pub trace_opcodes: bool,
trace_exceptions: bool, pub trace_exceptions: bool,
} }
#[cfg(feature = "debugger")] #[cfg(feature = "debugger")]
impl Default for DebuggerInfo { impl Default for DebuggerState {
fn default() -> DebuggerInfo { fn default() -> DebuggerState {
DebuggerInfo { DebuggerState {
last_executed: None, last_executed: None,
gpr_previous: [0; 15], gpr_previous: [0; 15],
breakpoints: Vec::new(), breakpoints: Vec::new(),
@ -126,7 +126,7 @@ pub struct Core<I: MemoryInterface> {
pub(super) banks: BankedRegisters, pub(super) banks: BankedRegisters,
#[cfg(feature = "debugger")] #[cfg(feature = "debugger")]
pub dbg_info: DebuggerInfo, pub dbg: DebuggerState,
} }
impl<I: MemoryInterface> Core<I> { impl<I: MemoryInterface> Core<I> {
@ -143,7 +143,7 @@ impl<I: MemoryInterface> Core<I> {
banks: BankedRegisters::default(), banks: BankedRegisters::default(),
#[cfg(feature = "debugger")] #[cfg(feature = "debugger")]
dbg_info: DebuggerInfo::default(), dbg: DebuggerState::default(),
} }
} }
@ -166,7 +166,7 @@ impl<I: MemoryInterface> Core<I> {
// savestate does not keep debugger related information, so just reinitialize to default // savestate does not keep debugger related information, so just reinitialize to default
#[cfg(feature = "debugger")] #[cfg(feature = "debugger")]
dbg_info: DebuggerInfo::default(), dbg: DebuggerState::default(),
} }
} }
@ -198,7 +198,7 @@ impl<I: MemoryInterface> Core<I> {
#[cfg(feature = "debugger")] #[cfg(feature = "debugger")]
pub fn set_verbose(&mut self, v: bool) { pub fn set_verbose(&mut self, v: bool) {
self.verbose = v; self.dbg.verbose = v;
} }
pub fn get_reg(&self, r: usize) -> u32 { pub fn get_reg(&self, r: usize) -> u32 {
@ -360,8 +360,8 @@ impl<I: MemoryInterface> Core<I> {
#[cfg(feature = "debugger")] #[cfg(feature = "debugger")]
fn debugger_record_step(&mut self, d: DecodedInstruction) { fn debugger_record_step(&mut self, d: DecodedInstruction) {
self.gpr_previous = self.get_registers(); self.dbg.gpr_previous = self.get_registers();
self.last_executed = Some(d); self.dbg.last_executed = Some(d);
} }
cfg_if! { cfg_if! {
@ -538,7 +538,7 @@ impl<I: MemoryInterface> fmt::Display for Core<I> {
let mut reg_name = reg_string(i).to_string(); let mut reg_name = reg_string(i).to_string();
reg_name.make_ascii_uppercase(); reg_name.make_ascii_uppercase();
let style = if gpr[i] != self.gpr_previous[i] { let style = if gpr[i] != self.dbg.gpr_previous[i] {
&reg_dirty_style &reg_dirty_style
} else { } else {
&reg_normal_style &reg_normal_style

View file

@ -114,10 +114,10 @@ impl Debugger {
Step(count) => { Step(count) => {
for _ in 0..count { for _ in 0..count {
self.gba.step_debugger(); 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(); 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 pc = last_executed.get_pc();
let symbol = let symbol =
self.symbols self.symbols
@ -208,10 +208,10 @@ impl Debugger {
None => println!("Breakpint already exists."), None => println!("Breakpint already exists."),
}, },
DelBreakpoint(addr) => self.delete_breakpoint(addr), DelBreakpoint(addr) => self.delete_breakpoint(addr),
ClearBreakpoints => self.gba.cpu.breakpoints.clear(), ClearBreakpoints => self.gba.cpu.dbg.breakpoints.clear(),
ListBreakpoints => { ListBreakpoints => {
println!("breakpoint list:"); 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) println!("[{}] 0x{:08x}", i, b)
} }
} }
@ -224,10 +224,10 @@ impl Debugger {
} }
TraceToggle(flags) => { TraceToggle(flags) => {
if flags.contains(TraceFlags::TRACE_OPCODE) { 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!( println!(
"[*] opcode tracing {}", "[*] opcode tracing {}",
if self.gba.cpu.trace_opcodes { if self.gba.cpu.dbg.trace_opcodes {
"on" "on"
} else { } else {
"off" "off"
@ -235,10 +235,10 @@ impl Debugger {
) )
} }
if flags.contains(TraceFlags::TRACE_EXCEPTIONS) { 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!( println!(
"[*] exception tracing {}", "[*] exception tracing {}",
if self.gba.cpu.trace_exceptions { if self.gba.cpu.dbg.trace_exceptions {
"on" "on"
} else { } else {
"off" "off"

View file

@ -55,7 +55,7 @@ impl Debugger {
pub fn check_breakpoint(&self) -> Option<u32> { pub fn check_breakpoint(&self) -> Option<u32> {
let next_pc = self.gba.cpu.get_next_pc(); 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 { if *bp == next_pc {
return Some(next_pc); return Some(next_pc);
} }
@ -65,7 +65,7 @@ impl Debugger {
} }
pub fn delete_breakpoint(&mut self, addr: u32) { 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<usize> { fn decode_reg(&self, s: &str) -> DebuggerResult<usize> {

View file

@ -325,9 +325,10 @@ impl GameBoyAdvance {
#[cfg(feature = "debugger")] #[cfg(feature = "debugger")]
pub fn add_breakpoint(&mut self, addr: u32) -> Option<usize> { pub fn add_breakpoint(&mut self, addr: u32) -> Option<usize> {
if !self.cpu.breakpoints.contains(&addr) { let breakpoints = &mut self.cpu.dbg.breakpoints;
let new_index = self.cpu.breakpoints.len(); if !breakpoints.contains(&addr) {
self.cpu.breakpoints.push(addr); let new_index = breakpoints.len();
breakpoints.push(addr);
Some(new_index) Some(new_index)
} else { } else {
None None
@ -337,7 +338,7 @@ impl GameBoyAdvance {
#[cfg(feature = "debugger")] #[cfg(feature = "debugger")]
pub fn check_breakpoint(&self) -> Option<u32> { pub fn check_breakpoint(&self) -> Option<u32> {
let next_pc = self.cpu.get_next_pc(); 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 { if (*bp & !1) == next_pc {
return Some(*bp); return Some(*bp);
} }