Skip to main content

KvmTracer

Struct KvmTracer 

Source
pub struct KvmTracer { /* private fields */ }
Expand description

Traces one KVM vCPU.

Implementations§

Source§

impl KvmTracer

Source

pub fn new(session: &Session, id: u32) -> Result<KvmTracer>

A tracer for vCPU id of session, writing to the session’s output.

Source

pub fn with_tracer(session: &Session, tracer: VcpuTracer) -> KvmTracer

Wraps an engine-level tracer (for example one with a custom sink).

Source

pub fn is_enabled(&self) -> bool

Is single-step tracing on?

Source

pub fn tracer(&mut self) -> &mut VcpuTracer

The engine-level tracer.

Source

pub fn prearm(&mut self, vcpu: &mut VcpuFd) -> Result<()>

Makes the vCPU report int3 to us instead of to the guest, without single-stepping yet.

On a multi-vCPU guest, call this on every vCPU, and wait until all have done so, before any of them calls enable: enable plants breakpoints in guest memory, and a vCPU without KVM_GUESTDBG_USE_SW_BP that reaches one hands #BP to the guest, which then recurses on its own breakpointed #BP handler. Likewise, when stopping, call Session::remove_breakpoints once every vCPU has stopped stepping, and only then disable. (libkvmtrace_preload does this rendezvous for QEMU.)

Source

pub fn enable(&mut self, vcpu: &mut VcpuFd) -> Result<()>

Switches tracing on. Must be called on the thread that runs the vCPU, while it is not running. See prearm for guests with more than one vCPU.

Source

pub fn disable(&mut self, vcpu: &mut VcpuFd) -> Result<()>

Switches tracing off; the guest continues at full speed.

With TraceOptions::trap_flag_guard (the default), the vCPU is left in GUARD_CONTROL instead of plain debugging-off: no single-stepping and no breakpoints, but a #DB exits to the VMM, which must pass KVM_EXIT_DEBUG exits to absorb_stale_single_step first. This costs nothing while the guest does not trap. Two consequences, both inside the guest: its own hardware breakpoints (DR0–DR7) do not fire while the guard is on, and a debugger in the guest that single-steps with TF has its traps absorbed. Call release to drop the guard.

Source

pub fn release(&mut self, vcpu: &mut VcpuFd) -> Result<()>

Switches all debugging off, guard included.

Source

pub fn needs_token(&mut self, vcpu: &VcpuFd) -> bool

Should the next KVM_RUN hold the session’s serialization token?

Not if the vCPU is halted or waiting for INIT/SIPI: it would block in the kernel holding the token until an interrupt arrives, and the vCPU that would send that interrupt could never run.

Source

pub fn holds_lifted_breakpoint(&self) -> bool

Must the serialization token be kept for the next step?

True right after the vCPU stopped on an entry breakpoint: the breakpoint is lifted for one step, and no other vCPU may run until it is back (see VcpuTracer::has_lifted_breakpoint). Keep the Token instead of dropping it:

let mut held = None;
loop {
    let token = held.take().or_else(|| if tracer.needs_token(vcpu) { session.token() } else { None });
    let exit = vcpu.run().map_err(kvmtrace::Error::kvm("KVM_RUN"))?;
    if let kvm_ioctls::VcpuExit::Debug(d) = exit {
        tracer.on_debug_exit(vcpu, &d, token.is_none())?;
    }
    if tracer.holds_lifted_breakpoint() { held = token; }
}
Source

pub fn on_debug_exit( &mut self, vcpu: &mut VcpuFd, d: &kvm_debug_exit_arch, unserialized: bool, ) -> Result<StopAction>

Handles a KVM_EXIT_DEBUG. Returns what was done; if StopAction::stop is set, the instruction budget ran out: stop all vCPUs (see prearm for the order) and call disable. The vCPU still reports breakpoints.

Source

pub fn flush(&mut self, vcpu: &VcpuFd) -> Result<()>

Records the vCPU’s last instruction from its current state, when no further debug exit will come for it: after the final VcpuExit::Hlt of a run, or before stopping a trace. See VcpuTracer::flush.

Source

pub fn finish(&mut self) -> Result<()>

Flushes this vCPU’s trace files.

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.