Skip to main content

Stepping Through a Program

You can step through an application and navigate the code. This is useful to check the status of your code at runtime. You can examine the call process, track variable values, or locate errors.

Stepping commands are provided in the Debug menu for this purpose. The commands become available when you set breakpoints in online mode and then halt execution at a breakpoint: the application is in HALT ON BP state (debug mode). During debug mode, the current break position is highlighted in yellow and marked with the symbol_step_arrow.png symbol in the text editors.

Procedure. Switching to debug mode
  1. Download your application to a controller.

    The application is highlighted in green. CODESYS and the editors of the POUs are in online mode.

    _cds_online_mode.png
  2. In the POUs, set breakpoints at the locations in the code that you want to examine.

    All breakpoints are listed in the Breakpoints view.

  3. Start the application.

    The application starts and the code is processed until the first breakpoint.

    Now the application is in debug mode. In the device tree, the application is labeled with [halt on breakpoint]. The status bar provides information about the operating state:

    _cds_debug_mode.png

    The editor was opened at the current break position. The line of code with an active breakpoint where program execution was halted is highlighted in yellow and marked by the symbol_step_arrow.png symbol. This statement highlighted in yellow has not been executed yet.

    _cds_pou_in_debug_mode.png

    Now you can select the various stepping commands or display the call tree.

Tip

Alternatively, you can first start the application and then set a breakpoint.

Behavior of the stepping command in the Debug menu

. Behavior of the stepping command in the Debug menu
  • icon_step_over.png Step Over command

    The statement at the breakpoint position is executed. Program execution halts before the next statement in the POU.

    If the statement contains a call (from a program, function block instance, function, method, or action), then the subordinate POU is processed completely in one step.

  • icon_step_into.png Step Into command

    The statement at the breakpoint position is executed. Program execution halts before the next statement.

    If the statement contains a call (from a program, function block instance, function, method, or action), then the program execution jumps to this subordinate POU. The first statement there is executed and the program execution halts before the next statement. The new current breakpoint position is then in the called POU.

  • icon_step_out.png Step Out command

    The command executes the POU from the current breakpoint position to the end of the POU and then jumps back to the calling POU. Program execution halts at the call location (in the line with the call).

    If the current breakpoint position is in the main program, then the POU is run through to the end. Then the program execution jumps back to the beginning (to the program start at the first line of code in the POU) and halts there.

  • icon_run_to_cursor.png Run to Cursor command

    First set the cursor at any line of code and then execute the command. The program is executed from the current breakpoint position and halts at the current cursor position without executing the code of this line.

  • icon_set_next_statement.png Set Next Statement command

    First set the cursor at any line of code (also before the current breakpoint position) and then execute the command. The statement marked with the cursor is executed next. All statements in between are ignored and skipped.

  • icon_show_current_statement.png Show Next Statement command

    If you do not see the current breakpoint position, then execute the command. Then the window with the current breakpoint position comes into focus and the breakpoint position is visible.

Click View → Call Stack to fully show the previous call tree for the breakpoint position currently reached in the program processing.

Tip

The Call Stack view shows the location of the block in the call structure of the program at all times, even before compiling the application.