Debugging programs involving multiple processes

Application programs involving multiple processes are those that call the fork() and exec() functions. When a program forks, the operating system creates another process that has the same image as the original; the original is called the parent process, and the created process is called the child process.

When a process calls an exec() function, a new program takes over or overlays the original program. Under default circumstances, the dbx utility can debug only the original or parent program; however, dbx can follow the execution and debug the program.

You must enter the multproc on subcommand to enable dbx to debug application programs that call an exec() function or to debug child processes created through use of the fork() function.

When multiprocess debugging is enabled and a fork occurs, both the parent and the child process are halted in the fork. A separate shell session needs to be opened for a new version of dbx to be started to control the running of the child process. When the fork occurs, execution is stopped in the parent, and dbx displays the state of the program:
(dbx) multproc on
(dbx) multproc
 
multi-process debugging is enabled
(dbx) run
 
application forked, child pid=65544, process stopped, awaiting input
use 'dbx -A 65544' on another terminal to establish a debug session
for the child pid
 
stopped due to fork with multiprocessing enabled in fork at 0x2a89074
0x2a89074 bfffd084     icm    $r15,X'F',X'84'($sp)
(dbx)
Another shell session must now be opened to debug the child process. On this second shell session, enter the dbx -A option with the process ID for the child:
dbx -A 65544
 
Waiting to attach process 65544 …
 
attached in fork at 0x2a89074
0x2a89074 bfffd084     icm    $r15,X'F',X'84'($sp)
(dbx)

At this point there are two distinct debugging sessions. The debugging session for the child process retains all the breakpoints from the parent process, but only the parent process can be rerun.

When the program calls an exec() function while in multiprocess debugging mode, the program overwrites itself and the original symbol information becomes obsolete. All breakpoints are deleted when the exec() occurs, and the new program is stopped and identified in order for the debugging to be meaningful. dbx attaches itself to the new program image, reports the name, and then prompts for input:
(dbx31) multproc
Multi-process debugging is enabled
(dbx31) run
FDBX6421: Loaded debug data from "./execprog.dbg"
FDBX0150: Debug target is 31-bit
FDBX0279: Attaching to process from exec…

FDBX6421: Loaded debug data from "./samp.dbg"

(dbx31)

Enter the map subcommand to determine the name of the new program being debugged.

When you are finished debugging the new program and end the dbx debugging session, enter the exit shell command to end the shell session and return to your first shell session.