pub struct KvmTracer { /* private fields */ }Expand description
Traces one KVM vCPU.
Implementations§
Source§impl KvmTracer
impl KvmTracer
Sourcepub fn new(session: &Session, id: u32) -> Result<KvmTracer>
pub fn new(session: &Session, id: u32) -> Result<KvmTracer>
A tracer for vCPU id of session, writing to the session’s output.
Sourcepub fn with_tracer(session: &Session, tracer: VcpuTracer) -> KvmTracer
pub fn with_tracer(session: &Session, tracer: VcpuTracer) -> KvmTracer
Wraps an engine-level tracer (for example one with a custom sink).
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Is single-step tracing on?
Sourcepub fn tracer(&mut self) -> &mut VcpuTracer
pub fn tracer(&mut self) -> &mut VcpuTracer
The engine-level tracer.
Sourcepub fn prearm(&mut self, vcpu: &mut VcpuFd) -> Result<()>
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.)
Sourcepub fn enable(&mut self, vcpu: &mut VcpuFd) -> Result<()>
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.
Sourcepub fn disable(&mut self, vcpu: &mut VcpuFd) -> Result<()>
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.
Sourcepub fn release(&mut self, vcpu: &mut VcpuFd) -> Result<()>
pub fn release(&mut self, vcpu: &mut VcpuFd) -> Result<()>
Switches all debugging off, guard included.
Sourcepub fn needs_token(&mut self, vcpu: &VcpuFd) -> bool
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.
Sourcepub fn holds_lifted_breakpoint(&self) -> bool
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; }
}Sourcepub fn on_debug_exit(
&mut self,
vcpu: &mut VcpuFd,
d: &kvm_debug_exit_arch,
unserialized: bool,
) -> Result<StopAction>
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.
Sourcepub fn flush(&mut self, vcpu: &VcpuFd) -> Result<()>
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.