Home
Categories
Dictionary
Download
Project Details
Changes Log
FAQ
License

Debugging scripts



The framework allows to debug scripts. Note that for the moment, only Groovy scripts can be used in the debugger.

Overview


The debugging does not use the Java Platform Debugger Architecture. It works by inserting "shadow" step instructions in the script source code before creating a debug session, allowing to execute the debugging session in the context of the calling program, and even if the scripting language does not support "standard" debugging.

When the code execution steps through and instruction, the control flow is passed to the Debug session which will decide if:
  • The execution must continue through the next instruction
  • The execution must pause at the step. The values of the variables at this step can be retrieved in the debug session
It is possible to set a breakpoint at any step line, in which case the execution flow will pause, if the breakpoint conditions are met.

Starting a debug session involves the following steps:
  • Setting a Debug listener for the ScriptWrapper. It will be fired for the steps where the execution is paused
  • Creating a Debug session. This is only possible for wrappers which support debugging
  • Set a Session Hook for the session, which will effectively call the method to debug
  • Start the session

Setting a debug listener

Main Article: Debug listener

The DebugListener is an interface which is used to manage the debugging session. It has the following API:

public class DebugListener


Modifier and Type Method and Description
void endSession()
Called when the session has ended
void setDebugSession(DebugSession session)
Set the debug session
void step(Step step)
Called for each step if the debugger must stop for this step

The DebugListener does not depend on the script interface, nor on the scripting language.

By default you have to implement the DebugListener interface, but the SwingDebugScriptWindow is already provided and has a Swing interface.

Creating a debug session

Main Article: Debug session

The DebuggingWrapper.createDebugSession() allows to create a session. It is only available for DebuggingWrappers.

For example:
      ScriptWrapper<Script> wrapper = new GroovyScriptWrapper<Script>() {
      };
      DebugSession<Script> session = wrapper.createDebugSession();
The DebugSession allows to:
  • Start the session
  • Start the session script
  • Step or continue the execution to the next breakpoint
  • Create breakpoints, or edit their properties
  • End the session
Note that it is possible to start another debug session in the context of one parent session. This can be useful for example if you want to start another ScriptWrapper in the Script helper.

Usage with the SwingDebugScriptWindow


See also


Categories: api | debugging

Copyright 2019-2020 Herve Girod. All Rights Reserved. Documentation and source under the BSD licence