From c25bf3e09d025d02f0dd216da6b97f0fc1cb8630 Mon Sep 17 00:00:00 2001 From: SuchAFuriousDeath <48620541+SuchAFuriousDeath@users.noreply.github.com> Date: Wed, 20 Nov 2024 18:10:20 +0100 Subject: [PATCH] Updates some dependencies, minor refactors (#1120) --- Cargo.lock | 20 +++++++++---------- gui/Cargo.toml | 6 +++--- gui/src/vmm/ffi.rs | 45 ++----------------------------------------- gui/src/vmm/mod.rs | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 56 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ab3b01955..22d454737 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -740,9 +740,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.20" +version = "4.5.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b97f376d85a664d5837dbae44bf546e6477a679ff6610010f17276f686d867e8" +checksum = "fb3b4b9e5a7c7514dfa52869339ee98b3156b0bfb4e8a77c4ff4babb64b1604f" dependencies = [ "clap_builder", "clap_derive", @@ -750,9 +750,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.20" +version = "4.5.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19bc80abd44e4bed93ca373a0704ccbd1b710dc5749406201bb018272808dc54" +checksum = "b17a95aa67cc7b5ebd32aa5370189aa0d79069ef1c64ce893bd30fb24bff20ec" dependencies = [ "anstream", "anstyle", @@ -2482,9 +2482,9 @@ checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8" [[package]] name = "libc" -version = "0.2.158" +version = "0.2.164" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" +checksum = "433bfe06b8c75da9b2e3fbea6e5329ff87748f0b144ef75306e674c3f6f7c13f" [[package]] name = "libloading" @@ -4115,9 +4115,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.86" +version = "2.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e89275301d38033efb81a6e60e3497e734dfcc62571f2854bf4b16690398824c" +checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" dependencies = [ "proc-macro2", "quote", @@ -4515,9 +4515,9 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "uuid" -version = "1.10.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81dfa00651efa65069b0b6b651f4aaa31ba9e3c3ce0137aaad053604ee7e0314" +checksum = "f8c5f0a0af699448548ad1a2fbf920fb4bee257eae39953ba95cb84891a0446a" dependencies = [ "getrandom", "serde", diff --git a/gui/Cargo.toml b/gui/Cargo.toml index 6216d61d7..e71c3a6b2 100644 --- a/gui/Cargo.toml +++ b/gui/Cargo.toml @@ -19,11 +19,11 @@ qt = [] [dependencies] bitfield-struct = "0.9.2" ciborium = "0.2.2" -clap = { version = "4.5.20", features = ["derive"], optional = true } +clap = { version = "4.5.21", features = ["derive"], optional = true } gdbstub = "0.7.3" gdbstub_arch = "0.3.1" humansize = "2.1.3" -libc = "0.2.155" +libc = "0.2.164" obconf = { path = "../src/obconf", features = ["serde", "virt"] } obfw = { git = "https://github.com/obhq/firmware-dumper.git", features = [ "read", @@ -35,7 +35,7 @@ pkg = { path = "../src/pkg" } rfd = { version = "0.14.0", optional = true } serde = { version = "1.0.209", features = ["derive"] } thiserror = "1.0" -uuid = { version = "1.10.0", features = ["serde", "v4"] } +uuid = { version = "1.11.0", features = ["serde", "v4"] } [dependencies.slint] version = "1.8.0" diff --git a/gui/src/vmm/ffi.rs b/gui/src/vmm/ffi.rs index 9a972d9a5..2ac94573c 100644 --- a/gui/src/vmm/ffi.rs +++ b/gui/src/vmm/ffi.rs @@ -3,9 +3,7 @@ use crate::debug::DebugClient; use crate::error::RustError; use crate::profile::Profile; use crate::screen::Screen; -use gdbstub::common::Signal; use gdbstub::stub::state_machine::GdbStubStateMachine; -use gdbstub::stub::MultiThreadStopReason; use std::ffi::{c_char, c_void, CStr}; use std::ptr::null_mut; use std::sync::atomic::Ordering; @@ -78,52 +76,13 @@ pub unsafe extern "C" fn vmm_draw(vmm: *mut Vmm) -> *mut RustError { pub unsafe extern "C" fn vmm_dispatch_debug(vmm: *mut Vmm, stop: *mut KernelStop) -> DebugResult { // Consume stop reason now to prevent memory leak. let vmm = &mut *vmm; - let mut stop = if stop.is_null() { + let stop = if stop.is_null() { None } else { Some(Box::from_raw(stop).0) }; - loop { - // Check current state. - let r = match vmm.gdb.take().unwrap() { - GdbStubStateMachine::Idle(s) => match super::debug::dispatch_idle(&mut vmm.cpu, s) { - Ok(Ok(v)) => Ok(v), - Ok(Err(v)) => { - // No pending data from the debugger. - vmm.gdb = Some(v.into()); - return DebugResult::Ok; - } - Err(e) => Err(e), - }, - GdbStubStateMachine::Running(s) => { - match super::debug::dispatch_running(&mut vmm.cpu, s, stop.take()) { - Ok(Ok(v)) => Ok(v), - Ok(Err(v)) => { - // No pending data from the debugger. - vmm.gdb = Some(v.into()); - return DebugResult::Ok; - } - Err(e) => Err(e), - } - } - GdbStubStateMachine::CtrlCInterrupt(s) => { - vmm.cpu.lock(); - - s.interrupt_handled( - &mut vmm.cpu, - Some(MultiThreadStopReason::Signal(Signal::SIGINT)), - ) - .map_err(|e| RustError::with_source("couldn't handle CTRL+C from a debugger", e)) - } - GdbStubStateMachine::Disconnected(_) => return DebugResult::Disconnected, - }; - - match r { - Ok(v) => vmm.gdb = Some(v), - Err(e) => return DebugResult::Error { reason: e.into_c() }, - } - } + vmm.dispatch_debug(stop) } #[no_mangle] diff --git a/gui/src/vmm/mod.rs b/gui/src/vmm/mod.rs index 263e9fdab..bb11911a3 100644 --- a/gui/src/vmm/mod.rs +++ b/gui/src/vmm/mod.rs @@ -11,6 +11,7 @@ use crate::hv::{Hypervisor, Ram}; use crate::profile::Profile; use crate::screen::Screen; use cpu::GdbError; +use gdbstub::common::Signal; use gdbstub::stub::state_machine::GdbStubStateMachine; use gdbstub::stub::{GdbStubError, MultiThreadStopReason}; use kernel::{KernelError, ProgramHeaderError}; @@ -345,6 +346,53 @@ impl Vmm { Ok(vmm) } + + fn dispatch_debug(&mut self, mut stop: Option>) -> DebugResult { + loop { + // Check current state. + let r = match self.gdb.take().unwrap() { + GdbStubStateMachine::Idle(s) => { + match debug::dispatch_idle(&mut self.cpu, s) { + Ok(Ok(v)) => Ok(v), + Ok(Err(v)) => { + // No pending data from the debugger. + self.gdb = Some(v.into()); + return DebugResult::Ok; + } + Err(e) => Err(e), + } + } + GdbStubStateMachine::Running(s) => { + match debug::dispatch_running(&mut self.cpu, s, stop.take()) { + Ok(Ok(v)) => Ok(v), + Ok(Err(v)) => { + // No pending data from the debugger. + self.gdb = Some(v.into()); + return DebugResult::Ok; + } + Err(e) => Err(e), + } + } + GdbStubStateMachine::CtrlCInterrupt(s) => { + self.cpu.lock(); + + s.interrupt_handled( + &mut self.cpu, + Some(MultiThreadStopReason::Signal(Signal::SIGINT)), + ) + .map_err(|e| { + RustError::with_source("couldn't handle CTRL+C from a debugger", e) + }) + } + GdbStubStateMachine::Disconnected(_) => return DebugResult::Disconnected, + }; + + match r { + Ok(v) => self.gdb = Some(v), + Err(e) => return DebugResult::Error { reason: e.into_c() }, + } + } + } } impl Drop for Vmm {