jEdit Community home jEdit Community Wiki > Plugins > Writing Plugins? > PluginDebuggingTechniques jEdit Community Wiki webs:
Main | Plugins | Know | TWiki | Sandbox?
Plugins . { Changes | Index | Search | Go }
This page is for developers to share how they debug the plugins they are developing. "Debugging plugins" is not to be confused with plugins for debugging such as Java Debugger and JSwat.

Print Debugging

The simplest form of debugging is printing the value of a variable. Since jEdit is a GUI application, printing a variable involves showing the variable on some graphical widget. This section discusses some ways of doing print debugging.

Macros.message and Macros.error

Included in the org.gjt.sp.jedit package is a class called Macros. It is so named because it was written to record and run jEdit macros. It also contains a few methods useful for displaying output messages or obtaining input from a macro. Two methods that are particularly useful are error() and message(). These methods take a View and a String as arguments and create a dialog box with the string argument displayed. To use these methods, you should be sure your actions.xml file passes the current view to your plugin and in your plugin, do the following:

    import org.gjt.sp.jedit.Macros;

    Macros.message(view, "DEBUG: someVariable = " + someVariable);

The advantage to this method is that it is easy. Most plugins already pass view to the action and import all classes from org.gjt.sp.jedit. So usually, inserting the message line is good enough to print a debug message.

The disadvantage to this method is that only one dialog shows at a time and you must click Ok to dismiss the dialog and continue execution. If you have many debug messages, this method can become messy. In some cases, it would be better if you could just print all your debug mesages to a separate area and let the program continue executing. This is where using Error List becomes a better alternative.

Using the Error List plugin

Error List is a plugin that was designed specifically to publish an error reporting API and display errors reported by other plugins. Using Error List to report debugging messages is relatively easy, but requires a little more setup than the Macros.message() method discussed above.

Here is a distilled version of what you need to do to use the Error List plugin to report debug messages:

  1. Read the Error List plugin documentation (RTFM).
  2. In your build.xml file, in the path section, add a pathelement setting with a location that points to where ErrorList.jar is installed.
  3. Find a place in your code to create an instance of DefaultErrorSource. For example, in the class YourPlugin in the start() method. The jEdit manual recommends against using start() as a place to register the error source because it forces the ErrorList class to be loaded, but we can ignore this recommendation since during debugging we will always want to use the plugin and display messages. Just remember to remove the debug code for production builds.
  4. Register the error source created in the previous step: ErrorSource.registerErrorSource(errorsource);
  5. Find a place in your code to unregister the error source you created. For example, in the class YourPlugin in the stop() method.
  6. Now, you can pepper your code with statements that add errors or warnings to the Error List panel. Here is an example of an addError() call that adds a warning, covering the entire line:
    errorsource.addError(new DefaultErrorSource.DefaultError(errorSource, 
        ErrorSource.WARNING, currentFullPath, currentLine, 0,0,
        "DEBUG message here."));

The advantages to this method are:

The disadvantages to this method are:

Real Debugging

So called real debugging allows you to pause the execution of your plugin and inspect many aspects of your code: view and change values of variables, set breakpoints to begin debugging at certain points in your code, etc.

The Java Debugger allows you to start a VM debugging session or to attach the debugger to an already running VM Process. See the online documentation for details: http://java.sun.com/j2se/1.5.0/docs/tooldocs/solaris/jdb.html

Topic PluginDebuggingTechniques . { Edit | Attach | Ref-By | Printable | Diffs | r1.4 | > | r1.3 | > | r1.2 | More }
Revision r1.4 - 31 Jan 2006 - 21:21 GMT - Rob York
Parents: Writing Plugins?
Copyright © 1999-2011 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding jEdit Community Wiki? Send feedback.
Get jEdit at !SourceForge.net. Fast, secure and Free Open Source software downloads