use core::fmt::Debug;
use core::num::NonZeroUsize;
use num_traits::{FromPrimitive, PrimInt, Unsigned};
use crate::internal::{BeBytes, LeBytes};
pub trait RegId: Sized + Debug {
fn from_raw_id(id: usize) -> Option<(Self, Option<NonZeroUsize>)>;
}
impl RegId for () {
fn from_raw_id(_id: usize) -> Option<(Self, Option<NonZeroUsize>)> {
None
}
}
pub trait Registers: Default + Debug + Clone + PartialEq {
type ProgramCounter: Copy;
fn pc(&self) -> Self::ProgramCounter;
fn gdb_serialize(&self, write_byte: impl FnMut(Option<u8>));
#[allow(clippy::result_unit_err)]
fn gdb_deserialize(&mut self, bytes: &[u8]) -> Result<(), ()>;
}
pub trait BreakpointKind: Sized + Debug {
fn from_usize(kind: usize) -> Option<Self>;
}
impl BreakpointKind for () {
fn from_usize(kind: usize) -> Option<Self> {
if kind != 0 {
None
} else {
Some(())
}
}
}
impl BreakpointKind for usize {
#[allow(clippy::wrong_self_convention)]
fn from_usize(kind: usize) -> Option<Self> {
Some(kind)
}
}
pub trait Arch {
type Usize: Debug + FromPrimitive + PrimInt + Unsigned + BeBytes + LeBytes;
type Registers: Registers<ProgramCounter = Self::Usize>;
type BreakpointKind: BreakpointKind;
type RegId: RegId;
#[inline(always)]
fn target_description_xml() -> Option<&'static str> {
None
}
#[inline(always)]
fn lldb_register_info(reg_id: usize) -> Option<lldb::RegisterInfo<'static>> {
let _ = reg_id;
None
}
fn single_step_gdb_behavior() -> SingleStepGdbBehavior;
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy)]
pub enum SingleStepGdbBehavior {
Optional,
Required,
Ignored,
#[doc(hidden)]
Unknown,
}
pub mod lldb {
pub enum RegisterInfo<'a> {
Register(Register<'a>),
Done,
}
pub struct Register<'a> {
pub name: &'a str,
pub alt_name: Option<&'a str>,
pub bitsize: usize,
pub offset: usize,
pub encoding: Encoding,
pub format: Format,
pub set: &'a str,
pub gcc: Option<usize>,
pub dwarf: Option<usize>,
pub generic: Option<Generic>,
pub container_regs: Option<&'a [usize]>,
pub invalidate_regs: Option<&'a [usize]>,
}
#[non_exhaustive]
pub enum Encoding {
Uint,
Sint,
IEEE754,
Vector,
}
#[non_exhaustive]
pub enum Format {
Binary,
Decimal,
Hex,
Float,
VectorSInt8,
VectorUInt8,
VectorSInt16,
VectorUInt16,
VectorSInt32,
VectorUInt32,
VectorFloat32,
VectorUInt128,
}
#[non_exhaustive]
pub enum Generic {
Pc,
Sp,
Fp,
Ra,
Flags,
Arg1,
Arg2,
Arg3,
Arg4,
Arg5,
Arg6,
Arg7,
Arg8,
}
}