mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
kernel: debug: store only a single object in GDB_STATE
This keeps a single object in the global singleton. Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
29c36c3b0f
commit
3becfc03c5
1 changed files with 23 additions and 10 deletions
|
|
@ -137,9 +137,12 @@ mod gdb_server {
|
||||||
tid: Option<xous_kernel::TID>,
|
tid: Option<xous_kernel::TID>,
|
||||||
thread_mask: usize,
|
thread_mask: usize,
|
||||||
}
|
}
|
||||||
|
pub struct XousDebugState<'a> {
|
||||||
|
pub target: XousTarget,
|
||||||
|
pub server: GdbStubStateMachine<'a, XousTarget, super::Uart>,
|
||||||
|
}
|
||||||
|
|
||||||
pub static mut GDB_SERVER: Option<GdbStubStateMachine<XousTarget, super::Uart>> = None;
|
pub static mut GDB_STATE: Option<XousDebugState> = None;
|
||||||
pub static mut GDB_TARGET: Option<XousTarget> = None;
|
|
||||||
pub static mut GDB_BUFFER: [u8; 4096] = [0u8; 4096];
|
pub static mut GDB_BUFFER: [u8; 4096] = [0u8; 4096];
|
||||||
|
|
||||||
impl XousTarget {
|
impl XousTarget {
|
||||||
|
|
@ -302,13 +305,16 @@ pub fn irq(_irq_number: usize, _arg: *mut usize) {
|
||||||
|
|
||||||
#[cfg(feature = "gdbserver")]
|
#[cfg(feature = "gdbserver")]
|
||||||
unsafe {
|
unsafe {
|
||||||
use crate::debug::gdb_server::{GDB_SERVER, GDB_TARGET};
|
use crate::debug::gdb_server::{GDB_STATE, XousDebugState};
|
||||||
use gdbstub::state_machine::GdbStubStateMachine;
|
use gdbstub::state_machine::GdbStubStateMachine;
|
||||||
use gdbstub::{DisconnectReason, GdbStubError};
|
use gdbstub::{DisconnectReason, GdbStubError};
|
||||||
if let Some(gdb) = GDB_SERVER.take() {
|
if let Some(XousDebugState {
|
||||||
let target = GDB_TARGET.as_mut().unwrap();
|
mut target,
|
||||||
|
server: gdb,
|
||||||
|
}) = GDB_STATE.take()
|
||||||
|
{
|
||||||
let new_gdb = match gdb {
|
let new_gdb = match gdb {
|
||||||
GdbStubStateMachine::Pump(gdb_state) => match gdb_state.pump(target, b) {
|
GdbStubStateMachine::Pump(gdb_state) => match gdb_state.pump(&mut target, b) {
|
||||||
// Remote disconnected -- leave the `GDB_SERVER` as `None`.
|
// Remote disconnected -- leave the `GDB_SERVER` as `None`.
|
||||||
Ok((_, Some(disconnect_reason))) => {
|
Ok((_, Some(disconnect_reason))) => {
|
||||||
match disconnect_reason {
|
match disconnect_reason {
|
||||||
|
|
@ -334,7 +340,10 @@ pub fn irq(_irq_number: usize, _arg: *mut usize) {
|
||||||
panic!("Deferred stop shouldn't happen")
|
panic!("Deferred stop shouldn't happen")
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
GDB_SERVER = Some(new_gdb);
|
GDB_STATE = Some(XousDebugState {
|
||||||
|
target,
|
||||||
|
server: new_gdb,
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -411,15 +420,19 @@ pub fn irq(_irq_number: usize, _arg: *mut usize) {
|
||||||
}
|
}
|
||||||
#[cfg(feature = "gdbserver")]
|
#[cfg(feature = "gdbserver")]
|
||||||
b'g' => {
|
b'g' => {
|
||||||
use gdb_server::{XousTarget, GDB_BUFFER, GDB_SERVER, GDB_TARGET};
|
use gdb_server::{XousDebugState, XousTarget, GDB_BUFFER, GDB_STATE};
|
||||||
println!("Starting GDB server -- attach your debugger now");
|
println!("Starting GDB server -- attach your debugger now");
|
||||||
unsafe { GDB_TARGET = Some(XousTarget::new()) };
|
|
||||||
match gdbstub::GdbStubBuilder::new(Uart {})
|
match gdbstub::GdbStubBuilder::new(Uart {})
|
||||||
.with_packet_buffer(unsafe { &mut GDB_BUFFER })
|
.with_packet_buffer(unsafe { &mut GDB_BUFFER })
|
||||||
.build()
|
.build()
|
||||||
{
|
{
|
||||||
Ok(gdb) => match gdb.run_state_machine() {
|
Ok(gdb) => match gdb.run_state_machine() {
|
||||||
Ok(state) => unsafe { GDB_SERVER = Some(state) },
|
Ok(state) => unsafe {
|
||||||
|
GDB_STATE = Some(XousDebugState {
|
||||||
|
target: XousTarget::new(),
|
||||||
|
server: state,
|
||||||
|
});
|
||||||
|
},
|
||||||
Err(e) => println!("Unable to start GDB state machine: {}", e),
|
Err(e) => println!("Unable to start GDB state machine: {}", e),
|
||||||
},
|
},
|
||||||
Err(e) => println!("Unable to start GDB server: {}", e),
|
Err(e) => println!("Unable to start GDB server: {}", e),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue