Next: , Previous: GDB/MI Output Records, Up: GDB/MI


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",
         enabled="y",addr="0x08048564",func="main",file="myprog.c",
         fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
         times="0"}
     <- (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",
        frame={addr="0x08048564",func="main",
        args=[{name="argc",value="1"},{name="argv",value="0xbfc4d4d4"}],
        file="myprog.c",fullname="/home/nickrob/myprog.c",line="68"}
     <- (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)