Set Breakpoints to Debug Charts
You enable debugging for a Stateflow® chart when you set a breakpoint. A breakpoint is a point on a Stateflow chart that pauses the simulation so you can examine the status of the chart. While simulation is paused, you can view Stateflow data, interact with the MATLAB® workspace, and step through the simulation. For more information, see Debugging Stateflow Charts.
Breakpoints appear as circular red badges. For example, this chart contains breakpoints on
upshifting state and the transition from
Set a Breakpoint for a Stateflow Object
You can set breakpoints on charts, states, transitions, graphical or truth table functions, and events.
Breakpoints on Charts
To set a breakpoint on a chart, right-click inside the chart and select Set Breakpoint on Chart Entry. This type of breakpoint pauses the simulation before entering the chart.
To remove the breakpoint, right-click inside the chart and clear the Set Breakpoint on Chart Entry option.
Breakpoints on States and Transitions
You can set different types of breakpoints on states and transitions.
To set a breakpoint on a state or transition, right-click the state or
transition and select Set Breakpoint. For states, the default
On State Entry and
During State. For transitions, the default breakpoint is
When Transition is Valid. To change the type of
breakpoint, click the breakpoint badge and select a different configuration of
breakpoints. For more information, see Change Breakpoint Types.
To remove the breakpoint, right-click the state or transition and select Clear Breakpoint.
Breakpoints on Stateflow Functions
To set a breakpoint on a graphical or truth table function, right-click the function and select Set Breakpoint During Function Call. This type of breakpoint pauses the simulation before calling the function.
To remove the breakpoint, right-click the function and clear the Set Breakpoint During Function Call option.
Breakpoints on Events
You can select two types of breakpoints on events:
Start of Broadcast— Pause the simulation before broadcasting the event.
End of Broadcast— Pause the simulation after a Stateflow object reads the event.
Available breakpoints depend on the scope of the event.
|Scope of Event||Start of Broadcast||End of Broadcast|
|Not available||Not available|
To set or clear breakpoints on an event, use the Property Inspector or the Model Explorer to modify the Debugger Breakpoints properties. For more information, see Debugger Breakpoints.
Change Breakpoint Types
A breakpoint badge can represent more than one type of breakpoint. To see a tooltip that
lists the breakpoint types that are set on a Stateflow object, point to its badge. In this example, the badge on the state
upshifting represents two breakpoint types:
To change the type of breakpoint on an object, click the breakpoint badge. In the Breakpoints dialog box, you can select a different configuration of breakpoints, depending on the object type.
Clearing all of the check boxes in the Breakpoints dialog box removes the breakpoint.
Add Breakpoint Conditions
To limit the number of times that the simulation stops at a breakpoint, add a condition to the breakpoint. By default, a Stateflow chart pauses whenever it reaches a breakpoint. When you add a condition to a breakpoint, the chart pauses at the breakpoint only when the condition is true.
To add a condition to a breakpoint:
On the Debug tab, click Breakpoints List to open the Stateflow Breakpoints and Watch window. Alternatively, you can open the Breakpoints and Watch window by clicking the Breakpoints List link in the Breakpoints dialog box.
Select the Breakpoints tab. The Breakpoints tab lists all of the breakpoints in the chart. For more information, see Manage Breakpoints Through the Breakpoints and Watch Window.
Under the Condition column, enter a condition for the breakpoint. You can use any valid MATLAB expression that combines numerical values and Stateflow data objects that are in scope at the breakpoint.
You cannot use message data in a breakpoint condition expression.
For example, this chart has a breakpoint on the transition from
upshifting. This breakpoint stops
the simulation every time that the transition is tested, even if the value of
speed is far below
To inspect the chart before the transition is taken, you want the breakpoint to pause
the simulation only when the value of
speed is approaching the value of
up_th. When you set the condition
speed > up_th-2
on the breakpoint, the simulation pauses only when the value of
within 2 of the value of
When the simulation pauses, you can inspect the values of the variables
up_th and step through the simulation. For
more information, see Inspect and Modify Data and Messages While Debugging and Control Chart Execution After a Breakpoint.
Manage Breakpoints Through the Breakpoints and Watch Window
You can manage all of the breakpoints in the chart in the Stateflow Breakpoints and Watch window. To open the Breakpoints and Watch window, on the Debug tab, click Breakpoints List. Alternatively, open the Breakpoints dialog box and click the Breakpoints List link.
To see a list of all of the breakpoints and their associated conditions, select the Breakpoints tab.
To inspect data and message values, select the Watch tab. For more information, see View Data in the Breakpoints and Watch Window.
Disable and Reenable Breakpoints
To disable a breakpoint without deleting its associated condition, clear the check box
next to the breakpoint name. For example, in this chart, the breakpoint on the
During State breakpoint for the
state is disabled.
If you disable all the breakpoints for a graphical object, its breakpoint badge changes color from red to gray. If there is at least one breakpoint enabled for an object, the breakpoint badge remains red.
To reenable a breakpoint, select the box next to the breakpoint name. To disable or reenable all breakpoints, clear or select the check box at the top of the window.
To remove a breakpoint from the chart, point to the name of the breakpoint and click the Remove this breakpoint icon that appears to the right of the name. When you remove a breakpoint, you also delete its associated condition.
View Breakpoint Hits
The Hits column displays the number of times that the simulation has paused on each breakpoint. When you change the condition for a breakpoint, the chart resets the number of hits.
Save and Restore Breakpoints
Breakpoints persist during a MATLAB session. When you close a model, its breakpoints remain in the Breakpoints and Watch window. If you reopen a model during the same MATLAB session, all of the breakpoints and their associated conditions are restored.
You can save the breakpoint and watch data lists and reload them in a later MATLAB session. To save a snapshot of the breakpoint and watch data lists, at the top of the Breakpoints and Watch Window, click the Save current breakpoints and watches icon. To restore a snapshot, click the Load breakpoints and watches icon.