No debugging unless the game is running
This commit is contained in:
+38
-9
@@ -9,7 +9,7 @@ use std::{
|
||||
use tokio::{
|
||||
io::{AsyncWriteExt as _, BufReader},
|
||||
net::{TcpListener, TcpStream},
|
||||
select,
|
||||
pin, select,
|
||||
sync::{mpsc, oneshot},
|
||||
};
|
||||
use tracing::{debug, enabled, error, info, Level};
|
||||
@@ -57,8 +57,9 @@ impl GdbServer {
|
||||
.unwrap()
|
||||
.block_on(async move {
|
||||
select! {
|
||||
_ = run_server(sim_id, client, port, &status) => {}
|
||||
_ = run_server(sim_id, client.clone(), port, &status) => {}
|
||||
_ = rx => {
|
||||
client.send_command(EmulatorCommand::StopDebugging(sim_id));
|
||||
*status.lock().unwrap() = GdbServerStatus::Stopped;
|
||||
}
|
||||
}
|
||||
@@ -73,19 +74,46 @@ impl GdbServer {
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for GdbServer {
|
||||
fn drop(&mut self) {
|
||||
self.stop();
|
||||
}
|
||||
}
|
||||
|
||||
async fn run_server(
|
||||
sim_id: SimId,
|
||||
client: EmulatorClient,
|
||||
port: u16,
|
||||
status: &Mutex<GdbServerStatus>,
|
||||
) {
|
||||
let (debug_sink, mut debug_source) = mpsc::unbounded_channel();
|
||||
client.send_command(EmulatorCommand::StartDebugging(sim_id, debug_sink));
|
||||
|
||||
info!("Connecting to debugger on port {port}...");
|
||||
let Some(stream) = try_connect(port, status).await else {
|
||||
return;
|
||||
let connect_future = try_connect(port, status);
|
||||
pin!(connect_future);
|
||||
|
||||
let stream = loop {
|
||||
select! {
|
||||
stream = &mut connect_future => {
|
||||
if let Some(stream) = stream {
|
||||
break stream;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
event = debug_source.recv() => {
|
||||
if event.is_none() {
|
||||
// The sim has stopped (or was never started)
|
||||
*status.lock().unwrap() = GdbServerStatus::Stopped;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
info!("Connected!");
|
||||
let mut connection = GdbConnection::new(sim_id, client);
|
||||
match connection.run(stream).await {
|
||||
match connection.run(stream, debug_source).await {
|
||||
Ok(()) => {
|
||||
info!("Finished debugging.");
|
||||
*status.lock().unwrap() = GdbServerStatus::Stopped;
|
||||
@@ -154,12 +182,13 @@ impl GdbConnection {
|
||||
memory_buf: None,
|
||||
}
|
||||
}
|
||||
async fn run(&mut self, stream: TcpStream) -> Result<()> {
|
||||
let (debug_sink, mut debug_source) = mpsc::unbounded_channel();
|
||||
async fn run(
|
||||
&mut self,
|
||||
stream: TcpStream,
|
||||
mut debug_source: mpsc::UnboundedReceiver<DebugEvent>,
|
||||
) -> Result<()> {
|
||||
let (rx, mut tx) = stream.into_split();
|
||||
let mut request_source = RequestSource::new(BufReader::new(rx));
|
||||
self.client
|
||||
.send_command(EmulatorCommand::StartDebugging(self.sim_id, debug_sink));
|
||||
loop {
|
||||
let response = select! {
|
||||
maybe_event = debug_source.recv() => {
|
||||
|
||||
Reference in New Issue
Block a user