add process and task managers
This commit is contained in:
@@ -58,7 +58,7 @@ impl HostDebugger {
|
||||
// Pre-load cartridge metadata so the Handshake message can contain
|
||||
// valid information about the App being debugged.
|
||||
if let Ok(cartridge) = CartridgeLoader::load(path) {
|
||||
let _ = firmware.os.initialize_vm(&mut firmware.vm, &cartridge);
|
||||
let _ = firmware.os.vm_runtime.initialize_vm(&mut firmware.vm, &cartridge);
|
||||
}
|
||||
|
||||
match TcpListener::bind(format!("127.0.0.1:{}", debug_port)) {
|
||||
@@ -117,10 +117,10 @@ impl HostDebugger {
|
||||
protocol_version: DEVTOOLS_PROTOCOL_VERSION,
|
||||
runtime_version: "0.1".to_string(),
|
||||
cartridge: HandshakeCartridge {
|
||||
app_id: firmware.os.current_app_id,
|
||||
title: firmware.os.current_cartridge_title.clone(),
|
||||
app_version: firmware.os.current_cartridge_app_version.clone(),
|
||||
app_mode: firmware.os.current_cartridge_app_mode,
|
||||
app_id: firmware.os.vm_runtime.current_app_id,
|
||||
title: firmware.os.vm_runtime.current_cartridge_title.clone(),
|
||||
app_version: firmware.os.vm_runtime.current_cartridge_app_version.clone(),
|
||||
app_mode: firmware.os.vm_runtime.current_cartridge_app_mode,
|
||||
},
|
||||
};
|
||||
self.send_response(handshake);
|
||||
@@ -138,7 +138,7 @@ impl HostDebugger {
|
||||
println!("[Debugger] Connection closed by remote.");
|
||||
self.stream = None;
|
||||
// Resume VM execution if it was paused waiting for the debugger.
|
||||
firmware.os.paused = false;
|
||||
firmware.os.vm_runtime.paused = false;
|
||||
self.waiting_for_start = false;
|
||||
}
|
||||
Ok(n) => {
|
||||
@@ -165,7 +165,7 @@ impl HostDebugger {
|
||||
Err(e) => {
|
||||
eprintln!("[Debugger] Connection error: {}", e);
|
||||
self.stream = None;
|
||||
firmware.os.paused = false;
|
||||
firmware.os.vm_runtime.paused = false;
|
||||
self.waiting_for_start = false;
|
||||
}
|
||||
}
|
||||
@@ -190,23 +190,23 @@ impl HostDebugger {
|
||||
println!("[Debugger] Starting execution...");
|
||||
self.waiting_for_start = false;
|
||||
}
|
||||
firmware.os.paused = false;
|
||||
firmware.os.vm_runtime.paused = false;
|
||||
}
|
||||
DebugCommand::Pause => {
|
||||
firmware.os.paused = true;
|
||||
firmware.os.vm_runtime.paused = true;
|
||||
}
|
||||
DebugCommand::Resume => {
|
||||
firmware.os.paused = false;
|
||||
firmware.os.vm_runtime.paused = false;
|
||||
}
|
||||
DebugCommand::Step => {
|
||||
// Execute exactly one instruction and keep paused.
|
||||
firmware.os.paused = true;
|
||||
let _ = firmware.os.debug_step_instruction(&mut firmware.vm, hardware);
|
||||
firmware.os.vm_runtime.paused = true;
|
||||
let _ = firmware.os.vm_runtime.debug_step_instruction(&mut firmware.vm, hardware);
|
||||
}
|
||||
DebugCommand::StepFrame => {
|
||||
// Execute until the end of the current logical frame.
|
||||
firmware.os.paused = false;
|
||||
firmware.os.debug_step_request = true;
|
||||
firmware.os.vm_runtime.paused = false;
|
||||
firmware.os.vm_runtime.debug_step_request = true;
|
||||
}
|
||||
DebugCommand::GetState => {
|
||||
// Return detailed VM register and stack state.
|
||||
@@ -215,8 +215,8 @@ impl HostDebugger {
|
||||
let resp = DebugResponse::GetState {
|
||||
pc: firmware.vm.pc(),
|
||||
stack_top,
|
||||
frame_index: firmware.os.logical_frame_index,
|
||||
app_id: firmware.os.current_app_id,
|
||||
frame_index: firmware.os.vm_runtime.logical_frame_index,
|
||||
app_id: firmware.os.vm_runtime.current_app_id,
|
||||
};
|
||||
self.send_response(resp);
|
||||
}
|
||||
@@ -301,14 +301,14 @@ impl HostDebugger {
|
||||
|
||||
/// Scans the system for new information to push to the debugger client.
|
||||
fn stream_events(&mut self, firmware: &mut Firmware) {
|
||||
if let Some(report) = firmware.os.last_crash_report.as_ref() {
|
||||
if let Some(report) = firmware.os.vm_runtime.last_crash_report.as_ref() {
|
||||
self.stream_fault(report);
|
||||
} else {
|
||||
self.last_fault_summary = None;
|
||||
}
|
||||
|
||||
// 1. Process and send new log entries.
|
||||
let new_events = firmware.os.log_service.get_after(self.last_log_seq);
|
||||
let new_events = firmware.os.vm_runtime.log_service.get_after(self.last_log_seq);
|
||||
for event in new_events {
|
||||
self.last_log_seq = event.seq;
|
||||
|
||||
@@ -316,16 +316,16 @@ impl HostDebugger {
|
||||
if event.tag == 0xDEB1 {
|
||||
self.send_event(DebugEvent::BreakpointHit {
|
||||
pc: firmware.vm.pc(),
|
||||
frame_index: firmware.os.logical_frame_index,
|
||||
frame_index: firmware.os.vm_runtime.logical_frame_index,
|
||||
});
|
||||
}
|
||||
|
||||
if (0xCA01..=0xCA07).contains(&event.tag)
|
||||
&& let Some(cert_event) = Self::cert_event_from_snapshot(
|
||||
event.tag,
|
||||
firmware.os.atomic_telemetry.snapshot(),
|
||||
&firmware.os.certifier.config,
|
||||
firmware.os.logical_frame_index,
|
||||
firmware.os.vm_runtime.atomic_telemetry.snapshot(),
|
||||
&firmware.os.vm_runtime.certifier.config,
|
||||
firmware.os.vm_runtime.logical_frame_index,
|
||||
)
|
||||
{
|
||||
self.send_event(cert_event);
|
||||
@@ -339,9 +339,9 @@ impl HostDebugger {
|
||||
}
|
||||
|
||||
// 2. Send telemetry snapshots at the completion of every frame.
|
||||
let current_frame = firmware.os.logical_frame_index;
|
||||
let current_frame = firmware.os.vm_runtime.logical_frame_index;
|
||||
if current_frame > self.last_telemetry_frame {
|
||||
let tel = firmware.os.atomic_telemetry.snapshot();
|
||||
let tel = firmware.os.vm_runtime.atomic_telemetry.snapshot();
|
||||
self.send_event(Self::telemetry_event_from_snapshot(tel));
|
||||
self.last_telemetry_frame = current_frame;
|
||||
}
|
||||
@@ -399,14 +399,14 @@ mod tests {
|
||||
let mut hardware = Hardware::new();
|
||||
|
||||
debugger.handle_command(DebugCommand::Pause, &mut firmware, &mut hardware);
|
||||
assert!(firmware.os.paused);
|
||||
assert!(firmware.os.vm_runtime.paused);
|
||||
|
||||
debugger.handle_command(DebugCommand::Resume, &mut firmware, &mut hardware);
|
||||
assert!(!firmware.os.paused);
|
||||
assert!(!firmware.os.vm_runtime.paused);
|
||||
|
||||
debugger.handle_command(DebugCommand::StepFrame, &mut firmware, &mut hardware);
|
||||
assert!(!firmware.os.paused);
|
||||
assert!(firmware.os.debug_step_request);
|
||||
assert!(!firmware.os.vm_runtime.paused);
|
||||
assert!(firmware.os.vm_runtime.debug_step_request);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -416,11 +416,11 @@ mod tests {
|
||||
let mut hardware = Hardware::new();
|
||||
|
||||
debugger.waiting_for_start = true;
|
||||
firmware.os.paused = true;
|
||||
firmware.os.vm_runtime.paused = true;
|
||||
|
||||
debugger.handle_command(DebugCommand::Start, &mut firmware, &mut hardware);
|
||||
|
||||
assert!(!debugger.waiting_for_start);
|
||||
assert!(!firmware.os.paused);
|
||||
assert!(!firmware.os.vm_runtime.paused);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,8 +58,8 @@ struct FrameCanvas<'a> {
|
||||
}
|
||||
|
||||
pub(crate) fn capture_snapshot(stats: &HostStats, firmware: &Firmware) -> OverlaySnapshot {
|
||||
let tel = firmware.os.atomic_telemetry.snapshot();
|
||||
let recent_logs = firmware.os.log_service.get_recent(10);
|
||||
let tel = firmware.os.vm_runtime.atomic_telemetry.snapshot();
|
||||
let recent_logs = firmware.os.vm_runtime.log_service.get_recent(10);
|
||||
let violations_count =
|
||||
recent_logs.iter().filter(|e| e.tag >= 0xCA01 && e.tag <= 0xCA07).count();
|
||||
|
||||
@@ -75,7 +75,7 @@ pub(crate) fn capture_snapshot(stats: &HostStats, firmware: &Firmware) -> Overla
|
||||
});
|
||||
}
|
||||
|
||||
if let Some(report) = firmware.os.last_crash_report.as_ref() {
|
||||
if let Some(report) = firmware.os.vm_runtime.last_crash_report.as_ref() {
|
||||
footer.push(OverlayMetric {
|
||||
label: "CRASH",
|
||||
value: truncate_value(&report.summary(), 28),
|
||||
@@ -86,6 +86,7 @@ pub(crate) fn capture_snapshot(stats: &HostStats, firmware: &Firmware) -> Overla
|
||||
let cycles_ratio = ratio(tel.cycles_used, tel.cycles_budget);
|
||||
let heap_total_bytes = firmware
|
||||
.os
|
||||
.vm_runtime
|
||||
.certifier
|
||||
.config
|
||||
.max_heap_bytes
|
||||
|
||||
@@ -153,7 +153,7 @@ impl HostRunner {
|
||||
let mut firmware = Firmware::new(cap_config);
|
||||
if let Some(root) = &fs_root {
|
||||
let backend = HostDirBackend::new(root);
|
||||
firmware.os.mount_fs(Box::new(backend));
|
||||
firmware.os.vm_runtime.mount_fs(Box::new(backend));
|
||||
}
|
||||
|
||||
Self {
|
||||
@@ -204,7 +204,7 @@ impl HostRunner {
|
||||
}
|
||||
|
||||
fn machine_running(&self) -> bool {
|
||||
!self.firmware.os.paused && !self.debugger.waiting_for_start
|
||||
!self.firmware.os.vm_runtime.paused && !self.debugger.waiting_for_start
|
||||
}
|
||||
}
|
||||
|
||||
@@ -320,23 +320,26 @@ impl ApplicationHandler for HostRunner {
|
||||
fn about_to_wait(&mut self, event_loop: &ActiveEventLoop) {
|
||||
let was_debugger_connected = self.debugger.stream.is_some();
|
||||
let was_waiting_for_start = self.debugger.waiting_for_start;
|
||||
let was_paused = self.firmware.os.paused;
|
||||
let was_paused = self.firmware.os.vm_runtime.paused;
|
||||
|
||||
// 1. Process pending debug commands from the network.
|
||||
self.debugger.check_commands(&mut self.firmware, &mut self.hardware);
|
||||
|
||||
// Sync inspection mode state. This is host-owned overlay/debugger control,
|
||||
// not a guest-visible debug ABI switch.
|
||||
self.firmware.os.inspection_active = self.overlay_enabled || self.debugger.stream.is_some();
|
||||
self.firmware.os.vm_runtime.inspection_active =
|
||||
self.overlay_enabled || self.debugger.stream.is_some();
|
||||
|
||||
// 2. Maintain filesystem connection if it was lost (e.g., directory removed).
|
||||
if let Some(root) = &self.fs_root {
|
||||
use prometeu_system::fs::FsState;
|
||||
if matches!(self.firmware.os.fs_state, FsState::Unmounted | FsState::Error(_))
|
||||
&& std::path::Path::new(root).exists()
|
||||
if matches!(
|
||||
self.firmware.os.vm_runtime.fs_state,
|
||||
FsState::Unmounted | FsState::Error(_)
|
||||
) && std::path::Path::new(root).exists()
|
||||
{
|
||||
let backend = HostDirBackend::new(root);
|
||||
self.firmware.os.mount_fs(Box::new(backend));
|
||||
self.firmware.os.vm_runtime.mount_fs(Box::new(backend));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -361,13 +364,13 @@ impl ApplicationHandler for HostRunner {
|
||||
// Unless the debugger is waiting for a 'start' command, advance the system.
|
||||
if !self.debugger.waiting_for_start {
|
||||
self.firmware.tick(&self.input.signals, &mut self.hardware);
|
||||
self.stats.record_host_cpu_time(self.firmware.os.last_frame_cpu_time_us);
|
||||
self.stats.record_host_cpu_time(self.firmware.os.vm_runtime.last_frame_cpu_time_us);
|
||||
}
|
||||
|
||||
// Sync pause state with audio.
|
||||
// We do this AFTER firmware.tick to avoid MasterPause/Resume commands
|
||||
// being cleared by the OS if a new logical frame starts in this tick.
|
||||
let is_paused = self.firmware.os.paused || self.debugger.waiting_for_start;
|
||||
let is_paused = self.firmware.os.vm_runtime.paused || self.debugger.waiting_for_start;
|
||||
if is_paused != self.last_paused_state {
|
||||
self.last_paused_state = is_paused;
|
||||
let cmd =
|
||||
@@ -382,11 +385,11 @@ impl ApplicationHandler for HostRunner {
|
||||
self.stats.record_frame();
|
||||
}
|
||||
|
||||
self.presentation.note_published_frame(self.firmware.os.logical_frame_index);
|
||||
self.presentation.note_published_frame(self.firmware.os.vm_runtime.logical_frame_index);
|
||||
|
||||
if was_debugger_connected != self.debugger.stream.is_some()
|
||||
|| was_waiting_for_start != self.debugger.waiting_for_start
|
||||
|| was_paused != self.firmware.os.paused
|
||||
|| was_paused != self.firmware.os.vm_runtime.paused
|
||||
{
|
||||
self.invalidate_host_surface();
|
||||
}
|
||||
@@ -400,9 +403,9 @@ impl ApplicationHandler for HostRunner {
|
||||
// Synchronize system logs to the host console.
|
||||
let last_seq = self.log_sink.last_seq().unwrap_or(u64::MAX);
|
||||
let new_events = if last_seq == u64::MAX {
|
||||
self.firmware.os.log_service.get_recent(4096)
|
||||
self.firmware.os.vm_runtime.log_service.get_recent(4096)
|
||||
} else {
|
||||
self.firmware.os.log_service.get_after(last_seq)
|
||||
self.firmware.os.vm_runtime.log_service.get_after(last_seq)
|
||||
};
|
||||
self.log_sink.process_events(new_events);
|
||||
|
||||
@@ -812,7 +815,7 @@ mod tests {
|
||||
stream.write_all(b"{\"type\":\"pause\"}\n").expect("Should write pause");
|
||||
std::thread::sleep(std::time::Duration::from_millis(50));
|
||||
runner.debugger.check_commands(&mut runner.firmware, &mut runner.hardware);
|
||||
assert!(runner.firmware.os.paused, "VM should be paused");
|
||||
assert!(runner.firmware.os.vm_runtime.paused, "VM should be paused");
|
||||
}
|
||||
|
||||
// 2. Disconnect (stream goes out of scope)
|
||||
@@ -820,7 +823,7 @@ mod tests {
|
||||
runner.debugger.check_commands(&mut runner.firmware, &mut runner.hardware);
|
||||
|
||||
// 3. Check if unpaused
|
||||
assert!(!runner.firmware.os.paused, "VM should have unpaused after disconnect");
|
||||
assert!(!runner.firmware.os.vm_runtime.paused, "VM should have unpaused after disconnect");
|
||||
assert!(!runner.debugger.waiting_for_start, "VM should have left waiting_for_start state");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,10 +88,11 @@ impl HostStats {
|
||||
self.current_fps,
|
||||
cpu_load_core,
|
||||
cpu_load_audio,
|
||||
firmware.os.tick_index,
|
||||
firmware.os.logical_frame_index,
|
||||
firmware.os.vm_runtime.tick_index,
|
||||
firmware.os.vm_runtime.logical_frame_index,
|
||||
firmware
|
||||
.os
|
||||
.vm_runtime
|
||||
.atomic_telemetry
|
||||
.completed_logical_frames
|
||||
.load(std::sync::atomic::Ordering::Relaxed),
|
||||
|
||||
Reference in New Issue
Block a user