Chapter 7. Debugging with Fix+Continue: A Tutorial

This chapter provides an interactive sample session that demonstrates most of the Fix and Continue functions. The session outlines common tasks you can perform with Fix and Continue, using example C++ application source to illustrate the use of each function. For complete reference information on the Fix and Continue user interface, see "Fix+Continue Windows".

Most steps in the session let you use either the graphical interface or the command-line alternatives.

This chapter contains the following sections:

Setting Up the Sample Session

For this tutorial, use the demo files in the directory
/usr/demos/WorkShop/bounce, which contain the complete source code for the C++ application bounce. To prepare for the session, you first need to create

Figure 7-1. Execution View Icon

Figure 7-1 Execution View Icon

the fileset, then launch Fix and Continue from the Debugger. You must enter the commands listed below:

  1. cd /usr/demos/WorkShop/bounce

  2. make bounce

  3. cvd bounce &

    The cvd command brings up the CaseVision Debugger, from which you can use the Fix and Continue utility. The Execution View icon (shown in Figure 7-1) and Main View (shown in Figure 7-2) appear. Note that the Debugger shows that the source code status indicator is (Read Only).

    Figure 7-2. Debugger Main View With Fix and Continue Menu

    Figure 7-2 Debugger Main View With Fix and Continue Menu

  4. Open the Execution View and position the window so you can see it and the Debugger Main View.

  5. To see what the program does, click Run. The bounce program opens a window on your desktop. Click Run in the new window, and then add balls from the Actors Menu to see how the program executes. (You may need to resize the bounce window.)

  6. The Execution View shows the program output (see Figure 7-3).

    Figure 7-3. Program Results in Execution View

    Figure 7-3 Program Results in Execution View

    If your screen shows different results, the program files may have been modified during a previous tutorial session.

Redefining a Function

In this section, you will do the following:

  • edit a function

  • change the code of an existing function and then parse and load the function, rebuilding your program to see the effect of your changes on program output (without recompiling)

  • save the changed function to its own separate file

Editing a Function

  1. Choose a function to edit by entering the following on the command line:

    cvd> func Clock::speedChanged 

    This opens the file Clock.C, and places the cursor at the beginning of the function Clock::speedChanged, as shown in Figure 7-4.

    Figure 7-4. Selecting a Function for Redefinition

    Figure 7-4 Selecting a Function for Redefinition

  2. Show line numbers by selecting "Show Line Numbers" from the Debugger Display menu.

  3. Select "Edit" from the Debugger Fix+Continue menu, or enter the Alt-Ctrl-E keyboard accelerator. The function is highlighted.

  4. Note the results as shown in Figure 7-5. Line numbers change to a decimal notation based on the first line number of the function body. The function body highlights to show that it is being edited. The line numbers of the rest of the file are not affected.

    Figure 7-5. Redefined Function

    Figure 7-5 Redefined Function

Changing Code

  1. To increase the speed of the ball, change the value of _delta from 1000 / value to 100 / value.

  2. Click the Stop button in the Debugger to halt the bounce process.

  3. Select "Parse and Load" from the Debugger Fix+Continue menu, or enter the Alt-Ctrl-X keyboard accelerator.

    If there are any errors, the Fix+Continue error messages window opens as shown in Figure 7-6. The Debugger command line also gives a report. If all went as planned, there are no errors or warnings.

    Figure 7-6. Checking Syntax Opens Fix and Continue Status Window

    Figure 7-6 Checking Syntax Opens Fix and Continue Status Window

    If you do have an error, correct it and repeat steps 1-3. You can go to the error location by double-clicking the appropriate line in the error message window. When you see the change ID and activated status, as shown in Figure 7-7, continue with the next step.

    When the parse and load has completed, the highlighting color of the function changes.

    Figure 7-7. Report of Successful Redefinition

    Figure 7-7 Report of Successful Redefinition

  4. Select Continue from the Debugger main view.

  5. The new value is not active until the function is called. To call the function, adjust the slider bar in the bounce window (see Figure 7-8).

    Figure 7-8. Bounce Window

    Figure 7-8 Bounce Window

Deleting Changed Code

If you make a mistake, there's a graceful way out. Suppose for example that you decided you didn't want to change the speed after all. To delete the change, you need merely select the "Delete Edits" option from the Fix+Continue menu in the Source view.

Changing Code From the Debugger Command Line

As an alternative to using the Fix and Continue menu, you can redefine and check syntax for a function from the Debugger command line. Try changing _delta to 100 by entering the following at the command line:

cvd> replace_source "Clock.C":83
"Clock.C":84.0> 
"Clock.C":84.1> 
"Clock.C":84.2> _delta = 100 / value;
"Clock.C":84.3> .

This generates the following output:

Change id: 4 redefined
Change id: 4 modified
Process 5779 stopped at ["select.s":12, 0x0fac2010]
Change id: 4 activated
Change id: 4 , build results:
  4  enabled  /usr/demos/WorkShop/bounce/Clock.C  Clock::speedChanged(int)
cvd> 

If you prefer to use the command line, experiment with add_source and redefine to get the same functionality described for the menu commands. For details on each command, refer to "Debugger Command Line".

Saving Changes

