Please note : This help page is not for the latest version of Enterprise Architect. The latest help can be found here.
Debugging Execution of Executable State Machines
Creation of Executable State Machines provides benefits even after the generation of code. By 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 State Machines, demonstrated by the simulation and ultimately incorporated in a real world system.
Debugging a State Machine
Being able to debug an Executable State Machine gives additional benefits. These benefits allow you to:
- Interrupt the execution of the simulation and all executing State Machines.
- View the raw state of each State Machine 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 State Machine 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 State Machine using the Simulation Control. Depending on the nature of the behavior being debugged, 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 wish 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 state machines 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: < > = >= <=. eg: (this.m_nCount > 100) and (this.m_ntype == 1)
To add a condition to a breakpoint you have set, right-click the breakpoint and select properties. By clicking the breakpoint while holding the CTRL key, 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 an effect for example. 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 / prove the sequence of events and the order in which instances change state.
Viewing the callstack
Whenever a breakpoint is encountered, the callstack is available. This is available from the Analyzer Menu. Use this to determine the order in which the execution is taking place.
Learn More