Next: GDB/MI Stack Manipulation, Previous: GDB/MI Thread Commands, Up: GDB/MI

### 27.11 gdb/mi Program Execution

These are the asynchronous commands which generate the out-of-band record ``*stopped`'. Currently gdb only really executes asynchronously with remote targets and this interaction is mimicked in other cases.

#### The `-exec-continue` Command

##### Synopsis

          -exec-continue [--all|--thread-group N]

Resumes the execution of the inferior program until a breakpoint is encountered, or until the inferior exits. In all-stop mode (see All-Stop Mode), may resume only one thread, or all threads, depending on the value of the ``scheduler-locking`' variable. In non-stop mode (see Non-Stop Mode), if the ``--all`' is not specified, only the thread specified with the ``--thread`' option (or current thread, if no ``--thread`' is provided) is resumed. If ``--all`' is specified, all threads will be resumed. The ``--all`' option is ignored in all-stop mode. If the ``--thread-group`' options is specified, then all threads in that thread group are resumed.

##### gdb Command

The corresponding gdb corresponding is ``continue`'.

##### Example

         -exec-continue
         ^running
         (gdb)
         @Hello world
         *stopped,reason="breakpoint-hit",disp="keep",bkptno="2",frame={
         func="foo",args=[],file="hello.c",fullname="/home/foo/bar/hello.c",
         line="13"}
         (gdb)

#### The `-exec-finish` Command

##### Synopsis

          -exec-finish

Resumes the execution of the inferior program until the current function is exited. Displays the results returned by the function.

##### gdb Command

The corresponding gdb command is ``finish`'.

##### Example

Function returning `void`.

         -exec-finish
         ^running
         (gdb)
         @hello from foo
         *stopped,reason="function-finished",frame={func="main",args=[],
         file="hello.c",fullname="/home/foo/bar/hello.c",line="7"}
         (gdb)

