|
Debug Support
The State Tracking
The StateTree can highlight the application state transitions while a program is running. Meanwhile the StateWizard directs the state tracking log data to the output window in VC and a text file whose name is defined by the macro SME_DEF_DBGLOG_FILE. More than one object can be derived from a state machine. Only the state transitions of one object derived from a state machine can be highlighted in the StateTree at a time. SME_HIGHLIGHT_OBJECT(root,object) is used to highlight a specified object's state transitions.

Figure: The State Tracking

Figure: State Tracking Data Log to VS2005

Figure: State Tracking Data Log to VC6
State Machine Engine Debug Support
State machine engine provides some tools to help developer to debug program, including
- Print debug string;
- Detect dynamic memory leaks error (failing to free allocations after they are no longer needed);
- Detect dynamic memory overwrite error (overwriting the end of an allocated buffer);
- Detect dynamic memory de-allocating more than once or an unknown memory de-allocating;
- Hook dynamic memory operation . Hook function is called every time when a memory block is pre-allocated, post-allocated, pre-freed or post-freed. This type of hook can be used for many different purposes. Use it to test how an application handles insufficient memory situations, to examine allocation patterns, or to log allocation information for later analysis.
Note: If _DEBUG is not defined, the above tools are removed.
State Machine Engine takes the following measures to detect errors:
- Developers are allowed to install a user-defined debug string output function. In default, debug strings are output to the Macro tab of the Visual C++ output window.
- Engine allocates the additional 4 bytes data, named no mans land, on the side of the user data. Fill these 4 bytes with known value SME_NO_MANS_LAND (0xFD). When this block is freed or engine is to exit, engine verifies the no mans land to detect whether the boundary of the user's memory block has been overwritten.
- Engine maintains an allocated memory block list. If developers try to free a block that does not exist in this list, Engine will raise an error.
- Engine also fills new memory blocks with a known value SME_NEW_MEM_BLK (0xCD). If a developer uses these un-initialized data as a memory address, Windows memory manager will trigger an exception.
|