Your original source files are not updated until the changed source file is saved. You could save redefined function changes to Clock.C. However, if you did, the file would not match the tutorial. So just observe the following steps:

  1. Select "Save As..." from the Fix+Continue menu.

  2. Look at the features of the dialog box (see Figure 7-9) that enable you to save your file. To save the changes back to the original source files, click that radio button and then click Apply or OK. To save to a different file, click the other radio button, choose a suffix, and click Apply or OK. Since you don't want to save the changes, press Cancel.

    Alternatively, on the Debugger command line, you could type save_changes -file Clock.C Clock.C. Either method saves all the changes to the file, replacing the compiled source code.

    Figure 7-9. Saving a Function File

    Figure 7-9 Saving a Function File

You usually want to wait until you are finished with Fix and Continue before you save your changes. In addition to the method described above, you can also save your changes with the "Save All Files..." option of the Fix+Continue menu. See "Fix+Continue Menu" for more information.

Setting Breakpoints in Redefined Code

To see how the Debugger works with traps (breakpoints) in redefined code you'll set breakpoints, run the Debugger, and view the results (Figure 7-10).

  1. Choose the function BouncingBall::BouncingBall by entering the following on the command line:

    cvd> func BouncingBall::BouncingBall 

    This opens the file BouncingBall.C, and places the cursor at the beginning of the function BouncingBall::BouncingBall.

  2. Select "Edit" from the Fix+Continue menu or enter Alt-Ctrl-E.

  3. Enter the following line after line 35.3:

    #define SIZE 15

    This makes the size of the balls smaller.

  4. Select "Parse and Load" from the Fix+Continue menu.

  5. Set a breakpoint just after your new SIZE definition by clicking in the source annotation column at line 35.5.

    Alternatively, you can set a breakpoint through the command line by entering stop at # or b # where # is the line number at which you want your breakpoint. Note that in code that has already been parsed and loaded, the line number is in decimal notation.

    Figure 7-10. Stopping After Breakpoints in Redefined Code

    Figure 7-10 Stopping After Breakpoints in Redefined Code

  6. Select Run, then in the bounce window pull down the Actors menu and select "Add Red Ball". The Debugger command line reports that the process stopped at some point in the code. You see the following information in the Debugger command line:

    [1] Stop at file /usr/demos/WorkShop/bounce/BouncingBall.C line 35.6
    [0] Process 595 stopped at ["BouncingBall.C":35, 0x004088d0]

  7. Select "Call Stack" from the Views menu to view the results of the breakpoint (see Figure 7-11).

    Figure 7-11. Call Stack BreakPoint Results

    Figure 7-11 Call Stack BreakPoint Results

  8. Select "Trap Manager" from the Views menu to view the locations of the traps (see Figure 7-12).

    Figure 7-12. Trap Manager BreakPoint Results

    Figure 7-12 Trap Manager BreakPoint Results

  9. Remove the breakpoint by clicking on it in the source annotation column.

Viewing Status

Pull down the Fix+Continue menu, choose the Views submenu, and select "Status Window". The View Status window opens, as shown in Figure 7-13.

Figure 7-13. Using the View Status Window

Figure 7-13 Using the View Status Window

Comparing Original and Redefined Code

You can compare your modified code to the original source when using Fix and Continue. This section shows you several ways to view your changes.

Switching Between Compiled and Redefined Code

If you want to see how the redefined code makes your executable different, follow these steps:

  1. Select Run to view your redefined code. Notice that the balls you add are smaller in your modified version.

  2. Place the insertion point in function BouncingBall.

  3. Select "Edit<-->Compiled" from the Fix+Continue menu. This disables your changes.

  4. Select Continue. Notice that the balls you add are now their original size, and that the Debugger command line states that the change has been deactivated.

    You can get the same results by entering the command disable_changes# from the Debugger command line, where # is the redefined function ID number.

    To re-enable your changes, do the following:

  5. Select Stop.

  6. Select "Edit<-->Compiled" from the Fix+Continue menu. This re-enables your changes. The balls you add will now be smaller.

    You can get the same results by entering the command enable_changes# at the Debugger command line.

Comparing Function Definitions

  1. Place the insertion point in the BouncingBall function body.

  2. Pull down the Fix+Continue menu, choose the Show Difference submenu, and select "For Function". A xdiff window opens as shown in Figure 7-14.

    Figure 7-14. Comparing Compiled vs. Redefined Function Code: xdiff

    Figure 7-14 Comparing Compiled vs. Redefined Function Code: xdiff

    You can get the same result by entering the command show_diff# from the Debugger command line.

    If you don't like xdiff, you can change the comparison tool by pulling down the Fix+Continue menu, choosing the Show Difference submenu, and selecting "Set Diff Tool...".

Comparing Source Code Files

When you have made several redefinitions to a file, sometimes you need a side-by-side comparison of the entire file. To see how your changes to the file look, pull down the Fix+Continue menu, choose the Show Difference submenu, and select "For Function". This opens a xdiff window that displays the entire file, rather than just the function.

You'll get the same result from the Debugger command line if you enter the following:

show_diff -file BouncingBall.C

As an alternative to pulling down menus using the mouse, you can use mnemonics to select the menu item from the keyboard. After closing the difference window, you'll reopen it. With the insertion point anywhere in the file, enter the following:

Alt-f d f

Ending the Session

Exit the Debugger by pulling down the Admin menu and choosing "Exit".