summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortaitep <taitep@taitep.se>2026-01-02 12:55:42 +0100
committertaitep <taitep@taitep.se>2026-01-02 12:55:42 +0100
commitceb7f2f172d5e9a5c50ddd845f4e4af87924ad5a (patch)
tree1a8a747f5ecf2b07d9e91da1cd8582709839e490
parent21fb6cbc8baab44c57c004e9f78904630044499d (diff)
Apply some clippy-suggested fixes
-rw-r--r--src/core.rs4
-rw-r--r--src/exceptions.rs12
-rw-r--r--src/gdb.rs83
3 files changed, 49 insertions, 50 deletions
diff --git a/src/core.rs b/src/core.rs
index 4a05aa8..118386e 100644
--- a/src/core.rs
+++ b/src/core.rs
@@ -112,7 +112,7 @@ impl Core {
loop {
match dbg_stream.recv()? {
DebugCommand::GetRegs(sender) => sender.send(gdb::RegsResponse {
- x_regs: self.x_regs.clone(),
+ x_regs: self.x_regs,
pc: self.pc,
})?,
DebugCommand::ReadMem {
@@ -163,7 +163,7 @@ impl Core {
return StopReason::Exception(ExceptionType::Breakpoint);
}
- if let Ok(_) = stopper.try_recv() {
+ if stopper.try_recv().is_ok() {
return StopReason::Interrupted;
}
diff --git a/src/exceptions.rs b/src/exceptions.rs
index 0b92a97..8ea4480 100644
--- a/src/exceptions.rs
+++ b/src/exceptions.rs
@@ -98,14 +98,14 @@ impl MemoryException {
}
}
-impl Into<MemoryExceptionType> for MemoryException {
- fn into(self) -> MemoryExceptionType {
- self.type_
+impl From<MemoryException> for MemoryExceptionType {
+ fn from(val: MemoryException) -> Self {
+ val.type_
}
}
-impl Into<ExceptionType> for Exception {
- fn into(self) -> ExceptionType {
- self.type_
+impl From<Exception> for ExceptionType {
+ fn from(val: Exception) -> Self {
+ val.type_
}
}
diff --git a/src/gdb.rs b/src/gdb.rs
index 7c1fcd8..0361c48 100644
--- a/src/gdb.rs
+++ b/src/gdb.rs
@@ -71,20 +71,18 @@ pub fn run_stub(cmd_sender: crossbeam::channel::Sender<CoreCmd>) {
std::thread::spawn(move || {
let listener = TcpListener::bind("127.0.0.1:1234").expect("couldnt start tcp listener");
- for stream_res in listener.incoming() {
- if let Ok(stream) = stream_res {
- let (dbg_tx, dbg_rx) = crossbeam::channel::bounded(16);
+ for stream in listener.incoming().flatten() {
+ let (dbg_tx, dbg_rx) = crossbeam::channel::bounded(16);
- stream
- .set_nonblocking(true)
- .expect("Couldnt set TCP stream to nonblocking");
+ stream
+ .set_nonblocking(true)
+ .expect("Couldnt set TCP stream to nonblocking");
- cmd_sender
- .send(CoreCmd::EnterDbgMode(DebugStream(dbg_rx)))
- .expect("couldnt ask core to enter debug mode");
+ cmd_sender
+ .send(CoreCmd::EnterDbgMode(DebugStream(dbg_rx)))
+ .expect("couldnt ask core to enter debug mode");
- handle_gdb_connection(stream, dbg_tx).expect("failure during connection");
- }
+ handle_gdb_connection(stream, dbg_tx).expect("failure during connection");
}
});
}
@@ -99,18 +97,19 @@ fn handle_gdb_connection(
loop {
match read_rsp_packet(&mut reader) {
- Ok(packet) => match handle_packet(
- &packet[..packet.len() - 1],
- &mut writer,
- &dbg_tx,
- &mut reader,
- ) {
- Err(_) => {
+ Ok(packet) => {
+ if handle_packet(
+ &packet[..packet.len() - 1],
+ &mut writer,
+ &dbg_tx,
+ &mut reader,
+ )
+ .is_err()
+ {
let _ = dbg_tx.send(DebugCommand::ExitDebugMode);
break;
}
- _ => {}
- },
+ }
Err(ref e) if e.kind() == ErrorKind::WouldBlock => {
std::thread::yield_now();
}
@@ -224,7 +223,7 @@ fn handle_packet<W: Write, R: BufRead>(
let (responder, stop_reason_rx) = oneshot::channel();
dbg_tx.send(DebugCommand::Step(responder)).unwrap();
let stop_reason = stop_reason_rx.recv().unwrap();
- send_packet(&stop_reason.to_rsp(), writer)?;
+ send_packet(stop_reason.to_rsp(), writer)?;
}
"c" => {
@@ -253,7 +252,7 @@ fn handle_packet<W: Write, R: BufRead>(
}
if let Ok(stop_reason) = stop_reason_rx.try_recv() {
- send_packet(&stop_reason.to_rsp(), writer)?;
+ send_packet(stop_reason.to_rsp(), writer)?;
return Ok(());
}
@@ -265,39 +264,39 @@ fn handle_packet<W: Write, R: BufRead>(
}
"Z" if packet.chars().nth(1) == Some('0') => {
- if let Some((addr_str, size_str)) = packet[3..].split_once(',') {
- if let (Ok(addr), Ok(size)) = (
+ if let Some((addr_str, size_str)) = packet[3..].split_once(',')
+ && let (Ok(addr), Ok(size)) = (
u64::from_str_radix(addr_str, 16),
u64::from_str_radix(size_str, 16),
- ) {
- if size != 4 {
- send_packet("", writer)?;
- return Ok(());
- }
-
- dbg_tx.send(DebugCommand::SetBreakpoint(addr)).unwrap();
- send_packet("OK", writer)?;
+ )
+ {
+ if size != 4 {
+ send_packet("", writer)?;
return Ok(());
}
+
+ dbg_tx.send(DebugCommand::SetBreakpoint(addr)).unwrap();
+ send_packet("OK", writer)?;
+ return Ok(());
}
send_packet("", writer)?;
}
"z" if packet.chars().nth(1) == Some('0') => {
- if let Some((addr_str, size_str)) = packet[3..].split_once(',') {
- if let (Ok(addr), Ok(size)) = (
+ if let Some((addr_str, size_str)) = packet[3..].split_once(',')
+ && let (Ok(addr), Ok(size)) = (
u64::from_str_radix(addr_str, 16),
u64::from_str_radix(size_str, 16),
- ) {
- if size != 4 {
- send_packet("", writer)?;
- return Ok(());
- }
-
- dbg_tx.send(DebugCommand::RemoveBreakpoint(addr)).unwrap();
- send_packet("OK", writer)?;
+ )
+ {
+ if size != 4 {
+ send_packet("", writer)?;
return Ok(());
}
+
+ dbg_tx.send(DebugCommand::RemoveBreakpoint(addr)).unwrap();
+ send_packet("OK", writer)?;
+ return Ok(());
}
send_packet("", writer)?;
}