From a91ab2e100149cf10cbe1c222695420c0aebaf85 Mon Sep 17 00:00:00 2001 From: Sidong Yang Date: Mon, 6 Jan 2025 03:38:39 +0000 Subject: [PATCH] use maybe_async on examples --- Cargo.toml | 1 + examples/armv4t/gdb/breakpoints.rs | 11 +++++++---- examples/armv4t/gdb/mod.rs | 4 +++- examples/armv4t/main.rs | 9 ++++++++- examples/armv4t_multicore/gdb.rs | 11 +++++++---- examples/armv4t_multicore/main.rs | 8 +++++++- 6 files changed, 33 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 69b3c5d..b25ba6e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] diff --git a/examples/armv4t/gdb/breakpoints.rs b/examples/armv4t/gdb/breakpoints.rs index 9d6d90d..973940b 100644 --- a/examples/armv4t/gdb/breakpoints.rs +++ b/examples/armv4t/gdb/breakpoints.rs @@ -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)] @@ -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, @@ -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, @@ -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, @@ -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, diff --git a/examples/armv4t/gdb/mod.rs b/examples/armv4t/gdb/mod.rs index d4190dc..c1d2dfb 100644 --- a/examples/armv4t/gdb/mod.rs +++ b/examples/armv4t/gdb/mod.rs @@ -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 @@ -231,8 +232,9 @@ impl SingleThreadBase for Emu { } } +#[maybe_async] impl SingleThreadResume for Emu { - fn resume(&mut self, signal: Option) -> Result<(), Self::Error> { + async fn resume(&mut self, signal: Option) -> 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`, diff --git a/examples/armv4t/main.rs b/examples/armv4t/main.rs index ab15f9b..44ad334 100644 --- a/examples/armv4t/main.rs +++ b/examples/armv4t/main.rs @@ -167,7 +167,14 @@ fn main() -> DynResult<()> { let gdb = GdbStub::new(connection); - match gdb.run_blocking::(&mut emu) { + #[cfg(feature = "sync")] + let run = gdb.run_blocking::(&mut emu); + #[cfg(not(feature = "sync"))] + let run = tokio::runtime::Runtime::new() + .unwrap() + .block_on(gdb.run_blocking::(&mut emu)); + + match run { Ok(disconnect_reason) => match disconnect_reason { DisconnectReason::Disconnect => { println!("GDB client has disconnected. Running to completion..."); diff --git a/examples/armv4t_multicore/gdb.rs b/examples/armv4t_multicore/gdb.rs index 11ed1e3..c4b346f 100644 --- a/examples/armv4t_multicore/gdb.rs +++ b/examples/armv4t_multicore/gdb.rs @@ -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 { @@ -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, @@ -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, @@ -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 @@ -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 diff --git a/examples/armv4t_multicore/main.rs b/examples/armv4t_multicore/main.rs index c24f795..7d80c09 100644 --- a/examples/armv4t_multicore/main.rs +++ b/examples/armv4t_multicore/main.rs @@ -169,7 +169,13 @@ fn main() -> DynResult<()> { let gdb = GdbStub::new(connection); - match gdb.run_blocking::(&mut emu) { + #[cfg(feature = "sync")] + let run = gdb.run_blocking::(&mut emu); + #[cfg(not(feature = "sync"))] + let run = tokio::runtime::Runtime::new() + .unwrap() + .block_on(gdb.run_blocking::(&mut emu)); + match run { Ok(disconnect_reason) => match disconnect_reason { DisconnectReason::Disconnect => { println!("GDB client has disconnected. Running to completion...");