The stub files provided with GDB implement the target side of the communication protocol, and the GDB side is implemented in the GDB source file `remote.c'. Normally, you can simply allow these subroutines to communicate, and ignore the details. (If you're implementing your own stub file, you can still ignore the details: start with one of the existing stub files. `sparc-stub.c' is the best organized, and therefore the easiest to read.)
However, there may be occasions when you need to know something about the protocol--for example, if there is only one serial port to your target machine, you might want your program to do something special if it recognizes a packet meant for GDB.
All GDB commands and responses (other than acknowledgements, which are single characters) are sent as a packet which includes a checksum. A packet is introduced with the character `$', and ends with the character `#' followed by a two-digit checksum:
checksum is computed as the modulo 256 sum of the packet info characters.
When either the host or the target machine receives a packet, the first response expected is an acknowledgement: a single character, either `+' (to indicate the package was received correctly) or `-' (to request retransmission).
The host (GDB) sends commands, and the target (the debugging stub incorporated in your program) sends data in response. The target also sends data when your program stops.
Command packets are distinguished by their first character, which identifies the kind of command.
These are some of the commands currently supported (for a complete list of commands, look in `gdb/remote.c.'):
If you have trouble with the serial connection, you can use the command
set remotedebug. This makes GDB report on all packets sent
back and forth across the serial line to the remote machine. The
packet-debugging information is printed on the GDB standard output
set remotedebug off turns it off, and
remotedebug shows you its current state.
Go to the first, previous, next, last section, table of contents.