Function returning other than `void`. The name of the internal gdb variable storing the result is printed, together with the value itself.

         -exec-finish
         ^running
         (gdb)
         *stopped,reason="function-finished",frame={addr="0x000107b0",func="foo",
         args=[{name="a",value="1"],{name="b",value="9"}},
         file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"},
         gdb-result-var="$1",return-value="0"
         (gdb)

#### The `-exec-interrupt` Command

##### Synopsis

          -exec-interrupt [--all|--thread-group N]

Interrupts the background execution of the target. Note how the token associated with the stop message is the one for the execution command that has been interrupted. The token for the interrupt itself only appears in the ``^done`' output. If the user is trying to interrupt a non-running program, an error message will be printed.

Note that when asynchronous execution is enabled, this command is asynchronous just like other execution commands. That is, first the ``^done`' response will be printed, and the target stop will be reported after that using the ``*stopped`' notification.

In non-stop mode, only the context thread is interrupted by default. All threads will be interrupted if the ``--all`' option is specified. If the ``--thread-group`' option is specified, all threads in that group will be interrupted.

##### gdb Command

The corresponding gdb command is ``interrupt`'.

##### Example

         (gdb)
         111-exec-continue
         111^running

         (gdb)
         222-exec-interrupt
         222^done
         (gdb)
         111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
         frame={addr="0x00010140",func="foo",args=[],file="try.c",
         fullname="/home/foo/bar/try.c",line="13"}
         (gdb)

         (gdb)
         -exec-interrupt
         ^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
         (gdb)

#### The `-exec-jump` Command

##### Synopsis

          -exec-jump location

Resumes execution of the inferior program at the location specified by parameter. See Specify Location, for a description of the different forms of location.

##### gdb Command

The corresponding gdb command is ``jump`'.

##### Example

         -exec-jump foo.c:10
         *running,thread-id="all"
         ^running

#### The `-exec-next` Command

##### Synopsis

          -exec-next

Resumes execution of the inferior program, stopping when the beginning of the next source line is reached.

##### gdb Command

The corresponding gdb command is ``next`'.

##### Example

         -exec-next
         ^running
         (gdb)
         *stopped,reason="end-stepping-range",line="8",file="hello.c"
         (gdb)

#### The `-exec-next-instruction` Command

##### Synopsis

          -exec-next-instruction

Executes one machine instruction. If the instruction is a function call, continues until the function returns. If the program stops at an instruction in the middle of a source line, the address will be printed as well.

##### gdb Command

The corresponding gdb command is ``nexti`'.

##### Example

         (gdb)
         -exec-next-instruction
         ^running

         (gdb)
         *stopped,reason="end-stepping-range",
         addr="0x000100d4",line="5",file="hello.c"
         (gdb)

#### The `-exec-return` Command

##### Synopsis

          -exec-return

Makes current function return immediately. Doesn't execute the inferior. Displays the new current frame.

##### gdb Command

The corresponding gdb command is ``return`'.

##### Example

         (gdb)
         200-break-insert callee4
         200^done,bkpt={number="1",addr="0x00010734",
         file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"}
         (gdb)
         000-exec-run
         000^running
         (gdb)
         000*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
         frame={func="callee4",args=[],
         file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
         fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"}
         (gdb)
         205-break-delete
         205^done
         (gdb)
         111-exec-return
         111^done,frame={level="0",func="callee3",
         args=[{name="strarg",
         value="0x11940 \"A string argument.\""}],
         file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
         fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"}
         (gdb)

#### The `-exec-run` Command

##### Synopsis

          -exec-run

Starts execution of the inferior from the beginning. The inferior executes until either a breakpoint is encountered or the program exits. In the latter case the output will include an exit code, if the program has exited exceptionally.

##### gdb Command

The corresponding gdb command is ``run`'.

##### Examples

         (gdb)
         -break-insert main
         ^done,bkpt={number="1",addr="0x0001072c",file="recursive2.c",line="4"}
         (gdb)
         -exec-run
         ^running
         (gdb)
         *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
         frame={func="main",args=[],file="recursive2.c",
         fullname="/home/foo/bar/recursive2.c",line="4"}
         (gdb)

Program exited normally:

         (gdb)
         -exec-run
         ^running
         (gdb)
         x = 55
         *stopped,reason="exited-normally"
         (gdb)

Program exited exceptionally:

         (gdb)
         -exec-run
         ^running
         (gdb)
         x = 55
         *stopped,reason="exited",exit-code="01"
         (gdb)

Another way the program can terminate is if it receives a signal such as `SIGINT`. In this case, gdb/mi displays this:

         (gdb)
         *stopped,reason="exited-signalled",signal-name="SIGINT",
         signal-meaning="Interrupt"

#### The `-exec-step` Command

##### Synopsis

          -exec-step

Resumes execution of the inferior program, stopping when the beginning of the next source line is reached, if the next source line is not a function call. If it is, stop at the first instruction of the called function.

##### gdb Command

The corresponding gdb command is ``step`'.

##### Example

Stepping into a function:

         -exec-step
         ^running
         (gdb)
         *stopped,reason="end-stepping-range",
         frame={func="foo",args=[{name="a",value="10"},
         {name="b",value="0"}],file="recursive2.c",
         fullname="/home/foo/bar/recursive2.c",line="11"}
         (gdb)

Regular stepping:

         -exec-step
         ^running
         (gdb)
         *stopped,reason="end-stepping-range",line="14",file="recursive2.c"
         (gdb)

#### The `-exec-step-instruction` Command

##### Synopsis

          -exec-step-instruction

Resumes the inferior which executes one machine instruction. The output, once gdb has stopped, will vary depending on whether we have stopped in the middle of a source line or not. In the former case, the address at which the program stopped will be printed as well.

##### gdb Command

The corresponding gdb command is ``stepi`'.

##### Example

         (gdb)
         -exec-step-instruction
         ^running

         (gdb)
         *stopped,reason="end-stepping-range",
         frame={func="foo",args=[],file="try.c",
         fullname="/home/foo/bar/try.c",line="10"}
         (gdb)
         -exec-step-instruction
         ^running

         (gdb)
         *stopped,reason="end-stepping-range",
         frame={addr="0x000100f4",func="foo",args=[],file="try.c",
         fullname="/home/foo/bar/try.c",line="10"}
         (gdb)

#### The `-exec-until` Command

##### Synopsis

          -exec-until [ location ]

Executes the inferior until the location specified in the argument is reached. If there is no argument, the inferior executes until a source line greater than the current one is reached. The reason for stopping in this case will be ``location-reached`'.

##### gdb Command

The corresponding gdb command is ``until`'.

##### Example

         (gdb)
         -exec-until recursive2.c:6
         ^running
         (gdb)
         x = 55
         *stopped,reason="location-reached",frame={func="main",args=[],
         file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="6"}
         (gdb)