implements PLN-0053
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
use super::dispatch::VmRuntimeHost;
|
||||
use super::*;
|
||||
use crate::CrashReport;
|
||||
use prometeu_hal::asset::{BankTelemetry, BankType};
|
||||
use prometeu_hal::log::{LogLevel, LogSource};
|
||||
use prometeu_hal::log::{LogLevel, LogService, LogSource};
|
||||
use prometeu_hal::{HardwareBridge, HostContext, InputSignals};
|
||||
use prometeu_vm::LogicalFrameEndingReason;
|
||||
use std::panic::{AssertUnwindSafe, catch_unwind};
|
||||
@@ -52,11 +53,17 @@ impl VirtualMachineRuntime {
|
||||
|
||||
pub fn debug_step_instruction(
|
||||
&mut self,
|
||||
log_service: &mut LogService,
|
||||
vm: &mut VirtualMachine,
|
||||
hw: &mut dyn HardwareBridge,
|
||||
) -> Option<CrashReport> {
|
||||
let mut ctx = HostContext::new(Some(hw));
|
||||
match vm.step(self, &mut ctx) {
|
||||
let step_result = {
|
||||
let mut ctx = HostContext::new(Some(hw));
|
||||
let mut host = VmRuntimeHost { runtime: self, log_service };
|
||||
vm.step(&mut host, &mut ctx)
|
||||
};
|
||||
|
||||
match step_result {
|
||||
Ok(_) => None,
|
||||
Err(e) => {
|
||||
let report = match e {
|
||||
@@ -70,6 +77,7 @@ impl VirtualMachineRuntime {
|
||||
},
|
||||
};
|
||||
self.log(
|
||||
log_service,
|
||||
LogLevel::Error,
|
||||
LogSource::Vm,
|
||||
report.log_tag(),
|
||||
@@ -83,6 +91,7 @@ impl VirtualMachineRuntime {
|
||||
|
||||
pub fn tick(
|
||||
&mut self,
|
||||
log_service: &mut LogService,
|
||||
vm: &mut VirtualMachine,
|
||||
signals: &InputSignals,
|
||||
hw: &mut dyn HardwareBridge,
|
||||
@@ -94,7 +103,7 @@ impl VirtualMachineRuntime {
|
||||
return None;
|
||||
}
|
||||
|
||||
self.update_fs();
|
||||
self.update_fs(log_service);
|
||||
|
||||
if !self.logical_frame_active {
|
||||
self.logical_frame_active = true;
|
||||
@@ -128,7 +137,8 @@ impl VirtualMachineRuntime {
|
||||
if budget > 0 {
|
||||
let run_result = {
|
||||
let mut ctx = HostContext::new(Some(hw));
|
||||
vm.run_budget(budget, self, &mut ctx)
|
||||
let mut host = VmRuntimeHost { runtime: self, log_service };
|
||||
vm.run_budget(budget, &mut host, &mut ctx)
|
||||
};
|
||||
|
||||
match run_result {
|
||||
@@ -143,6 +153,7 @@ impl VirtualMachineRuntime {
|
||||
self.paused = true;
|
||||
self.debug_step_request = false;
|
||||
self.log(
|
||||
log_service,
|
||||
LogLevel::Info,
|
||||
LogSource::Vm,
|
||||
0xDEB1,
|
||||
@@ -154,6 +165,7 @@ impl VirtualMachineRuntime {
|
||||
let report =
|
||||
CrashReport::VmPanic { message: err, pc: Some(vm.pc() as u32) };
|
||||
self.log(
|
||||
log_service,
|
||||
LogLevel::Error,
|
||||
LogSource::Vm,
|
||||
report.log_tag(),
|
||||
@@ -166,6 +178,7 @@ impl VirtualMachineRuntime {
|
||||
if let LogicalFrameEndingReason::Trap(trap) = &run.reason {
|
||||
let report = CrashReport::VmTrap { trap: trap.clone() };
|
||||
self.log(
|
||||
log_service,
|
||||
LogLevel::Error,
|
||||
LogSource::Vm,
|
||||
report.log_tag(),
|
||||
@@ -182,6 +195,7 @@ impl VirtualMachineRuntime {
|
||||
let message = Self::host_panic_payload_to_string(payload);
|
||||
let report = CrashReport::VmPanic { message, pc: Some(vm.pc() as u32) };
|
||||
self.log(
|
||||
log_service,
|
||||
LogLevel::Error,
|
||||
LogSource::Vm,
|
||||
report.log_tag(),
|
||||
@@ -229,18 +243,15 @@ impl VirtualMachineRuntime {
|
||||
let ts_ms = self.boot_time.elapsed().as_millis() as u64;
|
||||
let telemetry_snapshot = self.atomic_telemetry.snapshot();
|
||||
|
||||
let violations = self.certifier.evaluate(
|
||||
&telemetry_snapshot,
|
||||
&mut self.log_service,
|
||||
ts_ms,
|
||||
) as u32;
|
||||
let violations =
|
||||
self.certifier.evaluate(&telemetry_snapshot, log_service, ts_ms) as u32;
|
||||
|
||||
self.atomic_telemetry.violations.store(violations, Ordering::Relaxed);
|
||||
self.atomic_telemetry
|
||||
.completed_logical_frames
|
||||
.fetch_add(1, Ordering::Relaxed);
|
||||
|
||||
self.log_service.reset_count();
|
||||
log_service.reset_count();
|
||||
|
||||
self.logical_frame_index += 1;
|
||||
self.logical_frame_active = false;
|
||||
@@ -258,7 +269,13 @@ impl VirtualMachineRuntime {
|
||||
}
|
||||
Err(e) => {
|
||||
let report = CrashReport::VmPanic { message: e, pc: Some(vm.pc() as u32) };
|
||||
self.log(LogLevel::Error, LogSource::Vm, report.log_tag(), report.summary());
|
||||
self.log(
|
||||
log_service,
|
||||
LogLevel::Error,
|
||||
LogSource::Vm,
|
||||
report.log_tag(),
|
||||
report.summary(),
|
||||
);
|
||||
self.last_crash_report = Some(report.clone());
|
||||
return Some(report);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user