Using Sun WorkShop

Debugging Processes Simultaneously

You can debug more than one program at a time, with each program connected to a separate debugging session. Following are three examples of programs you may want to debug simultaneously:

Although you are debugging multiple sessions, you can see the context of only one session at a time. The Active Sessions dialog box (see Figure 5-6) maintains a list of all debugging sessions so that you can move between them. The current program is marked with an arrow. When you switch to a different session, the Debugging window, the editor window, the Dbx Commands window, and the other displays reflect the context of the new session.

Figure 5-6 Active Sessions Dialog Box

Graphic

Debugging multiple sessions consumes resources and may slow down your system. The Debugging window states how many active sessions you have. To remove sessions you no longer need, click Quit Session or Detach in the Active Sessions dialog box.

If you are debugging a program, and you ask to debug another program, a message tells you that you are currently debugging a program. You will be prompted to terminate or detach the current session and load a new debugging session, reuse the current session, or debug both sessions. Choose to debug both only if you want to debug both programs simultaneously.

Managing Sessions

During a Sun WorkShop session, you can debug any number of programs. A list of these programs is maintained in the Active Sessions dialog box and in the Sessions Display in the Debugging window, so you can easily terminate, detach, quit, or move between programs. The current program is marked with an arrow.

To manage your sessions using the Active Sessions dialog box:

  1. In the Debugging window, choose Debug > Manage Sessions.

    The Active Sessions dialog box opens.

  2. Select a program from the scrolling list.

  3. Click one of the following buttons:

     Set Current Makes the selected program the current program. The Stack pane, the editor window, and other displays update to reflect the context of the selected program.
     Terminate Terminates the program without terminating the debugging session.
     Detach Detaches the selected program without terminating the program or the debugging session.
     Quit Session Terminates the selected program and removes the debugging session. If you have only one session and you click this button, the session is removed and the Debugging window notes that there are no debugging sessions.

  4. Click Close.

To manage your sessions in the Sessions display of the Debugging window:

  1. If the Sessions/Threads Pane is not open, drag the sash above the Stack Pane to open it.

  2. If the pane is showing the Threads Display, click the Sessions radio button at the top of the pane.


    Note -

    Be careful when debugging multiple programs. Debugging more than two programs may slow down your system considerably. Always be sure to terminate, detach, or quit a session you no longer need.


Quitting a Debugging Session

Debugging multiple sessions can consume resources and slow down your system. If you no longer need a debugging session, use Quit Session to detach a running process or terminate a loaded process. The debugging session is not preserved.

To quit the current debugging session:

  1. In the Debugging window, choose Debug > Manage Sessions.

  2. From the list, select the session you want to quit.

  3. Click Quit Session.


    Note -

    The Terminate command terminates debugging of the current process, but preserves the debugging session. When you load another program, it should load faster than the first one you loaded because the session is already started. Keeping the debugging session around, however, takes up swap space. If you are running out of swap space, use Quit Session to terminate the program and quit the debugging session.


Debugging a Child Process

When a process forks a child process, you can choose to debug the parent process, the child process, or both. You can also override the normal deletion of all breakpoints from the forked process.

The Sampling Collector is disabled for a forked process.

If you consistently follow the same process across executions, you can bypass the Follow Fork dialog box by designating the default action you want to take.

To set the default for a forked process:

  1. From the Debugging window, choose Debug > Debugging Options.

  2. Choose Category > Forks and Threads.

  3. Click the appropriate radio button:

      Parent The fork is ignored and the parent is followed. This is the default behavior.
     Child Debugging switches to the forked child. The process ID of the current process changes to the child's process ID. The parent continues as if it had been detached, and the child process is suspended as if it had been attached. Use Go or Step Into to execute the child process.
     Both A second debugging session is launched to debug the child process, and becomes the current session. The parent's debugging session remains as an active process. The child process is suspended as if it had been attached.
     Ask User Whenever a fork is detected, the Follow Fork dialog box opens, allowing you to choose between the parent, the child, or both processes at the same time. You can examine the state of your program each time to see which fork you want to follow.

  4. Click OK to apply your choices to the current session, or click Save As Defaults and then click OK to use them as the new defaults.

The selected action occurs whenever the process executes fork().

To allow the child to inherit the parent's breakpoints when the new fork will not execute a different process:

  1. From the Debugging window, choose Debug > Debugging Options.

  2. Choose Category > Forks and Threads.

  3. At Child process inherits parent's breakpoints, click the checkbox to enable it.

  4. Click OK to apply your choices to the current session, or click Save As Defaults and then click OK to save your choices as the new defaults.