Skip to content

Commit

Permalink
use maybe_async on examples
Browse files Browse the repository at this point in the history
  • Loading branch information
realwakka committed Jan 6, 2025
1 parent a9814a3 commit b02c066
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 11 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ gdbstub_arch = { path = "./gdbstub_arch/" }
armv4t_emu = "0.1"
pretty_env_logger = "0.4"
goblin = "0.4"
tokio = { version = "1.42.0", features = ["full"] }

[features]
default = ["std", "trace-pkt", "sync"]
Expand Down
11 changes: 7 additions & 4 deletions examples/armv4t/gdb/breakpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::emu::Emu;
use gdbstub::target;
use gdbstub::target::ext::breakpoints::WatchKind;
use gdbstub::target::TargetResult;
use maybe_async::maybe_async;

impl target::ext::breakpoints::Breakpoints for Emu {
#[inline(always)]
Expand All @@ -19,8 +20,9 @@ impl target::ext::breakpoints::Breakpoints for Emu {
}
}

#[maybe_async]
impl target::ext::breakpoints::SwBreakpoint for Emu {
fn add_sw_breakpoint(
async fn add_sw_breakpoint(
&mut self,
addr: u32,
_kind: gdbstub_arch::arm::ArmBreakpointKind,
Expand All @@ -29,7 +31,7 @@ impl target::ext::breakpoints::SwBreakpoint for Emu {
Ok(true)
}

fn remove_sw_breakpoint(
async fn remove_sw_breakpoint(
&mut self,
addr: u32,
_kind: gdbstub_arch::arm::ArmBreakpointKind,
Expand All @@ -43,8 +45,9 @@ impl target::ext::breakpoints::SwBreakpoint for Emu {
}
}

#[maybe_async]
impl target::ext::breakpoints::HwWatchpoint for Emu {
fn add_hw_watchpoint(
async fn add_hw_watchpoint(
&mut self,
addr: u32,
len: u32,
Expand All @@ -61,7 +64,7 @@ impl target::ext::breakpoints::HwWatchpoint for Emu {
Ok(true)
}

fn remove_hw_watchpoint(
async fn remove_hw_watchpoint(
&mut self,
addr: u32,
len: u32,
Expand Down
4 changes: 3 additions & 1 deletion examples/armv4t/gdb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use gdbstub::target::Target;
use gdbstub::target::TargetError;
use gdbstub::target::TargetResult;
use gdbstub_arch::arm::reg::id::ArmCoreRegId;
use maybe_async::maybe_async;

// Additional GDB extensions

Expand Down Expand Up @@ -231,8 +232,9 @@ impl SingleThreadBase for Emu {
}
}

#[maybe_async]
impl SingleThreadResume for Emu {
fn resume(&mut self, signal: Option<Signal>) -> Result<(), Self::Error> {
async fn resume(&mut self, signal: Option<Signal>) -> Result<(), Self::Error> {
// Upon returning from the `resume` method, the target being debugged should be
// configured to run according to whatever resume actions the GDB client has
// specified (as specified by `set_resume_action`, `resume_range_step`,
Expand Down
9 changes: 8 additions & 1 deletion examples/armv4t/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,14 @@ fn main() -> DynResult<()> {

let gdb = GdbStub::new(connection);

match gdb.run_blocking::<EmuGdbEventLoop>(&mut emu) {
#[cfg(feature = "sync")]
let run = gdb.run_blocking::<EmuGdbEventLoop>(&mut emu);
#[cfg(not(feature = "sync"))]
let run = tokio::runtime::Runtime::new()
.unwrap()
.block_on(gdb.run_blocking::<EmuGdbEventLoop>(&mut emu));

match run {
Ok(disconnect_reason) => match disconnect_reason {
DisconnectReason::Disconnect => {
println!("GDB client has disconnected. Running to completion...");
Expand Down
11 changes: 7 additions & 4 deletions examples/armv4t_multicore/gdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use gdbstub::target::ext::breakpoints::WatchKind;
use gdbstub::target::Target;
use gdbstub::target::TargetError;
use gdbstub::target::TargetResult;
use maybe_async::maybe_async;

pub fn cpuid_to_tid(id: CpuId) -> Tid {
match id {
Expand Down Expand Up @@ -217,8 +218,9 @@ impl target::ext::breakpoints::Breakpoints for Emu {
}
}

#[maybe_async]
impl target::ext::breakpoints::SwBreakpoint for Emu {
fn add_sw_breakpoint(
async fn add_sw_breakpoint(
&mut self,
addr: u32,
_kind: gdbstub_arch::arm::ArmBreakpointKind,
Expand All @@ -227,7 +229,7 @@ impl target::ext::breakpoints::SwBreakpoint for Emu {
Ok(true)
}

fn remove_sw_breakpoint(
async fn remove_sw_breakpoint(
&mut self,
addr: u32,
_kind: gdbstub_arch::arm::ArmBreakpointKind,
Expand All @@ -241,8 +243,9 @@ impl target::ext::breakpoints::SwBreakpoint for Emu {
}
}

#[maybe_async]
impl target::ext::breakpoints::HwWatchpoint for Emu {
fn add_hw_watchpoint(
async fn add_hw_watchpoint(
&mut self,
addr: u32,
_len: u32, // TODO: properly handle `len` parameter
Expand All @@ -260,7 +263,7 @@ impl target::ext::breakpoints::HwWatchpoint for Emu {
Ok(true)
}

fn remove_hw_watchpoint(
async fn remove_hw_watchpoint(
&mut self,
addr: u32,
_len: u32, // TODO: properly handle `len` parameter
Expand Down
8 changes: 7 additions & 1 deletion examples/armv4t_multicore/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,13 @@ fn main() -> DynResult<()> {

let gdb = GdbStub::new(connection);

match gdb.run_blocking::<EmuGdbEventLoop>(&mut emu) {
#[cfg(feature = "sync")]
let run = gdb.run_blocking::<EmuGdbEventLoop>(&mut emu);
#[cfg(not(feature = "sync"))]
let run = tokio::runtime::Runtime::new()
.unwrap()
.block_on(gdb.run_blocking::<EmuGdbEventLoop>(&mut emu));
match run {
Ok(disconnect_reason) => match disconnect_reason {
DisconnectReason::Disconnect => {
println!("GDB client has disconnected. Running to completion...");
Expand Down

0 comments on commit b02c066

Please sign in to comment.