vmm_core_defs/
debug_rpc.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! The message definitions used to process debugging requests from
5//! `debug_worker`.
6
7use mesh::payload::Protobuf;
8pub use virt::x86::BreakpointSize;
9pub use virt::x86::BreakpointType;
10pub use virt::x86::DebugState;
11pub use virt::x86::HardwareBreakpoint;
12
13use mesh::MeshPayload;
14use mesh::rpc::FailableRpc;
15use virt::x86::SegmentRegister;
16
17#[derive(Debug, MeshPayload)]
18pub enum DebugRequest {
19    /// The debugger has been attached.
20    Attach,
21    /// The debugger has been detached.
22    Detach,
23    /// Resume the VM, responding with a [`DebugStopReason`] once the VM encounters a stop condition (e.g: breakpoint hit)
24    Resume {
25        response: mesh::OneshotSender<DebugStopReason>,
26    },
27    /// Debugger is requesting a manual break.
28    Break,
29    /// Sets the hardware debugger state for a VP.
30    SetDebugState { vp: u32, state: DebugState },
31    /// Fetch the specified vp's register state.
32    GetVpState(FailableRpc<u32, Box<DebuggerVpState>>),
33    /// Set the specified vp's register state.
34    SetVpState(FailableRpc<(u32, Box<DebuggerVpState>), ()>),
35    /// Read from the specified GPA from the guest.
36    ReadMemory(FailableRpc<(GuestAddress, usize), Vec<u8>>),
37    /// Write to the specified GPA from the guest.
38    WriteMemory(FailableRpc<(GuestAddress, Vec<u8>), ()>),
39}
40
41/// Register state for a VP.
42///
43/// This has all the supported architectures embedded in it to avoid having
44/// arch-specific compilation at this layer.
45#[derive(Debug, Protobuf)]
46pub enum DebuggerVpState {
47    X86_64(X86VpState),
48    Aarch64(Aarch64VpState),
49}
50
51/// Subset of VP state for debuggers.
52#[derive(Debug, PartialEq, Eq, Protobuf)]
53pub struct X86VpState {
54    pub gp: [u64; 16],
55    pub rip: u64,
56    pub rflags: u64,
57    pub cr0: u64,
58    pub cr2: u64,
59    pub cr3: u64,
60    pub cr4: u64,
61    pub cr8: u64,
62    pub efer: u64,
63    pub kernel_gs_base: u64,
64    pub es: SegmentRegister,
65    pub cs: SegmentRegister,
66    pub ss: SegmentRegister,
67    pub ds: SegmentRegister,
68    pub fs: SegmentRegister,
69    pub gs: SegmentRegister,
70}
71
72#[derive(Debug, PartialEq, Eq, Protobuf)]
73pub struct Aarch64VpState {
74    pub x: [u64; 31],
75    pub sp_el0: u64,
76    pub sp_el1: u64,
77    pub pc: u64,
78    pub cpsr: u64,
79    pub sctlr_el1: u64,
80    pub tcr_el1: u64,
81    pub ttbr0_el1: u64,
82    pub ttbr1_el1: u64,
83}
84
85/// An address within the Guest
86#[derive(Debug, MeshPayload)]
87pub enum GuestAddress {
88    /// Guest Virtual Address
89    Gva { vp: u32, gva: u64 },
90    /// Guest Physical Address
91    Gpa(u64),
92}
93
94#[derive(MeshPayload, Debug)]
95pub enum DebugStopReason {
96    /// Break has been acknowledged + executed.
97    Break,
98    /// VM has powered off.
99    PowerOff,
100    /// VM has been reset.
101    Reset,
102    /// `vp` has encountered a triple fault.
103    TripleFault { vp: u32 },
104    /// `vp` has completed a single step.
105    SingleStep { vp: u32 },
106    /// `vp` has reached a hardware breakpoint.
107    HwBreakpoint {
108        vp: u32,
109        breakpoint: HardwareBreakpoint,
110    },
111}