debug a standalone stateflow chart
a standalone stateflow® chart is a matlab® class that defines the behavior of a finite state machine. standalone charts implement classic chart semantics with matlab as the action language. you can program the chart by using the full functionality of matlab, including those functions that are restricted for code generation in simulink®. for more information, see create stateflow charts for execution as matlab objects.
to enable debugging, set a breakpoint in the standalone chart or in a matlab script that executes the chart. breakpoints pause the execution of a chart. while the execution is paused, you can step through each action in the chart, view data values, and interact with the matlab workspace to examine the state of the chart.
note
when debugging a standalone chart that you execute from a matlab script, first open the stateflow editor. attempting to debug a standalone chart before opening the editor at least once can produce unexpected results.
for information on debugging stateflow charts in simulink models, see set breakpoints to debug charts.
set and clear breakpoints
breakpoints appear as circular red badges. for example, this chart contains
breakpoints on the state a
and on the transition from
a
to b
.
you can set breakpoints on charts, states, and transitions.
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 execution 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.
object | breakpoint type |
---|---|
state |
|
| |
| |
transition |
|
|
to set a breakpoint on a state or transition, right-click the
state or transition and select set breakpoint. for
states, the default breakpoints are 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 manage breakpoint types and conditions.
to remove the breakpoint, right-click the state or transition and select clear breakpoint. to remove all of the breakpoints in a chart, right-click inside the chart and select clear all breakpoints in chart.
manage breakpoint types and conditions
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 state or transition, point
to its badge. in this example, the badge on the state a
represents two breakpoint types: on state entry
and
during state
.
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.
to limit the number of times that the execution 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. for example, with these conditions, the breakpoints on state
a
pause the execution of the chart only when the value of
x
is negative.
to specify 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.
control chart execution after a breakpoint
when execution stops at a breakpoint, stateflow enters debugging mode.
the matlab command prompt changes to
k>>
.the symbols pane displays the value of each data object in the chart.
the chart highlights active elements in blue and the currently executing object in green.
for example, when the execution stops at the breakpoint in state
a
, the border of the state and the first statement in the
state entry
action appear highlighted in green.
an execution status badge appears in the graphical object where execution pauses.
badge | description |
---|---|
| execution is paused before entering a chart or in a
state |
| execution is paused in a state
|
| execution is paused in a state |
| execution is paused before testing a transition. |
| execution is paused before taking a valid transition. |
when the chart is paused at a breakpoint, you can continue the execution by using:
buttons in the debug tab
the matlab command window
keyboard shortcuts
action | debug tab button | matlab command | keyboard shortcut | description |
---|---|---|---|---|
continue |
| dbcont | ctrl t | continue execution to the next breakpoint. |
step over |
| dbstep | f10 | advance to the next step in the chart execution. at the chart level, possible steps include:
for more information, see execution of a stateflow chart. |
step in |
| dbstep in | f11 | from a state or transition action that calls a function, advance to the first executable statement in the function. from a statement in a function containing another function call, advance to the first executable statement in the second function. otherwise, advance to the next step in the chart execution. (see the step over option.) |
step out |
| dbstep out | shift f11 | from a function call, return to the statement calling the function. otherwise, continue execution to the next breakpoint. (see the continue option.) |
stop |
| dbquit | ctrl shift t | exit debug mode and interrupt the execution. when you execute the standalone chart from the stateflow editor, this action removes the chart object from the matlab workspace. |
in state or transition actions containing more than one statement, you can step through the individual statements one at a time by selecting step over. the stateflow editor highlights each statement before executing it.
note
because standalone charts define temporal logic in terms of wall-clock time, a temporal logic operator can become valid while a chart is paused at a breakpoint. in this case, the chart exits debugging mode and the execution continues to the next breakpoint.
examine and change values of chart data
when stateflow is in debug mode, the symbols pane displays the value of each data object in the chart. you can also examine data values by pointing to a state or a transition in the chart. a tooltip displays the value of each data object used in the selected state or transition.
to test the behavior of your chart, in the symbols pane, you
can change the value of a data object during execution. alternatively, at the
debugging prompt, enter the new value by using the keyword in place of the chart object name. for instance,
to change the value of the local data x
,
enter:
this.x = 7
note
when debugging a chart in a simulink model, do not use the keyword this
. instead,
you can access all stateflow data directly at the debugging prompt. for more information, see
.