implements PR-007 to PR011

This commit is contained in:
2026-03-24 13:40:46 +00:00
parent c0ed9ba8e0
commit a75df486ce
19 changed files with 978 additions and 117 deletions
@@ -2,6 +2,7 @@ use prometeu_drivers::hardware::Hardware;
use prometeu_firmware::{BootTarget, Firmware};
use prometeu_hal::cartridge_loader::CartridgeLoader;
use prometeu_hal::debugger_protocol::*;
use prometeu_system::CrashReport;
use std::io::{Read, Write};
use std::net::{TcpListener, TcpStream};
@@ -22,6 +23,8 @@ pub struct HostDebugger {
last_log_seq: u64,
/// Frame tracker to send telemetry snapshots periodically.
last_telemetry_frame: u64,
/// Last fault summary sent to the debugger client.
last_fault_summary: Option<String>,
}
impl HostDebugger {
@@ -33,6 +36,7 @@ impl HostDebugger {
stream: None,
last_log_seq: 0,
last_telemetry_frame: 0,
last_fault_summary: None,
}
}
@@ -96,6 +100,7 @@ impl HostDebugger {
stream.set_nonblocking(true).expect("Cannot set non-blocking on stream");
self.stream = Some(stream);
self.last_fault_summary = None;
// Immediately send the Handshake message to identify the Runtime and App.
let handshake = DebugResponse::Handshake {
@@ -221,6 +226,12 @@ 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() {
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);
for event in new_events {
@@ -295,4 +306,25 @@ impl HostDebugger {
self.last_telemetry_frame = current_frame;
}
}
fn stream_fault(&mut self, report: &CrashReport) {
let summary = report.summary();
if self.last_fault_summary.as_deref() == Some(summary.as_str()) {
return;
}
let (trap_code, opcode) = match report {
CrashReport::VmTrap { trap } => (Some(trap.code), Some(trap.opcode)),
CrashReport::VmPanic { .. } | CrashReport::VmInit { .. } => (None, None),
};
self.send_event(DebugEvent::Fault {
kind: report.kind().to_string(),
summary: summary.clone(),
pc: report.pc(),
trap_code,
opcode,
});
self.last_fault_summary = Some(summary);
}
}
@@ -207,6 +207,14 @@ impl HostRunner {
self.hardware.gfx.draw_text(10, 90, &msg, color_warn);
}
}
if let Some(report) = self.firmware.os.last_crash_report.as_ref() {
let mut msg = report.summary();
if msg.len() > 30 {
msg.truncate(30);
}
self.hardware.gfx.draw_text(10, 98, &msg, color_warn);
}
}
}