use gdbstub::{
common::Tid,
target::{
TargetError,
ext::{host_io::HostIoErrno, monitor_cmd::ConsoleOutput},
},
};
use snafu::Snafu;
use crate::{
exceptions::DebugEventContext,
gdb_target::{V5Target, arch::ArmRegisterID, single_register_access::SavedRegister},
};
cfg_select! {
feature = "freertos" => {
pub mod freertos;
pub type System = freertos::FreeRtosSystem;
}
_ => {
pub mod bare;
pub type System = bare::BareSystem;
}
}
pub trait DebuggerSystem {
const MULTITHREADED: bool;
fn initialize(target: &mut V5Target);
fn suspend_preemption();
fn current_thread() -> Tid;
fn thread_exists(tid: Tid) -> bool;
fn all_threads(handler: &mut dyn FnMut(Tid));
fn read_thread_name(tid: Tid, buf: &mut [u8]) -> Result<usize, SystemError>;
fn read_registers(tid: Tid) -> Result<DebugEventContext, SystemError>;
unsafe fn write_registers(tid: Tid, registers: &DebugEventContext) -> Result<(), SystemError>;
fn read_single_register(tid: Tid, id: ArmRegisterID) -> Result<SavedRegister, SystemError>;
unsafe fn write_single_register(
tid: Tid,
id: ArmRegisterID,
value: SavedRegister,
) -> Result<(), SystemError>;
fn handle_monitor_cmd<'a>(_args: impl Iterator<Item = &'a str>, out: &mut ConsoleOutput) {
gdbstub::outputln!(out, "This system doesn't support the `sys` subcommand.");
}
}
#[derive(Debug, Snafu, Clone, Copy)]
pub enum SystemError {
NoSuchTid,
}
impl<T> From<SystemError> for TargetError<T> {
fn from(value: SystemError) -> Self {
match value {
SystemError::NoSuchTid => TargetError::Errno(HostIoErrno::EINVAL as u8),
}
}
}