21.1.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.

Evaluate expression

Here is an example to evaluate an expression:

-> -data-evaluate-expression 2+3 <- (gdb)

<- ^done,value="5" <- (gdb)

and later:

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

Simple CLI command

Here is 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)

A bad command

Here is what happens if you pass a bad command:

-> -rubbish

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

21.2 GDB/MI compatibility with CLI

To help users get familiar with GDB CLI, GDB/MI accepts existing CLI commands. As specified by the syntax, such commands can be directly entered into the GDB/MI interface and GDB will respond.

This mechanism is provided as an aid to developers of GDB/MI clients and not as a reliable interface into the CLI. Since the command is being interpreted in an environment that assumes GDB/MI behaviour, the exact output of such commands is likely to end up being an un-supported hybrid of GDB/MI and CLI output.

310 The GDB/MI Interface