GDB Remote Serial protocol -- RSP protocol Parsing

Source: Internet
Author: User
Document directory
  • Read register group: ("G ")
  • Write register group: ("G ")
  • Write register: ("P ")
  • Read Memory: ("M ")
  • Write memory: ("M ")
  • Obtain the final signal ("?")
  • Single-step command ("S ")
  • Continue command ("C ")
  • Last signal response ("S ")
  • Quick Response (expeditedresponse ("T "))
  • Console output ("O") -- customizable
  • Empty response (")
  • Error Response ("e")
  •  
  • Target Server Response: + $ e01 ##
Introduction

GDB Remote Serial protocol-GDB standard remote communication protocol.

 

When you are familiar with how your processor handles breakpoints and other exceptions, you can learn a little more about basic remote communication protocols, you can implement communication with the host GDB on your embedded platform. (Remote debugging)

Protocol definition

GDB remoteserial protocol (RSP) is a simple protocol for transmitting ASCII messages through at least half-duplex communication media, such as serial lines and networks.

The RSP package starts with a $ packet, followed by one or more ASCII bytes used to form the message to be sent, and ends with # As the packet. Then, there are two hexadecimal ASCII characters used as the message checksum. A complete RSP Protocol packet is as follows:

 

$ M4015bc, 2 # 5A

 

The receiver of the message immediately returns '+' indicating that the data is correctly received, or '-' indicates that the data is not correctly received. When '-' is returned, GDB returns the error code to the user and suspends the gdb process unconditionally.

The target machine sends information to the GDB Console in sequence according to the order of commands received. Unless other commands are being executed in the gdb process, information from the target machine will be output to the console at any time.

 

Commands required by RSP

The information sent by GDB can be divided into three commands: register-based, memory-based, and program control commands.

 

Register related

It mainly reads and writes registers.

 

Read register group: ("G ")

Eg: $ G #67

 

When GDB wants to obtain the register information of the current target machine, it will send the ("G") command like the target machine. The target opportunity will return the following information:

 

+ $123456789abcdef0... # Xx

(The value of register 0 is 0 x 12345678, and the value of 1 is 0xabcdef0 .... And so on)

 

The target machine returns the corresponding byte stream based on the size of the platform. For the definition of the size, you can find it in the gdb macro file of the target platform. For example: GDB/config/<arch> TM-<arch>. H (different versions may be different and I won't find them)

 

Write register group: ("G ")

Eg: $ g123456789abcdef0... # Xx

(Set register0 to 0 x 12345678, and 1 to 0xabcdef0... And so on)

 

With this command, GDB stores the data in the corresponding registers in the byte sequence before the program resumes running. At the same time, the target platform will also respond to GDB feedback, such as success + $ OK # 9A.

 

Write register: ("P ")

Eg: $ P10 = 0040149c # B3

(Set the value of register 16 to 0x40149c)

 

When GDB only wants to set one or two registers, GDB will send this command (instead of ("G") to the target machine. The Register number is the same as that of the read/write register group. At the same time, if the target opportunity is successful, + $ OK # 9A is returned.

 

Memory-related

 

Read Memory: ("M ")

Eg: $ 4015bc, 2 # 5A

(Read 2 bytes of data starting from the address 0x4015bc)

 

The read command sent by GDB determines the values of local variables and global variables, and uses the breakpoint command to replace opcode and the information required by other users. GDB knows the size of the target platform, so the target machine only needs to return the compaction stream, and GDB will reorganize them as appropriate.

The debugging pile of the target machine optimizes the read/write memory commands based on the data width of the target machine. For example, the peripheral configuration register of the Hitachi sh-2 processor can only read and write through 16-bit/32-bit. Therefore, at any time, the debugging pile only uses 16-bit/32-bit access. The following information is returned for the target opportunity:

 

+ $2f86 #-06

 

Write memory: ("M ")

Eg: m4015cc, 2: c320 # 6d

(Write data to address 0x4015cc 0xc320)

If yes, the target machine returns + $ OK # 9A.

 

Program Control commands

The program control command is the command that GDB uses to control the behavior of the program to be debugged. Compared with register-related commands and memory-related commands, it is more difficult to implement control commands.

 

Obtain the final signal ("?")

Eg: $? # 3f

 

This command is used to determine how the target is in the current state. The received response is the same as the final signal ("last signal"), which will be introduced later.

 

 

Single-step command ("S ")

Eg: $ s #73

 

When GDB wants the target to execute an assembly command accurately, GDB will send this command to the target machine. (You can enter step and stepi in the gdb Console.) For the received response, see continue.

 

 

Continue command ("C ")

Eg: $ C #63

 

When you execute the continue command on the console, GDB sends this command back to the target machine. After the target machine successfully parses this command, GDB will release the control to allow the target machine to be debugged to run at full speed.

In addition to the "+" message package returned, the debugging pile does not immediately respond to the step and continue commands, indicating that the message is correctly received. On the contrary, only when the next breakpoint arrives, when the requested command has been executed (STE, P), an exception occurs, or the program exits, the pile responds.

 

There are two ways to respond to these commands: one is simple ("last signal"), and the other is multi-purpose ("expedited response ").

 

Last signal response ("S ")

Eg: + $050 # B8

 

This is the simplest response to lastsignal ("?") Step and continue commands. "05" can be used as a response to any signal value using the POSIX standard signal function. "5" indicates a breakpoint exception, "10" indicates a bus error, and so on.

 

 

Quick Response (expeditedresponse ("T "))

For example: $ t0510: 1238; F: ffe0... # Xx

 

This information combines the final signal response (for example, "05") with some registers that GDB may immediately read. To improve GDB debugging performance when code is executed in one step, GDB can directly obtain the value of this Register (usually PC and Status Register) to avoid sending the read register command.

The format of the register number is the same as that of the read/write register command. In this example, the value of register 16 (hex 10) is 0x1238, and the value of register 15 (f HEX) is 0xffe0.

 

 

Other commands: Console output ("O") -- customizable

Eg: $ 0x48656c6cf2c20776fda-c64210a #55

(Output "Hello, world!" In the GDB Console! \ N ")

 

This command allows the debug pile to send text information to the gdbconsole. The text will be displayed in the console in hexadecimal notation, and GDB will always output information until it encounters ('\ n', 0xa) characters.

This information is usually initiated by the target machine, and GDB will never send a console output information to the target machine.

Empty response (")

When the target machine debugging pile encounters a command that it does not support or understand, it returns an empty response. This allows GDB to select an alternative command if another command is valid.

 

Eg: <an unrecognized command>

Target Server Response: + $#00

 

 

Error Response ("e")

When the target machine debugging pile encounters an error when executing the command, it will return an error message to GDB. For example, a bus error or illegal address access will generate such an error.

 

Eg: <a command that produces an error>

Target Server Response: + $ e01 ##

GDB does not contain any predefined error codes. Therefore, when GDB receives an error message, It outputs the error information in the console and suspends the current process.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.