Gdb/GDB 002fMI-Simple-Examples
Next: GDB/MI Command Description Format, Previous: GDB/MI Output Records, Up: GDB/MI [Contents][Index]
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", arch="i386:x86_64"} <- (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)