#[derive(Debug, Clone, PartialEq, Eq)]
pub enum DbgError {
Truncated,
BadMagic(u16),
UnterminatedName,
}
impl std::fmt::Display for DbgError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Truncated => write!(f, "truncated debug block"),
Self::BadMagic(m) => write!(f, "invalid magic: {m:#06x}"),
Self::UnterminatedName => write!(f, "unterminated name in debug block"),
}
}
}
impl std::error::Error for DbgError {}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Ident {
Variable,
Reference,
Array,
RefArray,
Function,
Other(u8),
}
impl Ident {
pub(crate) fn from_byte(b: u8) -> Self {
match b {
1 => Self::Variable,
2 => Self::Reference,
3 => Self::Array,
4 => Self::RefArray,
9 => Self::Function,
other => Self::Other(other),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum VClass {
Global,
Local,
Argument,
Other(u8),
}
impl VClass {
pub(crate) fn from_byte(b: u8) -> Self {
match b {
0 => Self::Global,
1 => Self::Local,
2 => Self::Argument,
other => Self::Other(other),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DbgFile {
pub address: u32,
pub name: String,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct DbgLine {
pub address: u32,
pub line: i32,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct DbgSymDim {
pub tag: i16,
pub size: u32,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DbgSymbol {
pub address: u32,
pub tag: i16,
pub codestart: u32,
pub codeend: u32,
pub ident: Ident,
pub vclass: VClass,
pub name: String,
pub dims: Vec<DbgSymDim>,
}
impl DbgSymbol {
#[must_use]
pub fn effective_address(&self, frm: i32) -> i32 {
match self.vclass {
VClass::Global => i32::try_from(self.address).unwrap_or(0),
_ => frm.wrapping_add(self.address.cast_signed()),
}
}
#[must_use]
pub fn is_array(&self) -> bool {
matches!(self.ident, Ident::Array | Ident::RefArray)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DbgTag {
pub tag: i16,
pub name: String,
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct AmxDbg {
pub file_version: u8,
pub amx_version: u8,
pub files: Vec<DbgFile>,
pub lines: Vec<DbgLine>,
pub symbols: Vec<DbgSymbol>,
pub tags: Vec<DbgTag>,
}