
7.3 How do I |
|
7.3.1 Starting the Debugger |
To start debuggingging 1. Click Start debugging on the Build menu. 2. Click Go, Step Into, or Run to Cursor |
7.3.2 Running to a Location |
To run until a breakpoint is reached 1. Set a breakpoint. 2. On the Build menu, click Start debugging. 3. From the Start debugging menu, choose Go. To run to the cursor (while the debugger is not running) 1. In a source file, move the insertion point to the location where you want the debugger to break. 2. From the Build menu, select Start debugging and Run To Cursor. To run to the cursor (while the debugger is running but halted) 1. In a source file, move the insertion point to the location where you want the debugger to break. 2. From the Debug menu, choose Run To Cursor. To set the next statement to execute (while the debugger is running but halted) 1. In a source window, move the insertion point to the statement or instruction that you want to execute next. 2. Click the right mouse button. 3. On the shortcut menu, click Set Next Statement. |
7.3.3 Halting a Program |
To halt debugging Click Break on the Debug menu. Control returns to Editor |
7.3.4 Setting Breakpoints |
Use the Breakpoints dialog box (accessed by the Breakpoints command on the Edit menu), to set, remove, disable, enable, or view breakpoints. The breakpoints you set will be saved as a part of your project. Note You must have a project open before you can set a breakpoint. With no project open, the Breakpoints command does not appear on the Edit menu. You can set breakpoints on a source-code line To set a breakpoint at a source-code line 1. In a source window, move the insertion point to the line where you want the program to break. 2. Choose the Insert/Remove Breakpoint toolbar button. A red dot appears in the left margin, indicating that the breakpoint is set. Note If you want to set a breakpoint on a source statement extending across two or more lines, you must set the breakpoint on the last line of the statement. |
7.3.5 Viewing and Enabling Breakpoints |
To view the list of current breakpoints 1. On the Edit menu, click Breakpoints. 2. Use the scroll bar to move up or down the Breakpoints list.
To disable a breakpoint 1. For a location breakpoint in a source code window٬move the insertion point to the line containing the breakpoint you want to disable. 2. Click the Enable/Disable Breakpoint toolbar button, or click the right mouse button, and choose Disable Breakpoint from the shortcut menu. -or- 3. For any breakpoint in the Breakpoints dialog box, find the breakpoint in the Breakpoints list. 4. Clear the check box corresponding to the breakpoint that you want to disable. 5. Click OK. For a location breakpoint, the red dot in the left margin changes to a hollow circle.
To enable a breakpoint 1. For a location breakpoint, in a source code window, move the insertion point to the line containing the breakpoint you want to enable. 2. Click the Enable/Disable Breakpoint toolbar button, or click the right mouse button, and choose Enable Breakpoint from the shortcut menu. -or- 3. In the Breakpoints dialog box, find the breakpoint in the Breakpoints list. 4. Select the empty check box corresponding to the breakpoint that you want to enable. 5. Click OK. For a location breakpoint, the hollow circle in the left margin changes to a red dot. Tip You can also use the SPACEBAR to toggle the state of one or more breakpoints in the Breakpoints list.
To remove a breakpoint 1. For a location breakpoint in a source window, , move the insertion point to the line containing the breakpoint you want to remove. 2. Click the Insert/Remove Breakpoint toolbar button, or click the right mouse button, and choose Remove Breakpoint from the shortcut menu. -or- 3. In the Breakpoints dialog box, select one or more breakpoints in the Breakpoints list. 4. Click the Remove button, or press the DELETE key. 5. Click OK. For a location breakpoint, the red dot in the left margin disappears.
To view the source code where a breakpoint is set 1. In the Breakpoints list, select a location breakpoint. 2. Click the Edit Code button This action takes you to the source code for a breakpoint set at a line number or function name. In the case of function names, the debugger must be running for this to work. |
7.3.6 Stepping Into Functions |
To run the program and execute the next statement (Step Into) 1. While the program is paused in break mode (program is waiting for user input after completing a debugging command), click Step Into from the Debug menu. The debugger executes the next statement, then pauses execution in break mode. If the next statement is a function call, the debugger steps into that function, then pauses execution at the beginning of the function. 2. Repeat step 1 to continue executing the program one statement at a time. If you
step into a nested function call, the debugger steps into the most deeply nested
function. For example, on the line of code |
7.3.7 Stepping Over or Out of Functions |
To step over a function 1. Open a source file, and start debuggingging. 2. Execute the program to a function call. 3. On the Debug menu, click Step Over. The debugger executes the next function, but pauses after the function returns. 4. Repeat step 3 to continue executing the program, one statement at a time. To step out of a function 1. Start debuggingging, and execute the program to some point inside the function. 2. On the Debug menu, click Step Out. The debugger continues until it has completed execution of the return from the function, then pauses. Caution In general, to avoid very slow execution, you should not step out of a function containing a loop. Instead, you should set a breakpoint at the end of the function, and then choose Go from the Debug menu to execute to the end of the function. Then choose Step Out. |
7.3.8 Viewing the Value of a Variable |
To view the value of a variable 1. Wait for the debugger to stop at a breakpoint. -or- Click Break on the Debug menu to halt the debugger. 2. On the Debug menu, click QuickWatch. 3. Type or paste the variable name or an expression into the Expression text box, and click Recalculate. 4. Click Close. Tip The Expression drop-down list box contains the most recently used QuickWatch expressions.
To view the value of a variable using QuickWatch 1. When the debugger is stopped at a breakpoint, switch to a source window, and click the right mouse button on a variable (Var, for example). 2. On the shortcut menu, click QuickWatch Var. 3. Click Close.
To view the value of a variable or expression in the Watch window 1. Start debuggingging, and pause the debugger in break mode (program is waiting for user input after completing a debugging command). 2. On the View menu, click Debug Windows, then click Watch. 3. Select a tab for the variable or expression. 4. Type, paste, or drag the variable or register name or an expression into the Name column on the tab. Press ENTER (if typing). The Watch window evaluates the variable or expression immediately and displays the value or an error message. If you add an array or object variable to the Watch window, plus sign (+) or minus sign (¨C) boxes appear in the Name column. Use these boxes to expand or collapse your view. |
7.3.9 Modifying the Value of a Variable |
When the program is paused at a breakpoint or between steps, you can change the value of any non-const variable . To modify the value of a variable using QuickWatch 1. On the Debug menu, click QuickWatch. 2. In the Expression text box, type the variable or register name. 3. Click the Recalculate button. 4. If the variable is an array or object, use the + box to expand the view until you see the value you want to modify. 5. Use the TAB key to move to the value you want to modify. 6. Type the new value, and then press ENTER. 7. Click Close. Tip To change the value of an array, modify the individual fields or elements. You cannot edit an entire array at once.
To modify the value of a variable or contents using the Watch window 1. In the Watch window, double-click the value. -or- Use the TAB key to move the insertion point to the value you want to modify. 2. If the variable is an array or object, use the + box to expand the view until you see the value you want to modify. 3. Type the new value, and press ENTER. |
