Skip to content

Commit c46cdca

Browse files
authored
Changes return type of CpuDebug::reason (#1291)
1 parent 39ceb71 commit c46cdca

File tree

5 files changed

+17
-20
lines changed

5 files changed

+17
-20
lines changed

gui/src/hv/linux/cpu.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
use super::arch::{KvmStates, StatesError};
33
use super::ffi::{KVM_EXIT_DEBUG, KVM_EXIT_HLT, KVM_EXIT_IO, KVM_RUN};
44
use super::run::KvmRun;
5-
use crate::hv::{Cpu, CpuDebug, CpuExit, CpuIo, CpuRun, IoBuf};
6-
use gdbstub::stub::MultiThreadStopReason;
5+
use crate::hv::{Cpu, CpuDebug, CpuExit, CpuIo, CpuRun, DebugEvent, IoBuf};
76
use libc::{ioctl, munmap};
8-
use std::num::NonZero;
97
use std::os::fd::{AsRawFd, OwnedFd};
108
use std::sync::MutexGuard;
119

@@ -168,15 +166,11 @@ pub struct KvmDebug<'a, 'b>(&'a mut KvmCpu<'b>);
168166
impl<'b> CpuDebug for KvmDebug<'_, 'b> {
169167
type Cpu = KvmCpu<'b>;
170168

171-
fn reason(&mut self) -> MultiThreadStopReason<u64> {
169+
fn reason(&mut self) -> DebugEvent {
172170
let debug = unsafe { (*self.0.cx.0).exit.debug.arch };
173171

174172
match debug.exception {
175-
3 => {
176-
let tid = NonZero::new(self.0.id + 1).unwrap();
177-
178-
MultiThreadStopReason::SwBreak(tid)
179-
}
173+
3 => DebugEvent::SwBreak,
180174
exception => todo!("unhandled exception {exception}"),
181175
}
182176
}

gui/src/hv/macos/cpu.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT OR Apache-2.0
2-
use crate::hv::{Cpu, CpuCommit, CpuDebug, CpuExit, CpuIo, CpuRun, CpuStates, IoBuf};
2+
use crate::hv::{Cpu, CpuCommit, CpuDebug, CpuExit, CpuIo, CpuRun, CpuStates, DebugEvent, IoBuf};
33
use aarch64::Esr;
44
use applevisor_sys::hv_exit_reason_t::HV_EXIT_REASON_EXCEPTION;
55
use applevisor_sys::hv_reg_t::{HV_REG_CPSR, HV_REG_PC, HV_REG_X0, HV_REG_X1};
@@ -11,7 +11,6 @@ use applevisor_sys::{
1111
hv_return_t, hv_vcpu_destroy, hv_vcpu_exit_t, hv_vcpu_run, hv_vcpu_set_reg,
1212
hv_vcpu_set_sys_reg, hv_vcpu_t,
1313
};
14-
use gdbstub::stub::MultiThreadStopReason;
1514
use std::marker::PhantomData;
1615
use std::num::NonZero;
1716
use thiserror::Error;
@@ -281,7 +280,7 @@ pub struct HvfDebug<'a, 'b>(&'a mut HvfCpu<'b>);
281280
impl<'a, 'b> CpuDebug for HvfDebug<'a, 'b> {
282281
type Cpu = HvfCpu<'b>;
283282

284-
fn reason(&mut self) -> MultiThreadStopReason<u64> {
283+
fn reason(&mut self) -> DebugEvent {
285284
todo!()
286285
}
287286

gui/src/hv/mod.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ pub use self::arch::*;
33
pub use self::os::{HvError, new};
44
pub use self::ram::*;
55

6-
use gdbstub::stub::MultiThreadStopReason;
76
use std::error::Error;
87

98
#[cfg_attr(target_arch = "aarch64", path = "aarch64.rs")]
@@ -94,6 +93,11 @@ pub enum IoBuf<'a> {
9493
pub trait CpuDebug {
9594
type Cpu: Cpu;
9695

97-
fn reason(&mut self) -> MultiThreadStopReason<u64>;
96+
fn reason(&mut self) -> DebugEvent;
9897
fn cpu(&mut self) -> &mut Self::Cpu;
9998
}
99+
100+
/// The debug event that cause the VM to exit.
101+
pub enum DebugEvent {
102+
SwBreak,
103+
}

gui/src/hv/windows/cpu.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// SPDX-License-Identifier: MIT OR Apache-2.0
2-
use crate::hv::{Cpu, CpuCommit, CpuDebug, CpuExit, CpuIo, CpuRun, CpuStates, IoBuf};
3-
use gdbstub::stub::MultiThreadStopReason;
2+
use crate::hv::{Cpu, CpuCommit, CpuDebug, CpuExit, CpuIo, CpuRun, CpuStates, DebugEvent, IoBuf};
43
use std::marker::PhantomData;
54
use std::mem::{MaybeUninit, size_of, zeroed};
65
use thiserror::Error;
@@ -561,7 +560,7 @@ pub struct WhpDebug<'a, 'b> {
561560
impl<'a, 'b> CpuDebug for WhpDebug<'a, 'b> {
562561
type Cpu = WhpCpu<'b>;
563562

564-
fn reason(&mut self) -> MultiThreadStopReason<u64> {
563+
fn reason(&mut self) -> DebugEvent {
565564
todo!()
566565
}
567566

gui/src/vmm/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ use self::kernel::{
88
};
99
use self::ram::{RamBuilder, RamMap};
1010
use crate::gdb::GdbHandler;
11-
use crate::hv::{CpuDebug, CpuExit, CpuIo, CpuRun, CpuStates, HvError, Hypervisor, Ram};
11+
use crate::hv::{
12+
CpuDebug, CpuExit, CpuIo, CpuRun, CpuStates, DebugEvent, HvError, Hypervisor, Ram,
13+
};
1214
use crate::profile::Profile;
1315
use config::{BootEnv, ConsoleType, Vm};
1416
use futures::{FutureExt, select_biased};
1517
use gdbstub::common::{Signal, Tid};
16-
use gdbstub::stub::MultiThreadStopReason;
1718
use gdbstub::target::ext::base::multithread::{
1819
MultiThreadBase, MultiThreadResume, MultiThreadResumeOps,
1920
};
@@ -474,7 +475,7 @@ impl<H: Hypervisor> Vmm<H> {
474475
args: &CpuArgs<H>,
475476
debug: &self::cpu::debug::Debugger,
476477
cpu: &mut impl crate::hv::Cpu,
477-
stop: Option<MultiThreadStopReason<u64>>,
478+
stop: Option<DebugEvent>,
478479
) -> Result<Option<bool>, CpuError> {
479480
// Notify GUI. We need to allow only one CPU to enter the debugger dispatch loop.
480481
let lock = args.breakpoint.lock().unwrap();

0 commit comments

Comments
 (0)