Debugging Execution of Executable StateMachines
Creation of Executable StateMachines provides benefits even after the generation of code. Using the Execution Analyzer, Enterprise Architect is able to connect to the generated code. As a result you are able to visually debug and verify the correct behavior of the code; the exact same code generated from your StateMachines, demonstrated by the simulation and ultimately incorporated in a real world system.
Debugging a StateMachine
Being able to debug an Executable StateMachine gives additional benefits, such as being able to:
- Interrupt the execution of the simulation and all executing StateMachines
- View the raw state of each StateMachine instance involved in the simulation
- View the source code and Call Stack at any point in time
- Trace additional information about the execution state through the placement of tracepoints on lines of source code
- Control the execution through use of actionpoints and breakpoints (break on error, for example)
- Diagnose changes in behavior, due to either code or modeling changes
If you have generated, built and run an Executable StateMachine successfully, you can debug it! The Analyzer Script created during the generation process is already configured to provide debugging. To start debugging, simply start running the Executable StateMachine using the Simulation Control. Depending on the nature of the behavior being debugged, however, we would probably set some breakpoints first.
Breaking execution at a state transition
Like any debugger we can use breakpoints to examine the executing StateMachine at a point in code. Locate a Class of interest in either the diagram or Project Browser and press to view the source code. It is easy to locate the code for State transitions from the naming conventions used during generation. If you want to break at a particular transition, locate the transition function in the editor and place a breakpoint marker by clicking in the left margin at a line within the function. When you run the Executable StateMachine, the debugger will halt at this transition and you will be able to view the raw state of variables for any StateMachines involved.
Breaking execution conditionally
Each breakpoint can take a condition and a trace statement. When the breakpoint is encountered and the condition evaluates to True the execution will halt. Otherwise the execution will continue as normal. You compose the condition using the names of the raw variables and comparing them using the standard equality operands: < > = >= <=. For example:
(this.m_nCount > 100) and (this.m_ntype == 1)
To add a condition to a breakpoint you have set, right-click on the breakpoint and select 'Properties'. By clicking on the breakpoint while pressing the , the properties can be quickly edited.
Tracing auxillary information
It is possible to trace information from within the StateMachine itself using the TRACE clause in, for example, an effect. Debugging also provides trace features known as Tracepoints. These are simply breakpoints that, instead of breaking, print trace statements when they are encountered. The output is displayed in the Simulation Control window. They can be used as a diagnostic aid to show and prove the sequence of events and the order in which instances change state.
Viewing the Call Stack
Whenever a breakpoint is encountered, the Call Stack is available from the Analyzer menu. Use this to determine the sequence in which the execution is taking place.