Revision as of 10:07, 17 December 2009 by Eglinger (talk | contribs) (This is an ultra quick start to jdb, the default Java debugger)
(This text was originally copied from the VIB project)

How to attach the Java debugger jdb to a running fiji process

This requires two separate processes, fiji itself and the debugger. You can do this either in one shell, backgrounding the first process or in two shells, this is recommended. In the two shells do the following:

Shell 1
In the first shell, start fiji with special parameters to open a port (8000 in this case) to which jdb can connect afterwards:
./fiji -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y --
(Tested with Java 1.5.0, ymmv)
Shell 2
In the second shell, tell jdb to attach to that port:
jdb -attach 8000

This is an ultra quick start to jdb, the default Java debugger

Hopefully you are a little familiar with gdb, since jdb resembles it lightly.

Notable differences:

  • a breakpoint is set with "stop in <class>.<method>" or "<class>:<line>". Just remember that the class must be fully specified, i.e. <package>.<subpackages...>.<classname>
  • no tab completion
  • no readline (cursor up/down)
  • no shortcuts; you have to write "run", not "r" to run the program
  • no listing files before the class was loaded
  • much easier method to specify the location of the source: "use <dir>"
  • "until" is "step", "step" is "stepi"

Okay, so here you go, a little demonstration:

(If you attach jdb to a running fiji process, you have to use the line from the previous section instead.)

$ jdb -classpath ij.jar ij.ImageJ
> stop in ij.ImageJ.main
Deferring breakpoint ij.ImageJ.main.
It will be set after the class is loaded.
> run
run ij.ImageJ
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
VM Started: Set deferred breakpoint ij.ImageJ.main

Breakpoint hit: "thread=main", ij.ImageJ.main(), line=466 bci=0

main[1] use .
main[1] list
462             //prefs.put(IJ_HEIGHT, Integer.toString(size.height));
463     }
465     public static void main(String args[]) {
466 =>          if (System.getProperty("java.version").substring(0,3).compareTo("1.4")<0) {
467                     javax.swing.JOptionPane.showMessageDialog(null,"ImageJ "+VERSION+" requires Java 1.4.1 or later.");
468                     System.exit(0);
469             }
470             boolean noGUI = false;
471             arguments = args;
main[1] print args[0]
java.lang.IndexOutOfBoundsException: Invalid array range: 0 to 0
 args[0] = null
main[1] print args.length
 args.length = 0
main[1] step
Step completed: "thread=main", ij.ImageJ.main(), line=470 bci=28
470             boolean noGUI = false;

main[1] step
Step completed: "thread=main", ij.ImageJ.main(), line=471 bci=30
471             arguments = args;

main[1] set noGUI = true
 noGUI = true = true
main[1] cont
The application exited