PreviousNextTracker indexSee it online !

(20/27) 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,
Tobias

Submitted d031119 - 2015-10-25 10:57:16.699000 Assigned
Priority 5 Labels
Status pending Group
Resolution remind

Comments

2016-07-06 04:16:57.906000
ezust

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.

2016-07-06 04:53:26.679000
ezust

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.

2016-07-10 20:43:12.012000
ezust

- **status**: open --> pending-remind
- **Group**: -->

2016-08-03 12:06:09.979000
d031119

A first version is now on github:
https://github.com/tobiasmelcher/jEditBeanshellDebugger

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");

2. 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.

2016-08-03 13:30:11.433000
daleanson

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:

https://sourceforge.net/p/jedit/svn/HEAD/tree/plugins/SVNPlugin/trunk/src/ise/plugin/svn/gui/TextAreaContextMenu.java

2. 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:

https://sourceforge.net/p/jedit/svn/HEAD/tree/plugins/SVNPlugin/trunk/src/ise/plugin/svn/ContextMenuService.java

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

<!-- adds the SVN context menu to the jEdit text area context menu -->
<SERVICE CLASS="org.gjt.sp.jedit.gui.DynamicContextMenuService" NAME="subversion">
new ise.plugin.svn.ContextMenuService();
</SERVICE>

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">
<CODE>
// put your action code here
</CODE>
</ACTION>

2. 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.

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

bshdebugger.togglebreakpoint.shortcut=A+b

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?

2016-08-03 14:12:34.766000
d031119

Thanks a lot the DynamicContextMenuService is working like a charm.

But the shortcut is somehow not recognized. I added the .shortcut entry in the props file and unfortunately the shortcut is not visible in the global options dialog.
Here is the commit:
https://github.com/tobiasmelcher/jEditBeanshellDebugger/commit/0994673e7f886d9047f206c546923785e5294bdf
Am I doing something wrong?

2016-08-03 14:19:47.207000
d031119

here the changes in the jedit core coding I would need to realize the beanshell debugger plugin without the need of using reflection.

IBeanShellDebugger.java (313B)

jedit_core_bsh_debugger.patch (2.3Kio)