Skip to content

Commit

Permalink
add gdb sw breakpoint
Browse files Browse the repository at this point in the history
Signed-off-by: Doru Blânzeanu <[email protected]>
  • Loading branch information
dblnz committed Dec 17, 2024
1 parent d1878d2 commit 8f4a63f
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/hyperlight_host/src/hypervisor/gdb/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use gdbstub::target::ext::base::singlethread::{
};
use gdbstub::target::ext::base::BaseOps;
use gdbstub::target::ext::breakpoints::{
Breakpoints, BreakpointsOps, HwBreakpoint, HwBreakpointOps,
Breakpoints, BreakpointsOps, HwBreakpoint, HwBreakpointOps, SwBreakpoint, SwBreakpointOps,
};
use gdbstub::target::ext::section_offsets::{Offsets, SectionOffsets};
use gdbstub::target::{Target, TargetError, TargetResult};
Expand Down Expand Up @@ -158,6 +158,10 @@ impl HyperlightKvmSandboxTarget {
}

let ip = self.get_instruction_pointer()?;
let gpa = self.translate_gva(ip)?;
if self.hw_breakpoints.contains(&gpa) {
return Ok(Some(SingleThreadStopReason::SwBreak(())));
}

if self.hw_breakpoints.contains(&ip) {
return Ok(Some(SingleThreadStopReason::HwBreak(())));
Expand Down Expand Up @@ -469,6 +473,9 @@ impl Breakpoints for HyperlightKvmSandboxTarget {
fn support_hw_breakpoint(&mut self) -> Option<HwBreakpointOps<Self>> {
Some(self)
}
fn support_sw_breakpoint(&mut self) -> Option<SwBreakpointOps<'_, Self>> {
Some(self)
}
}

impl HwBreakpoint for HyperlightKvmSandboxTarget {
Expand All @@ -489,6 +496,24 @@ impl HwBreakpoint for HyperlightKvmSandboxTarget {
}
}

impl SwBreakpoint for HyperlightKvmSandboxTarget {
fn add_sw_breakpoint(
&mut self,
addr: <Self::Arch as Arch>::Usize,
_kind: <Self::Arch as Arch>::BreakpointKind,
) -> TargetResult<bool, Self> {
self.add_breakpoint(addr).map_err(TargetError::Fatal)
}

fn remove_sw_breakpoint(
&mut self,
addr: <Self::Arch as Arch>::Usize,
_kind: <Self::Arch as Arch>::BreakpointKind,
) -> TargetResult<bool, Self> {
self.remove_breakpoint(addr).map_err(TargetError::Fatal)
}
}

impl SingleThreadResume for HyperlightKvmSandboxTarget {
fn resume(&mut self, _signal: Option<Signal>) -> Result<(), Self::Error> {
log::debug!("Resume");
Expand Down

0 comments on commit 8f4a63f

Please sign in to comment.