-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactors debugging-related code (#1123)
- Loading branch information
1 parent
1005d74
commit 12c65cd
Showing
3 changed files
with
121 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,96 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
use super::cpu::CpuManager; | ||
use super::cpu::{CpuManager, GdbError}; | ||
use crate::debug::DebugClient; | ||
use crate::error::RustError; | ||
use crate::hv::Hypervisor; | ||
use crate::screen::Screen; | ||
use gdbstub::stub::state_machine::state::{Idle, Running}; | ||
use gdbstub::stub::state_machine::{GdbStubStateMachine, GdbStubStateMachineInner}; | ||
use gdbstub::stub::MultiThreadStopReason; | ||
use thiserror::Error; | ||
|
||
pub fn dispatch_idle<H: Hypervisor, S: Screen>( | ||
target: &mut CpuManager<H, S>, | ||
mut state: GdbStubStateMachineInner< | ||
'static, | ||
Idle<CpuManager<H, S>>, | ||
CpuManager<H, S>, | ||
DebugClient, | ||
>, | ||
) -> Result< | ||
Result< | ||
GdbStubStateMachine<'static, CpuManager<H, S>, DebugClient>, | ||
GdbStubStateMachineInner<'static, Idle<CpuManager<H, S>>, CpuManager<H, S>, DebugClient>, | ||
>, | ||
RustError, | ||
> { | ||
// Check for pending command. | ||
let b = match state.borrow_conn().read() { | ||
Ok(v) => v, | ||
Err(e) if e.kind() == std::io::ErrorKind::WouldBlock => return Ok(Err(state)), | ||
Err(e) => { | ||
return Err(RustError::with_source( | ||
"couldn't read data from the debugger", | ||
e, | ||
)); | ||
impl<H: Hypervisor, S: Screen> CpuManager<H, S> { | ||
pub(super) fn dispatch_gdb_idle( | ||
&mut self, | ||
mut state: GdbStubStateMachineInner< | ||
'static, | ||
Idle<CpuManager<H, S>>, | ||
CpuManager<H, S>, | ||
DebugClient, | ||
>, | ||
) -> Result< | ||
Result< | ||
GdbStubStateMachine<'static, CpuManager<H, S>, DebugClient>, | ||
GdbStubStateMachineInner< | ||
'static, | ||
Idle<CpuManager<H, S>>, | ||
CpuManager<H, S>, | ||
DebugClient, | ||
>, | ||
>, | ||
DispatchGdbIdleError, | ||
> { | ||
let b = match state.borrow_conn().read() { | ||
Ok(v) => v, | ||
Err(e) if e.kind() == std::io::ErrorKind::WouldBlock => return Ok(Err(state)), | ||
Err(e) => return Err(DispatchGdbIdleError::ReadData(e)), | ||
}; | ||
|
||
state | ||
.incoming_data(self, b) | ||
.map(Ok) | ||
.map_err(DispatchGdbIdleError::ProcessData) | ||
} | ||
|
||
pub(super) fn dispatch_gdb_running( | ||
&mut self, | ||
mut state: GdbStubStateMachineInner<'static, Running, CpuManager<H, S>, DebugClient>, | ||
stop: Option<MultiThreadStopReason<u64>>, | ||
) -> Result< | ||
Result< | ||
GdbStubStateMachine<'static, CpuManager<H, S>, DebugClient>, | ||
GdbStubStateMachineInner<'static, Running, CpuManager<H, S>, DebugClient>, | ||
>, | ||
DispatchGdbRunningError, | ||
> { | ||
// Check If we are here because of a breakpoint. | ||
if let Some(r) = stop { | ||
return state | ||
.report_stop(self, r) | ||
.map(Ok) | ||
.map_err(DispatchGdbRunningError::ReportStopReason); | ||
} | ||
}; | ||
|
||
state | ||
.incoming_data(target, b) | ||
.map(Ok) | ||
.map_err(|e| RustError::with_source("couldn't process data from the debugger", e)) | ||
} | ||
// Check for pending command. | ||
let b = match state.borrow_conn().read() { | ||
Ok(v) => v, | ||
Err(e) if e.kind() == std::io::ErrorKind::WouldBlock => return Ok(Err(state)), | ||
Err(e) => return Err(DispatchGdbRunningError::ReadData(e)), | ||
}; | ||
|
||
pub fn dispatch_running<H: Hypervisor, S: Screen>( | ||
target: &mut CpuManager<H, S>, | ||
mut state: GdbStubStateMachineInner<'static, Running, CpuManager<H, S>, DebugClient>, | ||
stop: Option<MultiThreadStopReason<u64>>, | ||
) -> Result< | ||
Result< | ||
GdbStubStateMachine<'static, CpuManager<H, S>, DebugClient>, | ||
GdbStubStateMachineInner<'static, Running, CpuManager<H, S>, DebugClient>, | ||
>, | ||
RustError, | ||
> { | ||
// Check If we are here because of a breakpoint. | ||
if let Some(r) = stop { | ||
return state | ||
.report_stop(target, r) | ||
state | ||
.incoming_data(self, b) | ||
.map(Ok) | ||
.map_err(|e| RustError::with_source("couldn't report stop reason to the debugger", e)); | ||
.map_err(DispatchGdbRunningError::ProcessData) | ||
} | ||
} | ||
|
||
// Check for pending command. | ||
let b = match state.borrow_conn().read() { | ||
Ok(v) => v, | ||
Err(e) if e.kind() == std::io::ErrorKind::WouldBlock => return Ok(Err(state)), | ||
Err(e) => { | ||
return Err(RustError::with_source( | ||
"couldn't read data from the debugger", | ||
e, | ||
)); | ||
} | ||
}; | ||
#[derive(Debug, Error)] | ||
pub(super) enum DispatchGdbIdleError { | ||
#[error("couldn't read data from the debugger")] | ||
ReadData(#[source] std::io::Error), | ||
|
||
#[error("couldn't process data from the debugger")] | ||
ProcessData(#[source] gdbstub::stub::GdbStubError<GdbError, std::io::Error>), | ||
} | ||
|
||
#[derive(Debug, Error)] | ||
pub(super) enum DispatchGdbRunningError { | ||
#[error("couldn't report stop reason to the debugger")] | ||
ReportStopReason(#[source] gdbstub::stub::GdbStubError<GdbError, std::io::Error>), | ||
|
||
#[error("couldn't read data from the debugger")] | ||
ReadData(#[source] std::io::Error), | ||
|
||
state | ||
.incoming_data(target, b) | ||
.map(Ok) | ||
.map_err(|e| RustError::with_source("couldn't process data from the debugger", e)) | ||
#[error("couldn't process data from the debugger")] | ||
ProcessData(#[source] gdbstub::stub::GdbStubError<GdbError, std::io::Error>), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters