#576 Beanshell Debugger


Hi jEdit community,

the attached patchset contains a very first implementation of a debugger for beanshell scripts which are executed inside jEdit. Please take a look at following video https://www.youtube.com/watch?v=q0uNJhLXcMU to get a first idea how debugging of beanshell scripts could look like.
Breakpoints are added by statement "Interpreter.BSH_DEBUG = true;". If a script is executed and reaches this kind of statement, the beanshell interpreter stops execution and launches a debug ServerSocket listenening to request by the DebugClient which is also automatically started. The DebugClient is a simple standalone java application which allows to debug the beanshell script. Currently, the features Step Over, Continue and Evaluate Expression (including code completion support for the expression) are supported.
It is only a first implementation and by far not stable enough to be used in a productive environment.
What do you think? Are you interested in the implementation? Should we go a step further and productize this prototype?

With best regards,

1 Attachments


  • Alan Ezust

    Alan Ezust - 2016-07-06

    Very impressive. In terms of design, I would suggest making it into a plugin, and providing a dockable window instead of a Dialog. Making as few changes to core as possible.

  • Alan Ezust

    Alan Ezust - 2016-07-06

    Also, please use org.jedit for new classes that are added to Core, rather than the gjt.sp.jedit package.
    From the design, you may need to add a DebugServer interface to core, so the plugin can provide an implementation of it.

  • Alan Ezust

    Alan Ezust - 2016-07-10
    • status: open --> pending-remind
    • Group: -->
  • Tobias Melcher

    Tobias Melcher - 2016-08-03

    A first version is now on github:

    I have some questions regarding plugin development:
    1. How to contribute a context menu "Toggle Beanshell Breakpoint" entry in the editor area. Best would be if the context menu is only visible for .bsh files. Currently, I use following code snippet in plugin start method which looks more a workaround to me:

    String name = "view.context";
    String menuItems = jEdit.getProperty(name);
    if (menuItems.contains("bshdebugger.togglebreakpoint-action") == false)
    jEdit.setProperty(name, menuItems + " bshdebugger.togglebreakpoint-action");

    1. How to register a keyboard shortcut for a jEdit plugin action. I also use a workaround with following code snippet again in plugin start method:

    EditAction action = jEdit.getAction("bshdebugger.togglebreakpoint-action");
    String shortcut = jEdit.getProperty("bshdebugger.togglebreakpoint-action.shortcut");
    if (shortcut==null || shortcut.length()==0) {
    jEdit.getInputHandler().addKeyBinding("A+b", action);

    The Beanshell Debugger is now working without modifying the jEdit base code. To realize this, class org.gjt.sp.jedit.bsh.BSHBlock is replaced on plugin startup with customized code which is using reflection to call back to the beanshell debugger plugin. It would be much more helpful if the IBeanshellDebugger interface and necessary calls inside Interpreter and BSHBlock could be added to the core code base.

  • Dale Anson

    Dale Anson - 2016-08-03

    For the context menu, do this:
    1. write a class that extends JMenu. In your case, it sounds like it would have just the toggle break point action, although you could certainly add others.
    Here's a link to an example from the Subversion plugin:


    1. write a class that extends org.gjt.sp.jedit.gui.DynamicContextMenuService and loads your JMenu class. Here's a link to an example in the Subversion plugin again:


    1. add a reference to this menu service file in your services.xml file like this:

    <SERVICE CLASS="org.gjt.sp.jedit.gui.DynamicContextMenuService" NAME="subversion">
    new ise.plugin.svn.ContextMenuService();

    The built-in context menu doesn't have mode specific items, however, the ContextMenu plugin does. Maybe check the ContextMenu API to see if that could be useful in this case?

    For the action and shortcut, do this:
    1. put the action code in your actions.xml file, something like this:
    <ACTION NAME="bshdebugger.togglebreakpoint-action">
    // put your action code here

    1. put a label for your action in your plugin properties file like this:

    bshdebugger.togglebreakpoint-action.label=Toggle $Breakpoint

    where the $ indicates the hotkey for the menu item. The $ is optional.

    1. put a default shortcut in your plugin properties file like this:


    This will allow the user to change the shortcut in the Global Options - Shortcuts rather than having it hard-coded in your plugin. Personally, I'm hesitant to set a default shortcut since it's possible the user has already used that one for something else.

    Using reflection code always makes me a little uneasy, it works, but can break in later releases. Maybe you could develop a minimal patch for the core code that would let you eliminate the reflection code?


Log in to post a comment.