Open tromey opened 6 years ago
If we're going to wind up having async behavior then we'll either need to split networking and the handler into separate threads and use std::sync::mpsc::{Sender, Receiver}
to multiplex messages from both threads to a single place, or go all-in and use tokio
and Future
.
The server can also send output to gdb while gdb is waiting for a stop reply -- the O
packet. In the sync model this would be a callback from a handler back into the I/O loop.
I think it would be best if this code were just always async and then sometimes pretended to be sync for the protocol's sake.
If the server code were always async, then I think QNonStop
would be handled entirely by this library and not require a Handler
method.
See https://github.com/tromey/rust-gdb-remote-protocol/tree/multi-threaded for a draft of how this could work. So far that just implements the threading bits: the reading is done in one thread, and the handlers and response writing are done in whichever thread called process_packets_from
.
After this the idea would be that target-continuing functions (whatever Handler
method we call to implement vCont
) would get an object which implements Write
and which also has some sort of stopped
method.
The Write
implementation in all-stop would send O
packets, but in non-stop would just drop the output (since this isn't defined for non-stop yet)
The stopped
method would take a StopReason
and would simply post it to the channel, so that the command processor would send it on to the client. Maybe we could make this a bit safer by making each such object single-use, and requiring them to appear in order. That way the server couldn't re-send a stop reason or send stop reasons out of order somehow.
Maybe we could make this a bit safer by making each such object single-use
Actually they can't be single use in non-stop mode. And, in all-stop mode, it's expected that any stop will stop all threads -- so this information has to be exposed.
See https://github.com/tromey/rust-gdb-remote-protocol/tree/client-state for some more work in this area.
Also the %
notification / vStopped
processing will require a bit more state, namely a vector of pending stops and also a flag indicating whether the initial notification has been sent.
In non-stop mode, the client just replies
OK
to commands likevCont
, and then generates an async notification packet when there is some noteworthy inferior event.This means that the client would have to have some way to tell
process_packets_from
that an event like this occurred.