Skip to content

Commit

Permalink
Support lldb (#136)
Browse files Browse the repository at this point in the history
* Update Cargo test Error

* gdbstub update to 0.7

* Support LLDB command: continue
  • Loading branch information
joii2020 authored Aug 22, 2024
1 parent 6de697c commit 0a623ce
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 19 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions ckb-debugger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ ckb-vm-debug-utils = { path = "../ckb-vm-debug-utils", version = "0.117.0" }
ckb-vm-pprof = { path = "../ckb-vm-pprof", version = "0.117.0" }
env_logger = "0.4.3"
ckb-gdb-remote-protocol = { path = "../ckb-gdb-remote-protocol", version = "0.117.0" }
gdbstub = "0.6.6"
gdbstub_arch = "0.2.4"
gdbstub = "0.7"
gdbstub_arch = "0.3"
hex = "0.4"
lazy_static = "1.4.0"
libc = "0.2.132"
Expand Down
5 changes: 1 addition & 4 deletions ckb-debugger/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
use ckb_vm_debug_utils::{GdbStubHandler, GdbStubHandlerEventLoop};
use gdbstub::{
conn::ConnectionExt,
stub::{DisconnectReason, GdbStub, GdbStubError},
stub::{DisconnectReason, GdbStub},
};
use gdbstub_arch::riscv::Riscv64;
let mut h: GdbStubHandler<_, Riscv64> = GdbStubHandler::new(machine);
Expand All @@ -466,9 +466,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}
DisconnectReason::Kill => Err(Error::External("GDB sent a kill command!".to_string())),
},
Err(GdbStubError::TargetError(e)) => {
Err(Error::External(format!("target encountered a fatal error: {}", e)))
}
Err(e) => Err(Error::External(format!("gdbstub encountered a fatal error: {}", e))),
};
match result {
Expand Down
2 changes: 1 addition & 1 deletion ckb-gdb-remote-protocol/examples/noop-server.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use gdb_remote_protocol::{process_packets_from, Error, Handler, ProcessType, StopReason};
use ckb_gdb_remote_protocol::{process_packets_from, Error, Handler, ProcessType, StopReason};
use std::net::TcpListener;

struct NoopHandler;
Expand Down
2 changes: 1 addition & 1 deletion ckb-gdb-remote-protocol/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
extern crate log;

use assert_cli::Assert;
use gdb_remote_protocol::{process_packets_from, Error, Handler, ProcessType, StopReason};
use ckb_gdb_remote_protocol::{process_packets_from, Error, Handler, ProcessType, StopReason};
use std::net::TcpListener;
use std::thread;

Expand Down
5 changes: 3 additions & 2 deletions ckb-vm-debug-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ ckb-gdb-remote-protocol = { path = "../ckb-gdb-remote-protocol", version = "0.11
libc = { version = "0.2.47", optional = true }
log = "0.4.0"
nix = { version = "0.26.2", optional = true }
gdbstub = "0.6.6"
gdbstub_arch = "0.2.4"
gdbstub = "0.7"
gdbstub_arch = "0.3"
env_logger = "0.4.3"
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use ckb_vm::{
use ckb_vm_debug_utils::GdbHandler;
#[cfg(feature = "stdio")]
use ckb_vm_debug_utils::Stdio;
use gdb_remote_protocol::process_packets_from;
use ckb_gdb_remote_protocol::process_packets_from;
use std::env;
use std::fs::File;
use std::io::Read;
Expand Down
23 changes: 15 additions & 8 deletions ckb-vm-debug-utils/src/gdbstub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use ckb_vm::{
Bytes, Error, Memory, Register,
};
use gdbstub::{
arch::{Arch, SingleStepGdbBehavior},
arch::Arch,
common::Signal,
conn::{Connection, ConnectionExt},
stub::{
Expand Down Expand Up @@ -179,7 +179,18 @@ impl<R: Register + Debug + Eq + StdHash, M: SupportMachine + CoreMachine<REG = R
let mut executed_cycles = 0;
loop {
if let Some(event) = self.step() {
break event;
let mut continue_step = true;

match event {
VmEvent::DoneStep | VmEvent::Exited(_) | VmEvent::Break | VmEvent::Error(_) => {
continue_step = false;
}
_ => {}
};

if !continue_step {
break event;
}
}

executed_cycles += 1;
Expand Down Expand Up @@ -229,10 +240,6 @@ impl<
fn support_catch_syscalls(&mut self) -> Option<CatchSyscallsOps<'_, Self>> {
Some(self)
}

fn guard_rail_single_step_gdb_behavior(&self) -> SingleStepGdbBehavior {
SingleStepGdbBehavior::Optional
}
}

impl<
Expand All @@ -258,7 +265,7 @@ impl<
Ok(())
}

fn read_addrs(&mut self, start_addr: <Self::Arch as Arch>::Usize, data: &mut [u8]) -> TargetResult<(), Self> {
fn read_addrs(&mut self, start_addr: <Self::Arch as Arch>::Usize, data: &mut [u8]) -> TargetResult<usize, Self> {
for i in 0..data.len() {
data[i] = self
.machine
Expand All @@ -267,7 +274,7 @@ impl<
.map_err(TargetError::Fatal)?
.to_u8();
}
Ok(())
Ok(data.len())
}

fn write_addrs(&mut self, start_addr: <Self::Arch as Arch>::Usize, data: &[u8]) -> TargetResult<(), Self> {
Expand Down

0 comments on commit 0a623ce

Please sign in to comment.