26.4. gdb/mi Command Syntax

26.4.1. gdb/mi Input Syntax

command ==>

cli-command | mi-command

cli-command ==>

[ token ] cli-command nl, where cli-command is any existing gdb CLI command.

mi-command ==>

[ token ] "-" operation ( " " option )* [ " -" ] ( " " parameter )* nl

token ==>

"any sequence of digits"

option ==>

"-" parameter [ " " parameter ]

parameter ==>

non-blank-sequence | c-string

operation ==>

any of the operations described in this chapter

non-blank-sequence ==>

anything, provided it doesn't contain special characters such as "-", nl, """ and of course " "

c-string ==>

""" seven-bit-iso-c-string-content """

nl ==>

CR | CR-LF

Notes:

Pragmatics:

26.4.2. gdb/mi Output Syntax

The output from gdb/mi consists of zero or more out-of-band records followed, optionally, by a single result record. This result record is for the most recent command. The sequence of output records is terminated by (gdb).

If an input command was prefixed with a token then the corresponding output for that command will also be prefixed by that same token.

output ==>

( out-of-band-record )* [ result-record ] "(gdb)" nl

result-record ==>

[ token ] "^" result-class ( "," result )* nl

out-of-band-record ==>

async-record | stream-record

async-record ==>

exec-async-output | status-async-output | notify-async-output

exec-async-output ==>

[ token ] "*" async-output

status-async-output ==>

[ token ] "+" async-output

notify-async-output ==>

[ token ] "=" async-output

async-output ==>

async-class ( "," result )* nl

result-class ==>

"done" | "running" | "connected" | "error" | "exit"

async-class ==>

"stopped" | others (where others will be added depending on the needs--this is still in development).

result ==>

variable "=" value

variable ==>

string

value ==>

const | tuple | list

const ==>

c-string

tuple ==>

"{}" | "{" result ( "," result )* "}"

list ==>

"[]" | "[" value ( "," value )* "]" | "[" result ( "," result )* "]"

stream-record ==>

console-stream-output | target-stream-output | log-stream-output

console-stream-output ==>

"~" c-string

target-stream-output ==>

"@" c-string

log-stream-output ==>

"&" c-string

nl ==>

CR | CR-LF

token ==>

any sequence of digits.

Notes:

Refer to Section 26.6.2 gdb/mi Stream Records, for more details about the various output records.

26.4.3. Simple Examples of gdb/mi Interaction

This subsection presents several simple examples of interaction using the gdb/mi interface. In these examples, -> means that the following line is passed to gdb/mi as input, while <- means the output received from gdb/mi.

26.4.3.1. Target Stop

Here's an example of stopping the inferior process:

-> -stop
<- (gdb)

and later:

<- *stop,reason="stop",address="0x123",source="a.c:123"
<- (gdb)

26.4.3.2. Simple CLI Command

Here's an example of a simple CLI command being passed through gdb/mi and on to the CLI.

-> print 1+2
<- &"print 1+2\n"
<- ~"$1 = 3\n"
<- ^done
<- (gdb)

26.4.3.3. Command With Side Effects

-> -symbol-file xyz.exe
<- *breakpoint,nr="3",address="0x123",source="a.c:123"
<- (gdb)

26.4.3.4. A Bad Command

Here's what happens if you pass a non-existent command:

-> -rubbish
<- ^error,msg="Undefined MI command: rubbish"
<- (gdb)