Using Breakpoints

Breakpoints are commonly used for debugging programs. CODESYS supports breakpoints in all IEC editors.

You can set breakpoints at specific positions in the program to force an execution stop and to monitor variable values. You can set special data breakpoints to halt program execution when the value of a specific variable changes.

The halt at a breakpoint or data breakpoint can be linked to additional conditions. You can also redefine breakpoints and data breakpoints as execution points where specific code is executed instead of stopping the program.

Note

The Breakpoints view provides an overview of all defined breakpoints. It also includes additional commands for processing batch changes to multiple breakpoints.

In the editor, the following symbols identify the status of a breakpoint or execution point:

See also

Data breakpoints

Note

The function of data breakpoints depends on the target system. Currently, data breakpoints are possible only with the CODESYS Control Win V3.

Program execution stops at a data breakpoint when the value of a particular variable or memory address changes. As with ordinary breakpoints, the halt can be linked to an additional condition, or specific code can be processed instead of the halt (converted to a data execution point).

You set a data breakpoint either by means of the New Data Breakpoint command in the Debug menu or by means of the New button in the Breakpoints view. You specify a qualified variable name or a memory address directly which is to be monitored for changes in its value.

Example

In the following sample code, the memory of the variable iNumber is overwritten unintentionally. However, a data breakpoint at the variable iNumber will detect when its value changes. The processing then stops with a corresponding message at the array access, which overwrites the variable value: Idx = 7. See also below: “Setting a data breakpoint”.

PROGRAM PLC_PRG
VAR
  Idx : INT;
  Ary : ARRAY[0..3] OF BYTE;
  iNumber : INT := 55;
END_VAR
FOR idx := 0 TO 6 DO
  Ary[idx] := 0;
END_FOR

Breakpoints in applications with multiple tasks

Basically, debugging is not possible for multiple tasks at the same time. While you are working on a task with breakpoints or stepping, breakpoints are ignored in other tasks.

If a POU containing a breakpoint is used by multiple tasks, then only the debug task is halted because it reaches the breakpoint first. All other tasks continue. The Call Stack dialog shows which task is currently halted.

If you need a breakpoint to affect only one specific task, then you can define this in the breakpoint properties.

Breakpoints operate separately for each application so that a “HALT ON BP” does not affect any other applications. This applies also to parent/child applications, even if the breakpoint is set in a block that is used by several applications and whose code is located only once on the PLC.

Hint

The I/Os that are called by the debug task are not updated at a halt in the breakpoint, even if you select the Refresh I/Os in Stop check box in the PLC settings.

Note

If the application stops at a breakpoint on the PLC, then an online change or download causes all tasks to halt which means the PLC will stop. In this case, CODESYS prompts you whether or not to continue with the login.

See also

Setting a single breakpoint (example in ST editor)

Requirement: The application is in online mode and running. The operating mode is Debug.

  1. In the editor, open a POU programmed in structured text (ST).

  2. Place the cursor in the line where a breakpoint will be set.

  3. Click Debug ‣ Toggle Breakpoint or press F9.

    ⇒ The line is marked in red and identified by the “breakpoint enabled” symbol (). If the program is halted at the breakpoint, then the line is marked by the “stop at breakpoint” symbol (). The processing of the program is stopped. This is identified in the status line by the HALT ON BP status highlighted in red.

  4. Click Debug ‣ Start or press F5.

    ⇒ The program continues.

  5. Set more breakpoints and check the variable values at the break position.

  6. Place the cursor in the line where a breakpoint should be removed.

  7. Click Debug ‣ Toggle Breakpoint or press F9.

    ⇒ The marking disappears. The breakpoint is deleted.

See also

Defining a breakpoint condition (example in ST editor)

  1. In the editor, open a POU programmed in structured text (ST).

  2. Place the cursor in the line where a breakpoint will be set.

  3. Click Debug ‣ New Breakpoint .

    ⇒ The Breakpoint Properties dialog opens.

  4. Click the Condition tab.

  5. Click Break when the hit count is a multiple of in the Hit Count list box.

    Specify the value “5” in the field to the right.

  6. In addition, you can define a Boolean condition for when the breakpoint should be active. Select the Break, when true check box. Specify a Boolean variable in the text field to the right.

  7. Select the Enable breakpoint immediately check box.

  8. Close the dialog.

    ⇒ The line is marked red and identified by the “conditional breakpoint enabled” symbol ()

Monitor the running program. As long as the Boolean variable for the condition is FALSE, the breakpoint condition is not fulfilled and the program continues to run. If you set the variable to TRUE, then the condition is fulfilled and the program halts at the breakpoint every 5th pass.

See also

Defining an execution point (example in ST editor)

  1. In the editor, open a POU programmed in structured text (ST).

  2. Place the cursor at the position for an execution point.

  3. Click Debug ‣ New Breakpoint .

    ⇒ The Breakpoint Properties dialog opens.

  4. Click the Execution Point Settings tab.

  5. Select the Execution point option.

    In the Execute the following code field, type the following statement: iCounter := iCounter + 1;

    In the Print a message in the device log field, type the following text: Execution point reached {iCounter}

  6. Close the dialog.

When the program reaches the execution point, it does not halt, but executes the code defined above. In addition. a message is issued to the device log.

See also

Setting a data breakpoint

Requirement: The application is in online mode and running.

  1. Click View ‣ Breakpoints .

  2. Click Debug ‣ New Data Breakpoint .

  3. Click the button in the New breakpoint dialog (Data tab.

  4. In the Input assistant dialog (Watch Variables tab), select the variables for which the program should halt when changed.

    As an alternative, specify the qualified name of the variable on the Data tab directly in the input line. Example: PLC_PRG.iNumber. The exact number of bytes to be monitored is specified as the Size. A value that corresponds to the data type is set here automatically by default. You can also specify fewer bytes to be monitored.

  5. In the Breakpoints view, select the line with the data breakpoint and click the button.

    ⇒ The line is marked and identified by the “Data breakpoint enabled” symbol (). When the program reaches the data breakpoint (meaning when the value of the selected variables changes), the program processing halts. In the implementation part of the POU, the next line is identified by an arrow . This is identified in the status line by the HALT ON BP status highlighted in red.

  6. Click Debug ‣ Start or press F5.

    ⇒ The program continues running and halts again when the value of the variables changes again.

See also