This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

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.

You can execute a standalone chart in the MATLAB Command Window or through the Stateflow editor. To enable debugging, set a breakpoint in the standalone chart or in a MATLAB script that executes the chart. Breakpoints interrupt the execution of a chart. While execution is stopped, 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 Stateflow editor at least once can produce unexpected results.

For information on debugging Stateflow charts in Simulink models, see Debugging Charts.

Set and Clear Breakpoints

You can set breakpoints on charts, states, and transitions.

  • To add a breakpoint on a chart, right-click inside the chart and select Set Breakpoint on Chart Entry. This type of breakpoint interrupts the execution before the chart is entered. To remove the breakpoint, right-click inside the chart and clear the Set Breakpoint on Chart Entry option.

  • To add a breakpoint on a state, right-click the state and select Set Breakpoint. This type of breakpoint interrupts the execution before the chart performs the entry and during actions for the state. To remove the breakpoint, right-click the state and select Clear Breakpoint.

  • To add a breakpoint on a transition, right-click the transition and select Set Breakpoint. This type of breakpoint interrupts the execution when the transition becomes valid. To remove the breakpoint, right-click the transition and select Clear Breakpoint.

Breakpoints appear as circular red badges. For example, this chart contains breakpoints on the state A and on the transition from A to B.

To remove all of the breakpoints in a chart, right-click inside the chart and select Clear All Breakpoints In Chart.

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 window 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.

BadgeDescription

Execution stopped before entering a chart or state.

Execution stopped in a state during action.

Execution stopped after exiting a state.

Execution stopped before taking a valid transition.

You can continue the execution from the Stateflow editor, at the debugging prompt, or by selecting a keyboard shortcut.

Toolbar IconOptionCommandDescriptionKeyboard Shortcut

Continuedbcont

Continue execution to the next breakpoint.

Ctrl+T

Step Overdbstep

Advance to the next step in the chart execution. At the chart level, possible steps include:

  • Enter the chart

  • Execute a transition action

  • Activate a state

  • Execute a state action

For more information, see Execution of a Stateflow Chart.

F10

Step Indbstep in

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.)

F11

Step Outdbstep out

From a function call, return to the statement calling the function.

Otherwise, continue execution to the next breakpoint. (See the Continue option.)

Shift+F11

Stop dbquit

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.

Ctrl+Shift+T

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.

Examine and Change Values of Chart Data

When Stateflow is in debug mode, the Symbols window 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 window, you can change the value of a data object during execution. Alternatively, at the debugging prompt, enter the new value by using the name this in place of the chart object name. For instance, to change the value of the local data x, enter:

this.x = 7
The new value appears in the Symbols window.

Related Topics