The debugger can be invoked either by selecting the menu function Debug and Trace Analysis of the Compile Menu or by pressing the F7 key.
The SCRAMBLECODE debugger looks and works very much like an ordinary debugger. It can debug the source code line by line, set breakpoints, run to breakpoint, run to cursor, step in, step over, step out, present the call stack, trace values etc.
Figure shows a debug session in progress. The left panel presents the project and source files. The right panel displays the source code currently being debugged (with the next statement painted in yellow), and the call stack entries present the path of function calls leading up to the current point.
The debugger however has no direct real-time connection to the VM DLL that executes the bytecode, due to these Security Considerations.
Instead the debugger imports a file containing trace events generated by the VM during the execution of the bytecode. The debugger uses these recorded trace events to emulate the execution by processing the events sequentially to visualize what is happening.
Figure shows the events currently being executed. Events for code are written in black, and values are written in red. Please notice how event 40906 (the yellow line) is ready to be debugged as the next event corresponding to the yellow statement in the previous picture.
We often refer to this emulation as an execution, because the debugger makes it easy to follow the execution of the code step by step as an ordinary debugging session.
It is easy to generate the necessary trace events for the debugger. The bytecode can automatically produce trace events during VM execution. It just requires that trace instructions are included in the compiled bytecode, which is easily switched on/off in the project properties. Trace events can also be generated manually by inserting certain trace functions in the source code. It is even possible to switch tracing on/off while executing the bytecode to produce trace results which are focused at specific hot spots in the code.
The details of Trace Management are described later.