Set Breakpoints in Simulink Debugger
The debugger allows you to define stopping points called breakpoints in a simulation.
You can then run a simulation from breakpoint to breakpoint, using the debugger
continue command. The debugger lets you define two types of
breakpoints: unconditional and conditional. An unconditional breakpoint occurs whenever a
simulation reaches a method that you specified previously. A conditional breakpoint occurs
when a condition that you specified in advance arises in the simulation.
Breakpoints are useful when you know that a problem occurs at a certain point in your
program or when a certain condition occurs. By defining an appropriate breakpoint and
running the simulation via the
continue command, 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 in the debugger, 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 (command-line mode only)
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 either the Break on conditions controls group on the debugger Breakpoints pane
or the following commands (in command-line mode) to set conditional breakpoints.
|This command...||Causes the Simulation to Stop...|
At a simulation time step
At a recoverable error in the model
At the occurrence of an underflow or overflow (
When the simulation reaches the state that determines the simulation step size
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 (GUI mode) or enter the time using the
tbreak command. This causes the debugger to stop the simulation at
Outputs.Major method of the model at the first time step that
follows the specified time. For example, starting
vdp in debug mode and
entering the commands
tbreak 2 continue
causes the debugger to halt the simulation at the
method of time step
2.078 as indicated by the output of the
%----------------------------------------------------------------% [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 pinpointing computational errors in a
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.
- Start the Simulink Debugger
- Start a Simulation
- Display Information About the Simulation
- Display Information About the Model
- Run Accelerator Mode with the Simulink Debugger