Debugging: What's actually happening in my program?

Now that you know the basics, go through the Advanced LabVIEW tutorials to see what else you can do with LabVIEW. Let's start with "debugging".

LabVIEW comes with some very nice debugging tools that help you figure out what in the world your program is doing. One of the best tools allows you to highlight the execution of the program. It animates circles flowing along the wires, simulating dataflow, and displays the values of the wires at all the input and output terminals along the execution of program. It executes a bit slower, which allows you to follow the execution of the program. In this lesson, I'll teach you how to use this program to aid in debugging various applications.

Let's take the Monthly Loan Calculator from the LabVIEW Basics course 5, and open it in LabVIEW. We'll run it with it working and trace the execution of the program. Turning on execution highlighting is a very simple task. Simply click the light bulb icon next to the Stop and Pause buttons. It looks like what is shown below.

Execution Highlighting 1

You can then click it again to turn off execution highlighting. The light bulb will be shining yellow when the highlighting is enabled and grey when highlighting is turned off. Go ahead and run the program by clicking the Run arrow to test out execution highlighting. Here's an example of what you should see during the execution of the program.

Execution Highlighting 2

Let's now break the program and see if we can use this tool to fix it! Here's a screenshot of the broken program, and a link to the VI for the file.

Execution Highlighting 3

Now some of you can probably figure this out by just comparing it with the program given in the previous course, but let's say we're working with a much larger and more complex program, and the only copy of the program you have is broken? What are you going to do then? Well, the most efficient way to find the issue is to break the program down into small chunks, and use execution highlighting to identify the bug. You can then compare the values that are in the program to what you think should be there.

In this program, you can compare the output of the different parts of the program to what you expect from the equivalent parts of the equation, simply by reverse engineering the program. For example, the first part of the program where the Interest Rate is divided by 1200 corresponds to the Interest Rate / 1200 in the equation. Simple enough.

To find this bug:

  1. Compare the output of the Interest Rate / 1200, multiplied by the 1 + (Interest Rate / 1200) to the Months power with the output of that same section of the program.
  2. Also compare this section of the program to the equation.

Notice the difference? Looks like the multiplication was turned into division! This concludes this lesson on debugging, using execution highlighting. I do highly recommend that you try this out on some of the programs that you have already written! Enjoy!

So far, we've introduced simply watching the values run through your program, but what if you want to actually pause to analyze the values more carefully? Well, no need to worry! LabVIEW has you covered! There are two key components here to help you out:

Breakpoints are basically like stopping points that you can place into your program, and stepping is the action of going between breakpoints, or going between different sections/pieces of your program. So without further introduction, let's get to programming!

Let's open up the loan calculator, so click "File" then "Open", and browse to the location where you saved the VI. Once you have it open, run it with some default values to verify that it is working correctly by itself. Once you've run it successfully, go to the block diagram by pressing Ctrl - E or by clicking "Show Block Diagram" under "Window" in the menu. Let's turn on execution highlighting before we go any further by clicking the light bulb icon in the toolbar. Now, lets start stepping through the program. If you also wanted the program to stop at a certain point, right click the node or SubVI, go to "Breakpoint", and click "Set Breakpoint". Now, run the program and watch it stop on that node or SubVI. You can then click the "Pause" button to continue the execution.

Stepping 2

Now, lets say you want to through the program sequentially? This can be done through stepping. To start stepping, click the button with the arrow going over the box.

Stepping 1

You should now be able to step through the program. This can be an immense help when debugging, as you can pause on each Node or SubVI of the program to look at the values of the wires at that point in the programs execution.