Chapter 2. Using the Debugger

The WorkShop Debugger is a UNIX source-level debugging tool that provides special windows (views) for displaying program data and execution states as the program executes. The Debugger lets you set various types of breakpoints and watch points where you can conveniently view data such as variables, expressions, structures, large arrays, call stacks, and machine-level values.

The Debugger goes far beyond the capabilities of dbx. It includes fast data watchpoints and other types of breakpoints; graphical views for displaying local variables, source-level expressions, array variables, and data structures; and debugging at the machine level.

Debugger User Model

All WorkShop activities can be accessed from the Main View window, which is illustrated in Figure 2-1.

Figure 2-1. Major Areas of the Main View Window

The basic steps for debugging an application are as follows:

  1. Invoke the Debugger by typing:

    % cvd [-pid pid] [-host host] [executable [corefile]]

    The -pid option lets you attach the Debugger to a running process. You can use this to determine why a live process is in an infinite loop or is otherwise hung.

    The -host option lets you specify a remote host on which the target executable will be run; the Debugger runs locally. This option is useful if any of the following criteria apply to your application:

    • You do not want Debugger windows to interfere with the application you are debugging.

    • You are supporting an application remotely.

    • You do not want to use the Debugger on the target system for another reason.

    The argument executable is the name of the executable file for the process you want to run. It is optional; you can invoke the Debugger first and later specify the name of the executable file.

    The corefile option lets you invoke the Debugger and specify a core file (with the name of its executable file) to try to determine why a program crashed.

  2. Set breakpoints in the source code.

    You can set a simple breakpoints by clicking the left mouse button in the annotation column to the left of the source code display or by using the Traps menu. More complex traps can be set and managed from the Trap Manager window, the Signal Panel, and the Syscall Panel, all of which can be accessed from the Views menu. You can also set breakpoints by typing them at the Debugger command line in the Main View window. You can stop a process at any time by clicking the Stop button in the Main View.

  3. Start the program by clicking the Run button in the Main View.

  4. When the process stops at a breakpoint or other stopping point of interest, you can examine the data in one of the Debugger view windows (accessed from the Views menu).

    You can display windows at any time; they update automatically each time the program stops. Figure 2-2 shows four typical Debugger views and indicates how you access them from the Views menu.

    Figure 2-2. Typical Debugger Views Accessible at a Breakpoint

    Figure 2-3, shows the Array Visualizer window, a powerful view for examining data in arrays of up to 100 x 100 elements. You can look for problem areas in a 3D rendering of the array, click on the area of interest, and view the numerical values in a spreadsheet format. Note the high point coming out of the 3D image; it demonstrates how anomalies in large arrays stand out.

    Figure 2-3. Array Visualizer Window



    Note: For an explanation of all controls and menus on this window, refer to the ProDev Workshop: Debugger User's Guide.

    If you need to debug your application at the machine level, you can use Register View, Disassembly View, or Memory View, as shown in Figure 2-4. These views are accessed from the Views menu in the Debugger Main View.

    Figure 2-4. Machine-Level Debugger Views


  5. Use the control panel options in the Main View to continue execution (see Figure 2-1).

    From any breakpoint or trap, you have the following options:

    • Click the Continue button to run the program until the next breakpoint.

    • Choose the Continue To selection in the PC menu to proceed to a specified source line. (Placing the cursor on a specific source line also specifies the line.)

    • Choose the Jump To selection in the PC menu to go to the line specified by the cursor, skipping over any intermediate code.

    • Click the Step Into button to continue execution by one line or by a specified number of lines. To specify a number, hold down the right mouse button while the cursor is positioned over the Step Into button and select a number from the resulting dialog box. The process then continues the specified number of source lines and enters any called functions.

    • Click the Step Over button to continue execution by one line or by a specified number of lines as with the Step Into button. The process then continues the specified number of source lines but does not enter any called functions.

    • Click the Return button to execute the remaining instructions in a function and stop upon return from that function.

  6. Check out the source code that needs to be fixed.

    If you find a bug and are using an integrated source control program, you can check out the source code from the Main View (or the Source View window, an alternate editing window).

    Choose Check Out from the Versioning submenu of the Source menu.

  7. Fix any problems in your code by using the source code display area in the Main View, Source View, or by using the editor of your choice.

    Both the Main View and Source View allow you to annotate and do simple edits on your code. Source View also lets you display test data from the Performance Analyzer and Tester in the annotation column. If you prefer to view source code in a text editor other than Source View, add the following line to your .Xdefaults file:

    *editorCommand: editor

    The editor option is the command for the editor you want to use.

  8. Recompile using the Build Manager.

    The Build Manager has two windows: Build View and Build Analyzer. Build View lets you compile, view compile error lists, and access the problem code in Source View or an editor of your choice. Build Analyzer lets you view build dependencies and recompilation requirements, and access source files. Build View uses the UNIX make facility as its default build software. Although Build Analyzer determines dependencies using make, you can substitute the build software of your choice, that is, any make facility that runs on SGI platforms.

The following table details where to find more information about the Debugger in the ProDev Workshop: Debugger User's Guide.

Table 2-1. Debugger Information Details

Topic

See

General Debugger information

Chapter 1, “WorkShop Debugger Overview”

Basic Debugger Usage

Chapter 2, “Basic Debugger Usage

Debugger interaction with source files

Chapter 3, “Selecting Source Files

Debugger tutorial

Chapter 4, “Tutorial: The jello Program”

Comprehensive information about setting breakpoints and traps

Chapter 5, “Setting Traps”

Controlling execution in a process (stepping, jumping, etc.)

Chapter 6, “Controlling Program Execution”

Examining Debugger data in general at the source level

Chapter 7, “Viewing Program Data”

Tracing through the call stack

Chapter 7, “Viewing Program Data”

Entering expressions to be evaluated at stopping points

Chapter 7, “Viewing Program Data ”

Fix+Continue

Chapter 8, “Debugging with Fix+Continue”

Using the debugger to trap memory allocation problems

Chapter 9, “Detecting Heap Corruption”

Debugging multiprocesses

Chapter 10, “Multiple Process Debugging”

X/Motif Analyzer

Chapter 11, “X/Motif Analyzer”

Viewing or changing the values of variables

Appendix A, “ Variable Browser” subsection

Examining data in arrays using the 3D or spreadsheet format

Appendix A, “ Array Browser” subsection

Determining the data structures of variables

Appendix A, “ Structure Browser” subsection

Using the Debugger command line

Appendix A, “Debugger Command Line” subsection

Examining debugger data at the machine level

Appendix A, “Machine-level Debugging Windows” subsection