LabWindows/CVI is a complete ANSI C programming environment, with all of the flexible debugging and development tools available in general-purpose C programming environments you may have used in the past. In this tutorial, you will see some of the powerful debugging tools available in LabWindows/CVI. Experienced C programmers will recognize many of these utilities as standard C development and debugging tools. Novice programmers will discover powerful new tools for development and debugging.
You will be using the sample program developed in the tutorial section of this demonstration to review the debugging tools in LabWindows/CVI.
To review the program you need to debug, click on the Acquire Data button to acquire and display a waveform on the graph.
!
BEGIN_TEXT
!
LabWindows/CVI Debugging Tools
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
0
0
0
0
0
3
3
0
3
0
-1
DEBUG.AVI
0
2
4395
3375
5835
1950
0
0
0
0
BEGIN_TEXT
You will notice that we have added a channel input on the GUI. With this control, you interactively select which input channel to acquire and display on the graph.
Select channel two and click on the Acquire Data button.
!
BEGIN_TEXT
!
Acquiring from Channel 2
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
0
0
0
0
0
3
3
0
3
0
-1
DEBUG.AVI
0
6
4395
3375
6135
2220
0
0
0
0
BEGIN_TEXT
In this example, you use the LabWindows/CVI debugging tools to step through the source code of this application in a mock debugging exercise. Assume that an error occurs when you try to acquire and display the data on channel two.
Click on the Quit button to end program execution and view the source code.
!
BEGIN_TEXT
!
Viewing the Source Code
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
0
0
0
0
0
3
3
0
3
0
-1
DEBUG.AVI
0
8
4095
2220
7155
3075
0
0
0
0
BEGIN_TEXT
Based on the error information that you see, the bug must be somewhere within the AcquireData function. The AcquireData function deletes all traces on the graph, calls the scope_read_waveform function in the instrument driver to acquire a new waveform, and then plots the new waveform on the graph control.
Start your debugging exercise by placing a breakpoint on the line containing the scope_read_waveform function. You do this by left-clicking with your mouse in the left-hand column of the source window (where the arrow is pointing).
Add a breakpoint now, by clicking in the left-hand column.
!
BEGIN_TEXT
!
Adding a Breakpoint
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
ARR_L1R.BMP
ARR_L1_.BMP
222
20
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
0
0
0
0
0
3
3
0
3
0
-1
DEBUG.AVI
0
10
4305
2310
7200
2835
0
0
0
0
BEGIN_TEXT
The red diamond symbolizes a breakpoint is now located where you clicked, on line 23.
LabWindows/CVI breakpoints are conditional; you can apply specific conditions to a breakpoint to control its execution. In this example, you are only concerned with breaking program execution when the channel input is set to channel two.
Right-click on the breakpoint symbol to see a dialog box where you can set its conditions.
!
BEGIN_TEXT
!
Editing a Breakpoint
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
0
0
0
0
0
3
3
0
3
0
-1
DEBUG.AVI
0
11
2115
1710
5085
1725
0
0
0
0
BEGIN_TEXT
The Breakpoints display shows a list of all breakpoints in your project.
Click on the Add/Edit Item button to edit the breakpoint.
!
BEGIN_TEXT
!
Editing a Breakpoint
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
0
0
0
0
0
3
3
0
3
0
-1
DEBUG.AVI
0
13
5055
765
7155
1830
0
0
0
0
BEGIN_TEXT
From this screen, you can set pass counts or conditions for your breakpoints. In this example, we set the condition for this breakpoint so that program execution breaks only when the channel parameter is equal to 2.
Click on the arrow button to add this condition to the dialog box.
!
BEGIN_TEXT
!
Conditional Breakpoints
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
-1
0
0
0
0
3
3
-1
3
0
0
DEBUG.AVI
0
14
5055
765
6720
1305
0
0
0
0
BEGIN_TEXT
Click on the Replace button to add this condition to the existing breakpoint.
!
BEGIN_TEXT
!
Conditional Breakpoints
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
0
0
0
0
0
3
3
0
3
0
-1
DEBUG.AVI
0
16
3255
3645
4155
1185
0
0
0
0
BEGIN_TEXT
Click on the OK button to continue.
!
BEGIN_TEXT
!
Conditional Breakpoints
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
0
0
0
0
0
3
3
0
3
0
-1
DEBUG.AVI
0
18
4275
1200
6345
2040
0
0
0
0
BEGIN_TEXT
The breakpoint is now depicted by a yellow box, indicating that it is a conditional breakpoint. Run the program to see how the breakpoint operates.
Click on the Run Project icon in the toolbar to compile and run the program.
!
BEGIN_TEXT
!
Running the Program
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
ARR_U1G.BMP
ARR_U1_.BMP
68
254
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
0
0
0
0
0
3
3
0
3
0
-1
DEBUG.AVI
0
20
4335
1290
6840
2040
0
0
0
0
BEGIN_TEXT
Your program will now break execution only when the Acquire Data button is pressed and the Scope Channel is set to channel 2. To test this operation, try acquiring and displaying data from channel 1 first.
Click on the Acquire Data button to acquire and display the waveform from channel 1.
!
BEGIN_TEXT
!
Running the Program
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
0
0
0
0
0
3
3
0
3
0
-1
DEBUG.AVI
0
22
4320
1380
5415
1710
0
0
0
0
BEGIN_TEXT
Now set the Scope Channel indicator to channel 2 and click on the Acquire Data button. The program should break execution.
!
BEGIN_TEXT
!
Running the Program
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
0
0
0
0
0
3
3
0
3
0
-1
DEBUG.AVI
0
26
4125
645
5535
1590
0
0
0
0
BEGIN_TEXT
To quickly view the value of the channel parameter, double-click on the "channel" variable in the scope_read_waveform function call.
!
BEGIN_TEXT
!
View the Variable Value
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
0
0
0
0
0
3
3
0
3
0
-1
DEBUG.AVI
0
28
4305
3495
5535
1590
0
0
0
0
BEGIN_TEXT
Click on the View Variable Value icon in the toolbar to view the Variable Display with the channel variable highlighted.
!
BEGIN_TEXT
!
View the Variable Value
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
0
0
0
0
0
3
3
0
3
0
-1
DEBUG.AVI
0
30
3960
315
5730
1830
0
0
0
0
BEGIN_TEXT
As you can see, the Variable display shows all of the current variable values, organized between local variables within particular functions and global program variables.
Click on the arrow to continue.
!
BEGIN_TEXT
!
The Variable Display
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
0
0
0
0
0
3
3
-1
3
0
0
DEBUG.AVI
0
32
3960
315
6255
2205
0
0
0
0
BEGIN_TEXT
LabWindows/CVI has a built-in utility to automatically view the declaration of a variable. If you ever forget what the data type or scope of a particular variable is, you can highlight it and select Find Identifier Definition to view its declaration.
Click on the Find Identifier Definition icon in the toolbar to view the declaration of the highlighted channel variable.
!
BEGIN_TEXT
!
View Variable Declaration
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
ARR_U1M.BMP
ARR_U1_.BMP
88
106
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
0
0
0
0
0
3
3
0
3
0
-1
DEBUG.AVI
0
34
3960
315
6105
1605
0
0
0
0
BEGIN_TEXT
As you can see, the channel variable is an integer initialized to a value of 1.
Click on the arrow to continue.
!
BEGIN_TEXT
!
View Variable Declaration
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
0
0
0
0
0
3
3
-1
3
0
0
DEBUG.AVI
0
38
2490
720
6360
1845
0
0
0
0
BEGIN_TEXT
You can also use the Find Identifier Definition utility to automatically view the definition of a highlighted function call.
Click on the View Identifier Definition icon to view the definition of the scope_read_waveform function.
!
BEGIN_TEXT
!
View Function Definition
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
ARR_R1M.BMP
ARR_R1_.BMP
30
52
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
0
0
0
0
0
3
3
0
3
0
-1
DEBUG.AVI
0
40
4740
120
7890
2400
0
0
0
0
BEGIN_TEXT
The source code to the scope_read_waveform function automatically displays in a new source window. This function is located in the simulated oscilloscope instrument driver. Here you see a key benefit of having source code access to your instrument drivers: you can single-step into the instrument driver code to debug, optimize, or enhance your drivers directly from within LabWindows/CVI.
To step into the scope_read_waveform function, click on the Step Into icon in the toolbar.
!
BEGIN_TEXT
!
Stepping through Source Code
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
ARR_R1G.BMP
ARR_R1_.BMP
101
314
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
0
0
0
0
0
3
3
0
3
0
-1
DEBUG.AVI
0
42
1995
2610
6855
2820
0
0
0
0
BEGIN_TEXT
Now you can see that the first line of the scope_read_waveform function is outlined in red, indicating that program execution has temporarily stopped at this line. In many debugging instances, it is not practical to single-step through each line of your source code. In this example, the first few lines of the function are simple initializations. Using the LabWindows/CVI Go To Cursor feature, you can move the input cursor to a certain point in your source code and force program execution to continue until the cursor is reached.
Click on the arrow to place the cursor past the first few lines of this function.
!
BEGIN_TEXT
!
Go To Cursor
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
0
0
0
0
0
3
3
0
3
0
-1
DEBUG.AVI
0
45
1995
2610
6915
1665
0
0
0
0
BEGIN_TEXT
Click on the Go To Cursor icon to execute the source code up until the line where you left the cursor.
!
BEGIN_TEXT
!
Go To Cursor
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
0
0
0
0
0
3
3
0
3
0
-1
DEBUG.AVI
0
47
1995
2610
6915
1665
0
0
0
0
BEGIN_TEXT
Program execution is now halted at the scope_invalid_integer_range function.
Click on the Step Into icon to step into the source code for this particular function.
!
BEGIN_TEXT
!
Go To Cursor
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
ARR_U1B.BMP
ARR_U1_.BMP
64
328
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
0
0
0
0
0
3
3
0
3
0
-1
DEBUG.AVI
0
49
4320
2355
6870
2580
0
0
0
0
BEGIN_TEXT
With the stepping capabilities of LabWindows/CVI, you have stepped down through three successive function calls. When you get into these situations, you can use the Up and Down Call Stack utilities to find the area from which you have called a particular function. In this example, you can use the Up Call Stack to highlight the function from which the scope_invalid_integer function has been called.
Click on the Up Call Stack icon to see which function in your source code has called the scope_invalid_integer_range function.
!
BEGIN_TEXT
!
Up/Down Call Stack
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
0
0
0
0
0
3
3
0
3
0
-1
DEBUG.AVI
0
51
4320
2355
6930
1935
0
0
0
0
BEGIN_TEXT
As you can see, the scope_read_waveform function has been highlighted again.
Click on the Up Call Stack icon again to view the function that has called the scope_read_waveform function.
!
BEGIN_TEXT
!
Up/Down Call Stack
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
0
0
0
0
0
3
3
0
3
0
-1
DEBUG.AVI
0
53
4320
2355
6930
1935
0
0
0
0
BEGIN_TEXT
Now we have returned all the way to the AcquireData function. You can easily go to the deepest function in your call stack by using the Down Call Stack icon.
Click on the arrow to jump back down the call stack to the scope_invalid_integer_range function.
!
BEGIN_TEXT
!
Up/Down Call Stack
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
0
0
0
0
0
3
3
-1
3
0
0
DEBUG.AVI
0
57
4320
2355
6345
2265
0
0
0
0
BEGIN_TEXT
At any time when you are stepping through a function, you can use the Finish Function utility to execute the remainder of the function source code and return to where it was called.
Click on the Finish Function icon to execute through the scope_invalid_integer_range and return to the scope_read_waveform function.
!
BEGIN_TEXT
!
Finish Function
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
ARR_U1G.BMP
ARR_U1_.BMP
65
372
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
0
0
0
0
0
3
3
0
3
0
-1
DEBUG.AVI
0
59
4320
2355
6495
1815
0
0
0
0
BEGIN_TEXT
LabWindows/CVI also has a Watch window for viewing variable or expression values during program execution without breaking.
Double-click on the "sou" variable to highlight it.
!
BEGIN_TEXT
!
Watch Window
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
0
0
0
0
0
3
3
0
3
0
-1
DEBUG.AVI
0
61
1575
2625
6165
1560
0
0
0
0
BEGIN_TEXT
Click on the View Expression Value to add the sou variable to the Watch Window.
!
BEGIN_TEXT
!
Watch Window
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
0
0
0
0
0
3
3
0
3
0
-1
DEBUG.AVI
0
63
4185
360
6375
1830
0
0
0
0
BEGIN_TEXT
The Watch Window will display the value of the sou variable during program execution. You can resize and place the Watch Window anywhere on your screen.
Click on the arrow to hide the Watch Window.
!
BEGIN_TEXT
!
Watch Window
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
0
0
0
0
0
3
3
-1
3
0
0
DEBUG.AVI
0
66
1560
1200
6615
1395
0
0
0
0
BEGIN_TEXT
Now click on the Go To Cursor icon again to execute the source code down to line 132.
!
BEGIN_TEXT
!
Watch Window
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
0
0
0
0
0
3
3
0
3
0
-1
DEBUG.AVI
0
68
1560
1200
7275
1950
0
0
0
0
BEGIN_TEXT
You can highlight a string variable and view its value using the View Variable Value utility at any time.
Click on the arrow to view the value of the cmd string in the scope_write_data function call.
!
BEGIN_TEXT
!
Watch Window
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
0
0
0
0
0
3
3
-1
3
0
0
DEBUG.AVI
0
71
3900
540
7545
1710
0
0
0
0
BEGIN_TEXT
From the String Display, you can view the value of string variables in a number of different formats.
Pull down on the Format menu to view the different formats available.
!
BEGIN_TEXT
!
Watch Window
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
0
0
0
0
0
3
3
0
3
0
-1
DEBUG.AVI
0
72
3900
540
7545
1710
0
0
0
0
BEGIN_TEXT
A flexible string display can help you develop advanced instrument control applications.
Click on the arrow to continue.
!
BEGIN_TEXT
!
Watch Window
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
0
0
0
0
0
3
3
-1
3
0
0
DEBUG.AVI
0
75
5070
225
7335
1905
0
0
0
0
BEGIN_TEXT
The arrow symbols in the left-hand column of the Variable Display indicate that these variables are arrays. You can view the individual elements in an array variable by clicking on the arrow next to it.
Click on the arrow symbol next to the wvfm variable to view its individual elements.
!
BEGIN_TEXT
!
The Array Display
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
0
0
0
0
0
3
3
0
3
0
-1
DEBUG.AVI
0
77
975
1005
7155
1425
0
0
0
0
BEGIN_TEXT
Pull down on the View menu and select Array Display to view the wvfm array in the specialized Array Display.
!
BEGIN_TEXT
!
The Array Display
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
0
0
0
0
0
3
3
0
3
0
-1
DEBUG.AVI
0
81
4140
210
7305
1590
0
0
0
0
BEGIN_TEXT
Like the String Display for character strings, the Array Display has a number of formats in which you can view the array element values.
Pull down on the Format menu to view these formats.
!
BEGIN_TEXT
!
The Array Display
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
0
0
0
0
0
3
3
0
3
0
-1
DEBUG.AVI
0
83
4140
210
3930
1275
0
0
0
0
BEGIN_TEXT
Click on the arrow to continue.
!
BEGIN_TEXT
!
The Array Display
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
0
0
0
0
0
3
3
0
3
0
-1
DEBUG.AVI
0
87
1845
1590
4635
2685
0
0
0
0
BEGIN_TEXT
You have seen just a few of the powerful debugging features of LabWindows/CVI in this short tutorial. The toolbar lets you interactively step through source code and view variables.