Breakpoints and Debugging
The IDL Workbench provides robust tools for finding and correcting problems in your code.
Breakpoints
To set a breakpoint, place the cursor on the line where you want the breakpoint to appear and press Ctrl-Shift-B or select Run → Toggle breakpoint. A blue dot appears in the left-hand margin of the editor window.

You can also toggle breakpoints on and off by double-clicking in the left-hand margin next to the line of code on which you want IDL to pause.
Debug Perspective
The IDL Workbench makes a distinction between editing and debugging code, and provides the ability to switch automatically to the Debug perspective when an error or breakpoint is encountered. The Debug perspective is a collection of the views most useful for debugging and analyzing code.
See Using the Debug Perspective for details.
Viewing Variable Values
When you run a routine that contains a breakpoint, IDL will halt execution when it reaches the breakpoint. When execution is halted, you can inspect the variable values in the current execution scope using the Variables view or by hovering the mouse pointer over a variable in the editor.
Stepping Through Code
When execution is halted due to a breakpoint or an error, you can execute single statements using the Step commands on the Run menu. See Stepping Through Code for details.
Debugging a Short Program
Let's walk through the process of debugging a short program. In this example, we'll create a program, set a breakpoint, inspect variable values, and step through the code.
- To create a new
.profile, click the
icon or select File → New → IDL Source File. - Enter the following text into the editor window:
- To save your new
.profile, click the
icon or select File → Save. - Select "Default" as the parent folder and click OK, accepting the default filename (
tinyroutine.pro). - To execute the program, click the
icon, press F8, or select Run → Run tinyroutine. - Click OK on the dialog to clear it.
- Position the cursor on the words
PRINT, myStringin the editor window. - Press Ctrl-Shift-B or select Run → Toggle breakpoint. A blue dot appears in the left-hand margin of the editor window.

- Run the
tinyroutineprogram again (press F8, click the
icon, or select Run → Run tinyroutine). - Click Yes to display the IDL Debug perspective.
- Press F6, click the
icon (on the toolbar in the Debug view), or select Run → Step Over. - When you have stepped to the end of
tinyroutine(you will see the text "% Stepped to: $MAIN$" in the Console view), click the IDL icon on the Perspective toolbar to return to the IDL perspective.

A new editor window appears.
PRO tinyRoutine ; Create a string variable myString = 'This is a tiny IDL routine' PRINT, mystring ; Create some other variables myNumber = 4 myResult = STRING(myNumber * !PI) ; Display the myResult variable void = DIALOG_MESSAGE('Result: '+myResult) END
The program prints a string to the Console view, displays a dialog, and ends. If you wanted to temporarily stop execution of your routine somewhere in the middle, you would set a breakpoint.
You can also toggle breakpoints on and off by double-clicking in the left-hand margin next to the line of code on which you want IDL to pause.
If this is the first time you have run a program with a breakpoint (or an error), you will see the Confirm Perspective Switch dialog.
The IDL Workbench interface is rearranged to add several new views at the top of the screen: Debug, Variables, and Breakpoints.
Notice that the Variables view contains entries for the four variables defined in the tinyroutine routine, but that only the MYSTRING variable is defined. It is also instructive to examine the contents of the Debug and Console views when IDL stops at a breakpoint.
Note how the Debug, Console, Variables, and Editor views adjust as you repeatedly step through your code.
For additional information on debugging, see Debugging IDL Code.