Set Breakpoints to Debug Charts

You enable debugging for a chart when you set a breakpoint. A breakpoint indicates a point at which Stateflow® halts execution of a chart that you are simulating. While simulation is halted, you can view Stateflow data and interact with the MATLAB® workspace to examine the status of the chart.

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

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

ObjectBreakpoint Type
State

On State Entry — Stop simulation before performing the state entry actions.

During State — Stop simulation before performing the state during actions.

On State Exit — Stop simulation after performing the state exit actions.

Transition

When Transition is Valid — Stop simulation after the transition tests valid, but before taking the transition.

When Transition is Tested — Stop simulation before testing whether the transition is a valid path. If no condition exists on the transition, this breakpoint type is not available.

To set a breakpoint on a state or transition, right-click the state or transition and select Set Breakpoint. For states, the default breakpoint is 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 stops 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 — Stop simulation before broadcasting the event.

  • End of Broadcast — Stop simulation after a Stateflow object reads the event.

Available breakpoints depend on the scope of the event.

Scope of EventStart of BroadcastEnd of Broadcast
LocalAvailableAvailable
InputAvailableNot available
OutputNot availableNot available

To set or clear breakpoints for an event, modify the Debugger Breakpoints properties through the Property Inspector or the Model Explorer. For more information, see Set Properties for an Event.

Change Breakpoint Types

Breakpoints appear as circular red badges. A breakpoint badge can represent more than one type of breakpoint. To see a tooltip listing the breakpoint types set for a Stateflow object, point to its badge. For example, the badge on the state On represents two breakpoint types: On State Entry and During State.

To change the type of breakpoint for 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.

Clicking the Manage breakpoints link opens the Stateflow Breakpoints and Watch window. In this window, you can manage conditions for all breakpoints. For each breakpoint, you can:

  • Set conditions.

  • Enable the breakpoint.

  • Disable the breakpoint.

  • Clear the breakpoint.

  • View the number of times a breakpoint has been encountered during simulation.

For more information, see Manage Stateflow Breakpoints and Watch Data.

Control Chart Execution After a Breakpoint

When simulation stops at a breakpoint, Stateflow enters debugging mode.

  • The MATLAB command prompt changes to debug>>.

  • 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, this chart contains a breakpoint on entry in the HIGH state, a substate of On. When simulation stops at the breakpoint, the active state (On) appears highlighted in blue and the currently executing substate (HIGH) appears 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, graphical function, or truth table function.

Execution stopped after exiting a state.

Execution stopped before testing a transition.

Execution stopped before taking a valid transition.

To see execution status, point to the badge. A tooltip indicates:

  • Where the execution stopped

  • Simulation time

  • Current event (in the presence of a local or input event)

To view data values in the chart, point to a chart object. A tooltip displays:

  • The value of each data and message that the selected object uses

  • Temporal information (in the presence of a temporal logic operator)

For more information, see Watch Data in the Stateflow Chart.

After simulation stops at a breakpoint, you can continue chart execution from the Stateflow Editor toolbar, at the MATLAB command prompt, or by selecting a keyboard shortcut.

Toolbar IconOptionCommandDescriptionKeyboard Shortcut

Continuedbcont

Continue simulation 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

  • Test a transition

  • 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 Step Over.)

F11

Step Outdbstep out

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

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

Shift+F11

Step Forward  

Exit debug mode and pause simulation before next time step.

 

Stop dbquit

Exit debug mode and stop simulation.

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. Stateflow highlights each statement before executing it. To execute a group of statements together, right-click the last statement in the group and select Run To Cursor.

Related Topics