Debugging a Program With dbx

Chapter 13 Debugging Child Processes

This chapter describes how to debug a child process. dbx has several facilities to help you debug processes that create children via fork (2) and exec (2).

This chapter is organized into the following sections:

Attaching to Child Processes

You can attach to a running child in one of the following ways.

When starting dbx:


$ dbx progname
 pid

From the command line:


(dbx) debug progname
 pid

You can substitute progname with the name - (minus sign), so dbx finds the executable associated with the given process id (pid). After using a -, a subsequent run or rerun will not work because dbx does not know the full path name of the executable.

Following the exec

If a child process executes a new program using exec(2) or one of its variations, the process id does not change, but the process image does. dbx automatically takes note of an exec() and does an implicit reload of the newly executed program.

The original name of the executable is saved in $oprog. To return to it, use debug $oprog.

Following fork

If a child process does vfork(), fork(1), or fork(2), the process id changes, but the process image stays the same. Depending on how the dbxenv variable follow_fork_mode is set, dbx does the following:

Parent 

In the traditional behavior, dbx ignores the fork and follows the parent.

Child 

In this mode, dbx automatically switches to the forked child using the new pid. All connection to and awareness of the original parent is lost.

Both 

This mode is only available when using dbx through Sun WorkShop.

Ask 

You are prompted to choose parent, child, both, or stop to investigate whenever dbx detects a fork. If you choose stop, you can examine the state of the program, then type cont to continue, in which case you will be prompted again to select which way to proceed.

Interacting with Events

All breakpoints and other events are deleted for any exec() or fork() process. You can override the deletion for follow fork by setting the dbxenv variable follow_fork_inherit to on, or make them permanent using the -perm eventspec modifier. For more information on using event specification modifiers, see Chapter 6, Event Management."