15.4.1 Continuous Execution

Continuous execution lets you quickly execute the bug-free sections of code which would otherwise take a long time to execute one instruction at a time.

The simplest form of continuous execution is to click the line of code you want to debug or examine in more detail with the right mouse button. The program executes up to the start of this line, then pauses. An alternative method is to position the cursor on this line, then press F7.

You can also pause execution at a specific line of code with a “breakpoint.” There are several types of breakpoints. Breakpoints are explained in the following section.

Selecting Breakpoint Lines

Summary: Breakpoints can be tied to lines of code.

You can skip over those parts of the program that you don't want to examine by specifying one or more lines as breakpoints. The program executes up to the first breakpoint, then pauses. Pressing F5 continues program execution up to the next breakpoint, and so on. (You can halt execution at any time by pressing CTRL+C.)

Summary: There is no limit to the number of breakpoints.

You can set as many breakpoints as you like (limited only by available memory). There are several ways to set breakpoints:

Double-click anywhere on the desired breakpoint line. The selected line is highlighted to show that it is a breakpoint. To remove the breakpoint, double-click the line a second time.

Position the cursor anywhere on the line at which you want execution to pause. Press F9 to select the line as a breakpoint and highlight it. Press F9 a second time to remove the breakpoint and highlighting.

Display the Set Breakpoint dialog box by choosing Set Breakpoint from the Watch menu. Select one of the breakpoint options that permits a line (“location”) to be specified. The line at the cursor is the default breakpoint line in the Location field. If this line is not the desired location, enter the line number desired. (You must place a period in front of the line number, or CodeView will interpret the number as an absolute address.) To remove the breakpoint, use F9 or choose Edit Breakpoints from the Watch menu to display the Edit Breakpoints dialog box.

Summary: Not every line can be a breakpoint.

A breakpoint line must be a program line that represents executable code. You cannot select a blank line, a comment, or a declaration (such as a variable declaration or a segment specifier) as a breakpoint.

A breakpoint can also be set at an address. Type the address in segment:offset form in the Set Breakpoint dialog box. (Address breakpoints, unlike line breakpoints, are not saved in CodeView's status file, and therefore are not restored when you restart a debugging session.)

A breakpoint can be set to the name of a procedure if the procedure was declared with the PROC directive. If not, the procedure must contain a labeled line. Type the procedure's name or the line's label in the Set Breakpoint dialog box.

Once execution has paused, you can continue execution by clicking the F5=Go button in the display or by pressing F5. Execution continues to the next breakpoint. If there are no more breakpoints, execution continues to the end of the program, or until a fatal error occurs.

NOTE:

The Set Breakpoint dialog box contains a Commands text box. You can type Command-window commands in this box, separated by semicolons. These commands are executed when the breakpoint is reached. See the Command Window section of CodeView online help for a full description of Command-window commands.

Conditional Breakpoints

Breakpoints are not limited to specific lines of code. CodeView can also pause when a variable reaches a particular value or just changes value. This is a “conditional breakpoint.” In previous versions of CodeView, conditional breakpoints are called “watchpoints” and “tracepoints.”

You can associate a conditional breakpoint with a specific line of code, so that execution pauses at that line only if the variable has simultaneously reached a particular value or changed value. The check boxes in the Set Breakpoint dialog box select these other breakpoint types.

To pause execution when a variable reaches a particular value, type an expression that is usually false in the Expression field of the Set Breakpoint dialog box. For example, if you want to pause when the variable looptest equals 17, type looptest == 17.

To pause execution when a variable changes value, you need to type only the name of the variable in the Expression field. For large variables (such as arrays or character strings), you can specify the number of bytes you want checked (up to 32K) in the Length field. Execution pauses when any one of these values changes.

NOTE:

CodeView checks every conditional breakpoint after executing each line of source code. Unless you have enabled the use of the debug registers with the CodeView /R command-line option, this computational overhead greatly slows execution. (Execution is even slower if you are executing in Mixed mode or Assembly mode, because conditional breakpoints are checked after each machine instruction.)

For maximum speed when debugging, either associate conditional breakpoints with specific lines, or set conditional breakpoints only after you have reached the section of code that needs to be debugged. You can also use the Disable button in the Edit Breakpoints dialog box to temporarily suspend evaluation of a previously set conditional breakpoint.

Using Breakpoints

One of the most common bugs is a loop that executes too many or too few times. If you set a breakpoint on the statement that controls the loop statements, the program pauses after each iteration. With the loop variable or critical program variables in the Watch or Local windows, it should be easy to see what's going wrong in the loop.

Summary: You can specify how many times a breakpoint is reached before stopping.

You do not have to pause at a breakpoint the first time execution reaches it. CodeView lets you specify the number of times you want to ignore the breakpoint condition before pausing. Type the number in the Pass Count field of the Set Breakpoint dialog box. This feature can eliminate a lot of tedious single-stepping.

Another programming error is erroneously assigning a value to a variable that should not change. Type the variable in the Expression field of the Set Breakpoint dialog box. Execution breaks whenever this variable changes—even unintentionally.

Summary: You can assign new values to variables while execution is paused.

Breakpoints are a convenient way to pause the program so you can assign new values to variables. For example, if a limit value is set by a variable, you can change the value to see whether program execution is affected.