add debugger
This commit is contained in:
@@ -32,12 +32,17 @@ pub struct PrometeuOS {
|
||||
// Log Service
|
||||
pub log_service: LogService,
|
||||
pub current_app_id: u32,
|
||||
pub current_cartridge_title: String,
|
||||
pub current_cartridge_app_version: String,
|
||||
pub current_cartridge_app_mode: crate::model::AppMode,
|
||||
pub logs_written_this_frame: HashMap<u32, u32>,
|
||||
|
||||
// Telemetria e Certificação
|
||||
pub telemetry_current: TelemetryFrame,
|
||||
pub telemetry_last: TelemetryFrame,
|
||||
pub certifier: Certifier,
|
||||
pub paused: bool,
|
||||
pub debug_step_request: bool,
|
||||
|
||||
boot_time: Instant,
|
||||
}
|
||||
@@ -66,10 +71,15 @@ impl PrometeuOS {
|
||||
next_handle: 1,
|
||||
log_service: LogService::new(4096),
|
||||
current_app_id: 0,
|
||||
current_cartridge_title: String::new(),
|
||||
current_cartridge_app_version: String::new(),
|
||||
current_cartridge_app_mode: crate::model::AppMode::Game,
|
||||
logs_written_this_frame: HashMap::new(),
|
||||
telemetry_current: TelemetryFrame::default(),
|
||||
telemetry_last: TelemetryFrame::default(),
|
||||
certifier: Certifier::new(cap_config.unwrap_or_default()),
|
||||
paused: false,
|
||||
debug_step_request: false,
|
||||
boot_time,
|
||||
};
|
||||
|
||||
@@ -131,6 +141,21 @@ impl PrometeuOS {
|
||||
|
||||
// Determina o app_id numérico
|
||||
self.current_app_id = cartridge.app_id;
|
||||
self.current_cartridge_title = cartridge.title.clone();
|
||||
self.current_cartridge_app_version = cartridge.app_version.clone();
|
||||
self.current_cartridge_app_mode = cartridge.app_mode;
|
||||
}
|
||||
|
||||
/// Executa uma única instrução da VM (Debug).
|
||||
pub fn debug_step_instruction(&mut self, vm: &mut VirtualMachine, hw: &mut dyn HardwareBridge) -> Option<String> {
|
||||
match vm.step(self, hw) {
|
||||
Ok(_) => None,
|
||||
Err(e) => {
|
||||
let err_msg = format!("PVM Fault during Step: {:?}", e);
|
||||
self.log(LogLevel::Error, LogSource::Vm, 0, err_msg.clone());
|
||||
Some(err_msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Executa um tick do host (60Hz).
|
||||
@@ -138,6 +163,10 @@ impl PrometeuOS {
|
||||
let start = std::time::Instant::now();
|
||||
self.tick_index += 1;
|
||||
|
||||
if self.paused && !self.debug_step_request {
|
||||
return None;
|
||||
}
|
||||
|
||||
self.update_fs();
|
||||
|
||||
if !self.logical_frame_active {
|
||||
@@ -167,6 +196,12 @@ impl PrometeuOS {
|
||||
self.telemetry_current.cycles_used += run.cycles_used;
|
||||
self.telemetry_current.vm_steps += run.steps_executed;
|
||||
|
||||
if run.reason == crate::virtual_machine::LogicalFrameEndingReason::Breakpoint {
|
||||
self.paused = true;
|
||||
self.debug_step_request = false;
|
||||
self.log(LogLevel::Info, LogSource::Vm, 0xDEB1, format!("Breakpoint hit at PC 0x{:X}", vm.pc));
|
||||
}
|
||||
|
||||
if run.reason == crate::virtual_machine::LogicalFrameEndingReason::FrameSync {
|
||||
hw.gfx_mut().render_all();
|
||||
|
||||
@@ -183,6 +218,11 @@ impl PrometeuOS {
|
||||
self.logical_frame_index += 1;
|
||||
self.logical_frame_active = false;
|
||||
self.logical_frame_remaining_cycles = 0;
|
||||
|
||||
if self.debug_step_request {
|
||||
self.paused = true;
|
||||
self.debug_step_request = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
|
||||
Reference in New Issue
Block a user