Set Breakpoints in Simulink Debugger
The Simulink® debugger allows you to define stopping points called
breakpoints in a simulation. You can then run a simulation from
breakpoint to breakpoint, using the
continue function. You can define
unconditional and conditional breakpoints. An unconditional breakpoint pauses simulation when
the simulation reaches a specified method. A conditional breakpoint pauses simulation when the
specified condition arises in the simulation. For example, you can specify a conditional
breakpoint to pause the simulation when a signal has a certain value.
Breakpoints are useful when you know that a problem occurs at a certain point in your
model or when a certain condition occurs. By defining an appropriate breakpoint and running
the simulation using the
continue function, you can skip immediately to
the point in the simulation where the problem occurs.
When you stop a simulation at a breakpoint of a MATLAB® S-function, to exit MATLAB, you must first quit the debugger.
Setting Unconditional Breakpoints
You can set unconditional breakpoints from these locations:
Simulation Loop pane
MATLAB Command Window
Setting Breakpoints from the Simulink Toolstrip
To add a breakpoint, enable the Breakpoint button.
Simulate the model.
Click the Step over current method button until
Click the Step into current method button.
The debugger displays the name of the selected block in the Break/Display points panel of the Breakpoints pane.
Clicking Breakpoint on the toolbar sets breakpoints on the invocations of the methods of the block in major time steps.
You can temporarily disable the breakpoints on a block by deselecting the check box in the breakpoints column of the panel. To clear the breakpoints on a block and remove its entry from the panel,
Select the entry.
Click the Remove selected point button.
You cannot set a breakpoint on a virtual block. A virtual block is purely graphical:
it indicates a grouping or relationship among the computational blocks of a model. The
debugger warns you if you try to set a breakpoint on a virtual block. You can get a
listing of nonvirtual blocks of a model by using the
(see Displaying a Model's Nonvirtual Blocks).
Setting Breakpoints from the Simulation Loop Pane
To set a breakpoint at a particular invocation of a method displayed in the Simulation Loop pane, select the check box next to the method name of the method in the breakpoint column.
To clear the breakpoint, clear the check box.
Setting Breakpoints from the Command Window
Setting Conditional Breakpoints
You can use the Break on conditions controls group on the debugger Break Points pane.
Use these functions to set conditional breakpoints.
Pauses simulation at specified simulation time step
Pauses simulation at a recoverable error in the model
Pauses simulation at the occurrence of an underflow or overflow
Pauses simulation when the simulation reaches the state that determines the simulation step size
Pauses simulation when a zero crossing occurs between simulation time steps
Setting Breakpoints at Time Steps
To set a breakpoint at a time step, enter a time in the debugger Break at time field or enter the time using the
function. The debugger stops the simulation at the
of the model at the first time step that follows the specified time. For example, starting
vdp in debug mode and entering these commands causes the debugger to
pause the simulation at the
vdp.Outputs.Major method of time step
tbreak 2 continue
%----------------------------------------------------------------% [Tm = 2.034340153847549 ] vdp.Outputs.Minor (sldebug @37):
Breaking on Nonfinite Values
Selecting the debugger NaN values option or entering
nanbreak command causes the simulation to stop when a computed
value is infinite or outside the range of values that is supported by the machine running
the simulation. This option is useful for locating computational errors in a model.
Breaking on Step-Size Limiting Steps
Selecting the Step size limited by state option or
xbreak command causes the debugger to stop the simulation
when the model uses a variable-step solver and the solver encounters a state that limits
the size of the steps that it can take. This command is useful in debugging models that
appear to require an excessive number of simulation time steps to solve.
Breaking at Zero Crossings
Selecting the Zero crossings option or entering the
zcbreak command causes the simulation to halt when a nonsampled zero
crossing is detected in a model that includes blocks where zero crossings can arise. After
halting, the ID, type, and name of the block in which the zero crossing was detected is
displayed. The block ID (
s:b:p) consists of a system index
s, block index
b, and port index
p separated by colons (see Block ID).
For example, setting a zero-crossing break at the start of execution of the
zeroxing example model,
>> sldebug zeroxing %-------------------------------------------------------------- % [TM = 0 ] zeroxing.Simulate (sldebug @0): >> zcbreak Break at zero crossing events : enabled
and continuing the simulation
(sldebug @0): >> continue
results in a zero-crossing break at
Interrupting model execution before running mdlOutputs at the left post of (major time step just before) zero crossing event detected at the following location: 6[-0] 0:5:2 Saturate 'zeroxing/Saturation' %----------------------------------------------------------------% [TzL= 0.3435011087932808 ] zeroxing.Outputs.Major (sldebug @16): >>
If a model does not include blocks capable of producing nonsampled zero crossings, the command prints a message advising you of this fact.
Breaking on Solver Errors
Selecting the debugger Solver Errors option or entering the
ebreak command causes the simulation to
stop if the solver detects a recoverable error in the model. If you do not set or disable
this breakpoint, the solver recovers from the error and proceeds with the simulation
without notifying you.