|
Application Programming: Debugging and Error-Handling |
|
When a file displayed in an IDL editor window has been compiled (by selecting Compile or Memory Compile from the Run menu, or by entering .COMPILE, .COMPILE -f, or .RUN at the IDL command prompt), a number of debugging commands become available for selection. You can suspend execution of a program temporarily by setting breakpoints in the code. To use the test file, broken.pro to test breakpoints, enter the following lines at the command line:
.EDIT broken
Edit the first program line to read as follows and then save and compile the program:
PRO BROKEN, i
This allows you to pass a value for i to the program. Set a breakpoint at the fifth line of broken.pro by placing the cursor in the line that reads:
PRINT, i*2
and selecting Set Breakpoint from the Run menu. A breakpoint dot appears next to the line. Now enter the following to execute the program:
BROKEN, 10
The Output Log window displays the following:
10 % Breakpoint at: BROKEN 5
and a current line indicator arrow marks line 5. Select Run to resume execution. To list the breakpoints, enter HELP,/BREAKPOINT at the command line.
Setting a breakpoint allows you to inspect (or change) variable definitions as the program executes. Since our example does not set any variables, setting a breakpoint in broken.pro is not very informative. Breakpoints can be extremely helpful, though, when debugging complex programs, or programs that call other routines. For more information on working with breakpoints, see the following section.
You can select to edit, enable/disable, and change breakpoint properties using Breakpoint Toolbar buttons. Additionally, through the Edit Breakpoints dialog, breakpoints can be set for execution dependent upon a condition or enabled after the breakpoint has been encountered a specific number of times.
There are three buttons in the main menu bar. These are:

The Toggle Breakpoint button creates or deletes a breakpoint. Create a breakpoint at the line where your cursor is positioned by clicking the Toggle Breakpoint button. If a breakpoint already exists in the line where your cursor is positioned, clicking this button removes the breakpoint.

The Enable/Disable Breakpoint button enables or disables a breakpoint. If a breakpoint is enabled, a filled circle appears next to the line in the IDL Editor window. If disabled, the circle is not filled. Disabled breakpoints are ignored when you run the file.

The Edit Breakpoints button displays the Edit Breakpoints dialog. In previous releases, this printed a listing of the current breakpoints. From this dialog, you can list your current breakpoints, create new breakpoints, enable or disable breakpoints, change breakpoint options, or delete breakpoints.
The Edit Breakpoints dialog allows you to add, remove, and remove all breakpoints in a file as well as the ability to move to the line in the source file that contains the breakpoint. The following figure shows the Edit Breakpoints dialog:
To create a breakpoint using the Edit Breakpoints dialog, complete the following steps:
button in the IDLDE toolbar or by selecting Run
Edit Breakpoints...
When you run your program, execution halts at the breakpoints you have specified.
IDL Online Help (March 06, 2007)