Debugging a flow control script

Describes breakpoint management, call stack display, variable object examination, and stepping.

You are now going to learn how to debug a script. The debug features in the IDE are breakpoint management, call stack display, variable object examination, and stepping.

A simple debugging scenario is to place a breakpoint in a script, execute the script by means of the Debug button Debug button, examine the call stack, and then interactively execute statements using the Step Over button.

This section covers the successive debugging steps:

Adding a breakpoint to a flow control script

Still using the Solve models sequence by changing data run configuration of the mulprod model, you are going to add a breakpoint to set the debugging mode, then execute the script again, using this time the Debug button.

  1. If it is not already open, double-click the mulprod_main.mod file in the editing area and scroll down to this line just before the loop:
    
    var curr = Infinity;
    
  2. Right-click in the grey margin next to this line. From the popup menu, select Toggle Breakpoint and a blue dot appears in the margin of the editing area to signal the breakpoint.
    Note:

    To remove a breakpoint, right-click and select again Toggle Breakpoint to make the blue dot disappear.

    You can also double-click in the grey margin to set and remove breakpoints.

    Figure 1. Inserting a breakpoint
    Inserting a breakpoint before debugging
  3. In the main toolbar, click the arrow on the Debug button Debug icon in the toolbar and select 1 mulprod Solve models sequence by changing data to run the script.

    Execution stops at the breakpoint and a blue arrow in the margin shows the current position, as shown in the following screen capture.

    Figure 2. A breakpoint before the loop of the script (mulprod_main.mod)
    Inserting a breakpoint

Examining the flow control call stack

The call stack is now spread over two views: the Debug view, representing the call stack (showing nested function calls) and the Variables view, showing the content of the selected call frame.

  1. The call stack appears in the Debug view. Each function called has information in a stack frame. In this example, there is one frame, [mulprod_main.mod:58].

    Click the + and sign as necessary to expand or collapse nodes.

    Figure 3. The call stack in the Debug view (mulprod_main.mod)
    Call stack
  2. The Variables view shows the content of the selected call frame. In this example, there is only one call frame.
    variables view for the example mulprod_main

    Many of the variables in this example are marked undefined because they are not decision variables.

Stepping to the next instruction

When you execute a run configuration in debugging mode, the Debug view is displayed to enable you to use the stepping buttons in its toolbar.

Figure 4. Debug toolbar
The Execution toolbar

The Step Over button Step Over button allows you to step through the script instruction by instruction, executing each instruction as you go. Use it to step over:

  • a function and go to the statement after the function call

  • an instruction and go to the instruction after it

When you are stepping in a script, the blue arrow in the margin keeps track of the current position.

To step to the next instruction:

  1. Click the Step Over button Step Over button.

    The IDE executes the current instruction and the blue arrow in the margin moves to the next line, which is the statement for warm start:

    
    var basis = new IloOplCplexBasis();
    

    as shown in the following screen capture.

    Figure 5. Step by step execution of a script
    Stepping through a script
  2. By repeatedly clicking the Step Over button, you can follow the execution of the loop one instruction after another.

    Note that the Step Into button Step Into button would give the same behavior as Step Over in this script because there are no functions, so it just executes the current instruction.

Continuing without stepping

At any moment while you are stepping in the script, you can ask the IDE to continue executing until completion by clicking the Resume button Resume button in the toolbar of the Debug view.

The IDE executes the rest of the script without stopping at instructions. The possible outputs of the script are printed in the Scripting log.

Aborting execution

At any moment while you are stepping in the script, you can abort execution.

  1. Click the Abort the current solve button About current solve button in the execution toolbar of the main window. (You can also click the Terminate button in the toolbar of the Debug view.)

    The Debug view shows that the status of the execution is 'terminated'.

    Figure 6. Aborting the execution of a script in debugging mode
    Aborting execution of a script
  2. After aborting, you can relaunch the script by clicking the Debug button.

Ending execution

To summarize, while stepping through a script, you can end execution in one of three ways:

  1. Click the Continue the current solve button Continue button: the IDE completes the script.
  2. Click the Abort the current solve button Abort Execution button: the script terminates without being completed.
  3. Click the Step Over button Step Over button (or Step Into button Step Into button, if there are no functions) repeatedly; the IDE completes the script, instruction by instruction.

The output of execution is displayed in the Scripting log.

Output in Scripting log for the mulprod example. Run config: Solve models sequence by changing data