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.
Tip
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:
: The breakpoint is enabled.
: The breakpoint is disabled.
: The breakpoint is set in another instance of the POU open in the editor.
: The program halts at the breakpoint.
: The breakpoint with condition is enabled.
: The breakpoint with condition is disabled.
: The execution point is enabled.
: The execution point is disabled.
: The execution point with condition is enabled.
: The execution point with condition is disabled.
: The data breakpoint is enabled.
: The data breakpoint is disabled.
: The program halts at the data breakpoint.
: The data execution point is enabled.
: The data execution point is disabled.
: The program halts at the data execution point.
: The data execution point with condition is enabled.
: The data breakpoint with condition is enabled.
For more information, see: Breakpoints
Data breakpoints
Tip
The function of the data breakpoints depends on the target system. Currently, data breakpoints are possible only with the CODESYS Control Win.
Program execution stops at a data breakpoint when the value of a particular variable or memory address changes. As with "normal" 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.
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 task ("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.
Important
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.
Tip
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.
Setting a single breakpoint (example in ST editor)
Requirement: The application is in online mode and running. The operating mode is Debug.
In the editor, open a POU programmed in structured text (ST).
Place the cursor in the line where a breakpoint will be set.
Click F9 key.
or press theThe line is marked in red and identified by the
symbol (breakpoint enabled). If the program is halted at the breakpoint, then the line is marked by the
symbol (halt at breakpoint). The processing of the program is stopped. This is identified in the status line by the
HALT ON BP
status highlighted in red.Click F5 key.
or press theThe program continues.
Set more breakpoints and check the variable values at the break position.
Place the cursor in the line where a breakpoint should be removed.
Click F9 key.
or press theThe marking disappears. The breakpoint is deleted.
Defining a breakpoint condition (example in ST editor)
In the editor, open a POU programmed in structured text (ST).
Place the cursor in the line where a breakpoint will be set.
Click
.The New Breakpoint dialog opens.
Click the Condition tab.
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.
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.
Select the Enable breakpoint immediately check box.
Close the dialog.
The line is marked red and identified by the
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.
Defining an execution point (example in ST editor)
In the editor, open a POU programmed in structured text (ST).
Place the cursor at the position for an execution point.
Click
.The New Breakpoint dialog opens.
Click the Execution Point Settings tab.
Select the Execution point option.
In the Execute the following code field, specify the following statement:
iCounter := iCounter + 1;
In the Print a message in the device log field, specify the following text:
Execution point reached {iCounter}
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.
Setting a data breakpoint
Requirement: The application is in online mode and running.
Click
.Click
.In the New breakpoint dialog, on the Data tab, click the
button.
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.In the Breakpoints view, select the line with the data breakpoint and click the
button.
The line is marked and identified by the
symbol (data breakpoint enabled). 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.Click F5 key.
or press theThe program continues running and halts again when the value of the variables changes again.