Next: , Previous: Kill Process, Up: Running


4.9 Debugging Multiple Inferiors

Some gdb targets are able to run multiple processes created from a single executable. This can happen, for instance, with an embedded system reporting back several processes via the remote protocol.

gdb represents the state of each program execution with an object called an inferior. An inferior typically corresponds to a process, but is more general and applies also to targets that do not have processes. Inferiors may be created before a process runs, and may (in future) be retained after a process exits. Each run of an executable creates a new inferior, as does each attachment to an existing process. Inferiors have unique identifiers that are different from process ids, and may optionally be named as well. Usually each inferior will also have its own distinct address space, although some embedded targets may have several inferiors running in different parts of a single space.

Each inferior may in turn have multiple threads running in it.

To find out what inferiors exist at any moment, use info inferiors:

info inferiors
Print a list of all inferiors currently being managed by gdb.

gdb displays for each inferior (in this order):

  1. the inferior number assigned by gdb
  2. the target system's inferior identifier

An asterisk `*' preceding the gdb inferior number indicates the current inferior.

For example,

     (gdb) info inferiors
       Num  Description
     * 1    process 2307
       2    process 3401

To switch focus between inferiors, use the inferior command:

inferior infno
Make inferior number infno the current inferior. The argument infno is the inferior number assigned by gdb, as shown in the first field of the `info inferiors' display.

To quit debugging one of the inferiors, you can either detach from it by using the detach inferior command (allowing it to run independently), or kill it using the kill inferior command:

detach inferior infno
Detach from the inferior identified by gdb inferior number infno, and remove it from the inferior list.


kill inferior infno
Kill the inferior identified by gdb inferior number infno, and remove it from the inferior list.

To be notified when inferiors are started or exit under gdb's control use set print inferior-events:

set print inferior-events
set print inferior-events on
set print inferior-events off
The set print inferior-events command allows you to enable or disable printing of messages when gdb notices that new inferiors have started or that inferiors have exited or have been detached. By default, these messages will not be printed.


show print inferior-events
Show whether messages will be printed when gdb detects that inferiors have started, exited or have been detached.