Introduction to Breakpoints and Watch Expressions
You can pause the execution of a program without aborting it altogether by marking breakpoints in code. You can use these breakpoints to interrupt program execution for debugging. Breakpoints can be either conditional or unconditional. Breakpoints apply to specific lines of code, but LabWindows/CVI maintains them separately from the source file. If you modify the source code outside of the LabWindows/CVI environment, you might invalidate breakpoint position information. If you set a breakpoint on a line that contains no executable code, LabWindows/CVI moves the breakpoint to the next line that contains executable code. LabWindows/CVI disables the breakpoint if there is no executable code beyond the line containing the breakpoint.
You also can use watch expressions for debugging. With watch expressions, you can specify that LabWindows/CVI suspend execution conditionally without regard to a specific line of code.
![]() |
Notes
|
Breakpoint State
When a program reaches a breakpoint, LabWindows/CVI positions the keyboard cursor at the next program statement to execute and outlines the statement. You can continue to edit the source code for the suspended project while the breakpoint is in effect. You also can open other windows, change the state of breakpoints, and modify the value of variables in the Variables and Call Stack and Array Display windows. If you are at a breakpoint in a Source window, you can execute code in the Interactive Execution window or in a function panel.
![]() |
Note Although you can edit source code while you suspend program execution, those changes do not take effect immediately, even if you save the file. You must terminate execution and rebuild the project to see your changes. |
To resume program execution after a breakpoint, you have several options under the Run menu. You can restart the project at a breakpoint by selecting Debug. To halt the execution of a program at a breakpoint, select Terminate Execution while a LabWindows/CVI environment window is active.
Setting and Using Breakpoints
You can set, disable, edit, and clear breakpoints in the following ways.
- You can set breakpoints directly in source code using the Breakpoint function.
- If you select View»Line Icons, click the line icon area next to a line of code to set or clear a breakpoint on that line.
- Move the cursor to the line of code where you want to set or clear a breakpoint and select Run»Toggle Breakpoint.
- Move the cursor to the line of code where you want to disable a breakpoint and select Run»Disable Breakpoint.
- Move the cursor to the line of code where you want to edit a breakpoint and select Run»Edit Breakpoint.
- Select Run»Breakpoints to edit all breakpoints in the workspace and the Interactive Execution window. You also can use the Breakpoints command to set conditional breakpoints.
- Select Run»Break On»First Statement to break on the first executable statement in the project or the Interactive Execution window.
- You can manually suspend execution while the program runs if the program checks for user input. For example, if the program makes calls to RunUserInterface or scanf, pressing <Ctrl-F12>, if you have default shortcut keys enabled, while a LabWindows/CVI environment window is active causes a breakpoint state.
You also can use the context menu of the Source window to complete many of the previous tasks.
Conditional Breakpoints
Create conditional breakpoints in the Edit Breakpoint dialog box. When you assign a conditional breakpoint to a line in a program, LabWindows/CVI evaluates an expression you supply, such as x==100 or y<0, before executing the line. If the expression is true, program execution suspends.
![]() |
Note If you assigned these expressions to line 23 in a program, make sure that you define x and y before line 23. |
Watch Expressions
You can use watch expressions to suspend program execution conditionally. Watch expressions do not apply to specific lines of code. Instead, LabWindows/CVI evaluates them before each statement in source code.