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:
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
cd /usr/demos/WorkShop/bounce
make bounce
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).
Open the Execution View and position the window so you can see it and the Debugger Main View.
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.)
The Execution View shows the program output (see Figure 7-3).
If your screen shows different results, the program files may have been modified during a previous tutorial session.
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
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.
Show line numbers by selecting "Show Line Numbers" from the Debugger Display menu.
Select "Edit" from the Debugger Fix+Continue menu, or enter the Alt-Ctrl-E keyboard accelerator. The function is highlighted.
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.
To increase the speed of the ball, change the value of _delta from 1000 / value to 100 / value.
Click the Stop button in the Debugger to halt the bounce process.
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.
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.
Select Continue from the Debugger main view.
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).
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.
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".
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:
Select "Save As..." from the Fix+Continue menu.
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.
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.
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).
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.
Select "Edit" from the Fix+Continue menu or enter Alt-Ctrl-E.
Enter the following line after line 35.3:
#define SIZE 15 |
This makes the size of the balls smaller.
Select "Parse and Load" from the Fix+Continue menu.
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.
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] |
Select "Call Stack" from the Views menu to view the results of the breakpoint (see Figure 7-11).
Select "Trap Manager" from the Views menu to view the locations of the traps (see Figure 7-12).
Remove the breakpoint by clicking on it in the source annotation column.
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.
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.
If you want to see how the redefined code makes your executable different, follow these steps:
Select Run to view your redefined code. Notice that the balls you add are smaller in your modified version.
Place the insertion point in function BouncingBall.
Select "Edit<-->Compiled" from the Fix+Continue menu. This disables your changes.
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.
Select Stop.
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.
Place the insertion point in the BouncingBall function body.
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.
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...".
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