Implement stepping

This commit is contained in:
2025-01-05 13:44:59 -05:00
parent 6fd8d8f5cf
commit 84f2cf7ece
3 changed files with 58 additions and 11 deletions
+19 -3
View File
@@ -315,7 +315,7 @@ impl Emulator {
fn stop_debugging(&mut self, sim_id: SimId) {
if let Some(sim) = self.sims.get_mut(sim_id.to_index()) {
sim.clear_breakpoints();
sim.clear_debug_state();
}
self.debuggers.remove(&sim_id);
if self.debuggers.is_empty() {
@@ -345,12 +345,21 @@ impl Emulator {
}
}
fn debug_continue(&mut self, sim_id: SimId) {
fn debug_continue(&mut self, sim_id: SimId) -> bool {
let Some(debugger) = self.debuggers.get_mut(&sim_id) else {
self.stop_debugging(sim_id);
return;
return false;
};
debugger.stop_reason = None;
true
}
fn debug_step(&mut self, sim_id: SimId) {
if self.debug_continue(sim_id) {
let Some(sim) = self.sims.get_mut(sim_id.to_index()) else {
return;
};
sim.step();
}
}
pub fn run(&mut self) {
@@ -412,6 +421,7 @@ impl Emulator {
};
if let Some(reason) = sim.stop_reason() {
let stop_reason = match reason {
StopReason::Stepped => DebugStopReason::Trace,
StopReason::Breakpoint => DebugStopReason::Breakpoint,
};
self.debug_stop(sim_id, stop_reason);
@@ -509,6 +519,9 @@ impl Emulator {
EmulatorCommand::DebugContinue(sim_id) => {
self.debug_continue(sim_id);
}
EmulatorCommand::DebugStep(sim_id) => {
self.debug_step(sim_id);
}
EmulatorCommand::ReadRegister(sim_id, register, done) => {
let Some(sim) = self.sims.get_mut(sim_id.to_index()) else {
return;
@@ -596,6 +609,7 @@ pub enum EmulatorCommand {
StopDebugging(SimId),
DebugInterrupt(SimId),
DebugContinue(SimId),
DebugStep(SimId),
ReadRegister(SimId, VBRegister, oneshot::Sender<u32>),
ReadMemory(SimId, Range<u32>, Vec<u8>, oneshot::Sender<Vec<u8>>),
AddBreakpoint(SimId, u32),
@@ -628,6 +642,8 @@ type DebugSender = tokio::sync::mpsc::UnboundedSender<DebugEvent>;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum DebugStopReason {
// We are stepping
Trace,
// We hit a breakpoint
Breakpoint,
// The debugger told us to pause