Skip to main content

TraceState

Struct TraceState 

Source
pub struct TraceState {
    pub watchpoints: Vec<Watchpoint>,
    pub sink: RefCell<Option<Box<dyn Write + Send>>>,
    pub exec_on: bool,
    pub last_eip: u32,
}
Expand description

Per-sandbox trace state — owned by crate::emulator::Mmu so the MMU’s hot path can consult watchpoints without an extra indirection, and shared via &mut with the higher layers (Cpu, Sandbox, Win32 dispatch) that emit their own probe flavours.

Fields§

§watchpoints: Vec<Watchpoint>

Active watchpoints. Linear-scan inside hot paths; we don’t expect more than a handful at a time per spec.

§sink: RefCell<Option<Box<dyn Write + Send>>>

Sink that JSONL events flush to. None ⇒ events are silently dropped (per the design doc), even when the feature is on.

Wrapped in RefCell so the immutable load paths in the MMU (which take &self) can still emit a mem_read event without forcing every caller in the crate onto a &mut Mmu borrow.

§exec_on: bool

true when the trace-exec sub-feature is on AND the runtime has flipped the per-instruction trace on. The feature flag alone gates compilation; this flag gates emission per-step, so a sandbox can toggle exec trace mid run when triaging a specific section.

§last_eip: u32

Mirror of cpu.regs.eip updated by crate::emulator::Cpu::step before each MMU access — the MMU itself doesn’t have a reference to the CPU, so we shadow the EIP into the trace state on the slow probe path.

Implementations§

Source§

impl TraceState

Source

pub fn new() -> Self

Create a TraceState with an empty watchpoint set, the default sink (env-var) installed, and exec-trace off.

Source

pub fn watch(&mut self, addr: u32, size: u32, mode: WatchMode)

Install a watchpoint. Multiple watchpoints may overlap; each fires independently. A duplicate (addr, size, mode) is registered as a separate entry — callers wanting de-dup can use Self::unwatch first.

Source

pub fn unwatch(&mut self, addr: u32, size: u32)

Remove watchpoints whose (addr, size) exactly matches. Mode is ignored for the match — the design doc treats a (addr, size) pair as the watchpoint identity.

Source

pub fn set_sink(&mut self, sink: Box<dyn Write + Send>)

Override the sink at runtime. Use this from tests to capture events into a Vec<u8>-backed Box<dyn Write>.

Source

pub fn clear_sink(&mut self)

Convenience inverse — tear down the current sink so subsequent emits drop silently.

Source

pub fn set_eip(&mut self, eip: u32)

Set the per-step EIP shadow. Called by crate::emulator::Cpu::step once per instruction so the MMU’s mem_read / mem_write probes can include the faulting EIP without taking another reference to the CPU.

Source

pub fn matched_for_write(&self, addr: u32, size: u32) -> Option<&Watchpoint>

Walk the watchpoint list — return the first watchpoint whose mode + range matches the access, or None.

Source

pub fn matched_for_read(&self, addr: u32, size: u32) -> Option<&Watchpoint>

As above for reads.

Source

pub fn emit_line(&self, line: &str)

Write one already-formatted JSONL line followed by \n. Errors are silenced — the trace tape is a debugging convenience, not part of any correctness contract.

Source

pub fn has_sink(&self) -> bool

True iff a sink is currently installed. Used by emit helpers to short-circuit the formatting work when the event would be dropped.

Source

pub fn ev_win32_call( &self, dll: &str, name: &str, args: &[u32], ret: u32, eip: u32, )

Emit a kind=win32_call event.

args is captured from the guest stack at call time; ret is the dword the stub put back into eax.

Source

pub fn ev_mem_write(&self, addr: u32, size: u32, value: u64, eip: u32)

Emit a kind=mem_write event.

Source

pub fn ev_mem_read(&self, addr: u32, size: u32, value: u64, eip: u32)

Emit a kind=mem_read event.

Source

pub fn ev_exec( &self, eip: u32, bytes: &[u8], mnemonic: &str, registers: &[(&str, u32)], )

Emit a kind=exec event. bytes is hex-encoded (opcode_bytes field in the design doc); mnemonic is a short SDM-style hint when available, or just the leading opcode byte otherwise.

Source

pub fn ev_trap( &self, trap: &str, eip: u32, opcode: Option<u32>, registers: &[(&str, u32)], )

Emit a kind=trap event.

Trait Implementations§

Source§

impl Default for TraceState

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.