| Stateflow User's Guide |
 |
Using the Debug Tool During Simulation
In Simulating a Stateflow Diagram, Stateflow highlights executing transitions and active states. You can enhance normal Stateflow simulation with the Stateflow Debugging tool. This tool lets you step through individual Stateflow actions that are not identified to you in normal simulation. By identifying all Stateflow diagram actions, the Debugging tool gives you insight into Stateflow behavior, and helps eliminate any doubts you may have about how your Stateflow diagrams work.
The following steps show you how to step through a simulation of the Controller Stateflow diagram using the Stateflow Debugging tool:
- In the Stateflow diagram editor, from the Tools menu, select Debug.
- The Stateflow Debugging window appears as shown.

- Select the Chart Entry breakpoint.
- This pauses execution when the diagram is entered after it is triggered by an event from the Manual Switch.
- Position the Stateflow Debugging window so that you can see it, the Simulink model window, and the Controller Stateflow diagram window at the same time.
- In the Stateflow Debugging window, click Start to start the simulation.
- When simulation begins, the Start button is relabeled to a Continue button and both the Continue and Step buttons are disabled. This means that the Controller diagram is inactive (asleep) and waiting for an event.
Simulation running.... This message appears in the top pane of the Debugging window. It indicates that the simulation is running, but there are no events to process. The Controller diagram is active, but asleep.
|

|
- In the Simulink window, double-click the Manual Switch block to send an event to the Controller diagram.
- The Debugging window now displays information in its top pane with the following labels:
- Stopped -- What is being processed in the current step.
- Executing -- The Stateflow diagram executing. In this example, this will always be Controller.
- Current Event -- The current event being processed. In this example, this will always be the event
event.
- Simulink Time -- The simulation time of the model.
For now, pay attention only to the Stopped message. This message indicates what is taking place in the current simulation step. It is included with the examples that follow.
Stopped: Entry: Chart Controller Indicates that this step is taking place while the Controller diagram is active and ready to respond to events.
|

|
- In the Stateflow Debugging window, click Step to advance simulation by a step.
Stopped: After activation of Transition ? The Controller diagram is processing its default transition. The Debugging window refers to the identity of the current transition by its label. Because the Default Transition has no label, its label is referred to with a question mark character (?).
|

|
- Click Step to advance simulation by a step.
Stopped: Just after activation of State Off. State Off is entered and is now active.
|

|
- Click Step to advance simulation by a step.
Stopped: After broadcast of Input event event. All response activity to the event event is finished. The event has been consumed.
|

|
- Click Step to advance simulation by a step.
Simulation running.... The Controller diagram is active but asleep. In this phase, it is waiting for an event to wake it and be processed. The Continue and Step buttons are disabled until another event occurs.
|

|
- In the Simulink model, continue indefinitely to double-click the Manual Switch block to send another event to the Controller diagram and advance simulation to the next active state with the Step button.
- When you are finished debugging, in the Debugging window, click Stop Simulation to stop the simulation.
- Once the simulation stops, the model becomes editable.
- In the Debugging window, click Close to close it.
The Stateflow Debugging window is an important tool for studying Stateflow semantics, the description of the behavior of Stateflow objects in Stateflow diagrams. Even though the Stateflow Debugging window is not used throughout the remainder of this guide, you are encouraged to use it whenever you want to clarify Stateflow semantics in your models.
| Simulating a Stateflow Diagram | | Guarding Transitions with Event Triggers |  |
© 1994-2005 The MathWorks, Inc.