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

Note the line breaks shown in the examples are here only for readability, they don't appear in the real output.

Setting a Breakpoint

Setting a breakpoint generates synchronous output which contains detailed information of the breakpoint.

     -> -break-insert main
     <- ^done,bkpt={number="1",type="breakpoint",disp="keep",
     <- (gdb)

Program Execution

Program execution generates asynchronous records and MI gives the reason that execution stopped.

     -> -exec-run
     <- ^running
     <- (gdb)
     <- *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
     <- (gdb)
     -> -exec-continue
     <- ^running
     <- (gdb)
     <- *stopped,reason="exited-normally"
     <- (gdb)

Quitting gdb

Quitting gdb just prints the result class ^exit.

     -> (gdb)
     <- -gdb-exit
     <- ^exit

Please note that ^exit is printed immediately, but it might take some time for gdb to actually exit. During that time, gdb performs necessary cleanups, including killing programs being debugged or disconnecting from debug hardware, so the frontend should wait till gdb exits and should only forcibly kill gdb if it fails to exit in reasonable time.

A Bad Command

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

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