Previous Application Programming: Debugging and Error-Handling Next

Working with Breakpoints

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.

Using Breakpoints

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.

The Breakpoint Toolbar Buttons

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 Windows Edit Breakpoints Dialog

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:

Figure 8-1: Edit Breakpoints Dialog

Figure 8-1: Edit Breakpoints Dialog

To create a breakpoint using the Edit Breakpoints dialog, complete the following steps:

  1. Open the file you in which you want to set a breakpoint.
  2.  

  3. Display the Edit Breakpoints dialog by clicking the button in the IDLDE toolbar or by selecting Run Edit Breakpoints...
  4.  

  5. Place the cursor in the line in which you want to create the breakpoint in the Editor window.
  6.  

  7. Select Add in the Edit Breakpoints dialog box. You will see a new entry display in the dialog. The following table describes each property of a breakpoint:
  8.  

    Table 8-1: Edit Breakpoints Dialog Fields

    Table 8-1: Edit Breakpoints Dialog Fields
    Item
    Description
    E/D
    Specifies whether a breakpoint is enabled or disabled. If a check mark is displayed, the breakpoint is enabled and execution will stop when the all criteria for the breakpoint is met.
    Module
    Specifies the procedure or function where the breakpoint is set.
    Note - This item will not be displayed until the file has been compiled with the new breakpoint.
    Line
    Specifies the line number where the breakpoint occurs.
    File
    Specifies the filename where the breakpoint occurs.
    After
    Specifies how many times the execution must pass the breakpoint before stopping execution. For example, if this item is set to 0, execution will stop the first time this breakpoint is encountered. If it is set to 9, execution will not stop until the breakpoint has been encountered for the ninth time.
    Once
    The breakpoint is removed after it is encountered for the first time.
    Condition
    Specifies a condition to be met for the execution to stop. The condition is a string containing an IDL expression. When a breakpoint is encountered, the expression is evaluated. If the expression is true (if it returns a non-zero value), program execution is interrupted. The expression is evaluated in the context of the program containing the breakpoint.

     

  9. At this point, you can modify any of the items (except Module and Line) by double-clicking in the entry.

When you run your program, execution halts at the breakpoints you have specified.

  IDL Online Help (March 06, 2007)