The serial connection is established in response to a target remote or target extended-remote command from the GDB client. The way the server handles this depends on the nature of the serial connection:
Connection via a serial device. The target should be listening for connections on the device. This may either be via routine polling or via an event driven interface. Once the connection is established, packets are read from and written to the device.
Connection via TCP/IP or UDP/IP. The target
should be listening on a socket connected to the specified
port. This may either be via routine polling or via an event
driven interface. Accepting a new connection (the POSIX
accept ()
function) will yield a file
descriptor, which can be used for reading and writing packets.
Connection via a pipe. The target will be created, with standard input and output as the file descriptors for packet reading and writing.
In each case there is no specific requirement that the target be either running or stopped. GDB will establish via RSP commands the state of the target once the connection is established.
GDB is almost entirely non-preemptive, which is reflected in the sequence of packet exchanges of RSP. The exception is when GDB wishes to interrupt an executing program (typically via ctrl-C). A single byte, 0x03, is sent (no packet structure). If the target is prepared to handle such interrupts it should recognize such bytes. Unless the target is routinely polling for input (which may be the case for simulators), a prompt response typically will require an event driven reader for the connection.