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.
In the examples below, `->' and `<-' are used to indicate transmitted and received data respectfully.
All GDB commands and responses (other than acknowledgments) are sent as a PACKET. A PACKET is introduced with the character `$', the actual PACKET-DATA, and the terminating character `#' followed by a two-digit CHECKSUM:
The two-digit CHECKSUM is computed as the modulo 256 sum of all characters between the leading `$' and the trailing `#' (an eight bit unsigned checksum).
Implementors should note that prior to GDB 5.0 the protocol specification also included an optional two-digit SEQUENCE-ID:
That SEQUENCE-ID was appended to the acknowledgment. GDB has never output SEQUENCE-IDs. Stubs that handle packets added since GDB 5.0 must not accept SEQUENCE-ID.
When either the host or the target machine receives a packet, the first response expected is an acknowledgment: either `+' (to indicate the package was received correctly) or `-' (to request retransmission):
-> `$'PACKET-DATA`#'CHECKSUM <- `+'
The host (GDB) sends COMMANDs, and the target (the debugging stub incorporated in your program) sends a RESPONSE. In the case of step and continue COMMANDs, the response is only sent when the operation has completed (the target has again stopped).
PACKET-DATA consists of a sequence of characters with the exception of `#' and `$' (see `X' packet for additional exceptions).
Fields within the packet should be separated using `,' `;' or `:'. Except where otherwise noted all numbers are represented in HEX with leading zeros suppressed.
Implementors should note that prior to GDB 5.0, the character `:' could not appear as the third character in a packet (as it would potentially conflict with the SEQUENCE-ID).
Response DATA can be run-length encoded to save space. A `*' means that the next character is an ASCII encoding giving a repeat count which stands for that many repetitions of the character preceding the `*'. The encoding is `n+29', yielding a printable character where `n >=3' (which is where rle starts to win). The printable characters `$', `#', `+' and `-' or with a numeric value greater than 126 should not be used.
means the same as "0000".
The error response returned for some packets includes a two character error number. That number is not well defined.
For any COMMAND not supported by the stub, an empty response (`$#00') should be returned. That way it is possible to extend the protocol. A newer GDB can tell if a packet is supported based on that response.
A stub is required to support the `g', `G', `m', `M', `c', and `s' COMMANDs. All other COMMANDs are optional.Created Mon Nov 8 17:42:41 2004 on tillpc with info_to_html version 0.9.6.