Just a little feedback about my experience using JDE to debug my java apps.
Well, after much fiddling, I finally got debugging to work with JDE.
My goal is to "just debug my java app". I was looking for something
relatively simple like gud-mode in emacs.
First of all, I've come to the conclusion that the best way to debug
java apps is by attaching to running processes. There appears two ways
to do this in JDE:
a. use JDEbug
b. use jdb mode, specifying -attach
In both cases, you have to start up your java app with special
switches. An example looks like (see references below for information
about all the switches):
java -Xdebug
-Xrunjdwp:transport=dt_socket,server=yes,suspend=yes,address=4444
-Xnoagent -Djava.compiler=NONE <main-class-name>
JDEbug method
=============
Here are some observations.
- In order to get JDEbug to work, you need to set
- jde-debugger to "JDEbug"
- jde-sourcepath to directory where your java source resides
- jde-jdk-registry to the java version your are using (and you have
to set jde-jdk if you have more than one version of java installed).
It is the last variable that has seemingly changed since the
JDEbug documentation was published. The JDEbug doc talks about a
variables called jde-bug-vm-includes-jpda-p and jde-bug-jdk-directory,
both of which no longer exist. If you don't set jde-jdk-registry, then the
JDEbug debugger will be launched with an incorrect classpath, and the
debugger will fail when you try to listen or attach to a java
app. (The debugger process is launched when you say "Start Debugger").
java -classpath
/usr/local/lib/xemacs/xemacs-packages/etc/jde/java/lib/jde.jar:/usr/lib/tools.jar
jde.debugger.Main
Note it says /usr/lib/tools.jar which is the incorrect path.
You then start up the JDEbug process by selecting
JDEbug->Processes->Start Debugger
JDEbug->Processes->Attach Process->On Local Host
It prompts you for a "Process Port", and you need to enter the same one you
use when you launched the java app.
I don't understand why it prompts you when there is a variable called
jde-bug-server-socket that should be the default.
Here is a sample prj.el:
(jde-project-file-version "1.0")
(jde-set-variables
'(jde-debugger (quote ("JDEbug")))
'(jde-sourcepath (quote ("/tmp/ffj")))
'(jde-jdk-registry (quote (("1.3.1" . "/usr/j2se") ))))
I still encounter problems however with
Symbol's value as variable is void: old-assoc
but I think this is an XEmacs specific problem.
I can't quite figure out how to print variables, e.g. I'm not sure how
to use JDEbug->Display-Variable. But that is probably just me.
JDB method
==========
With this method you are invoking jdb with its "-attach" switch so
that jdb uses the JPDA debugger agent.
Have java (i.e. jdb) in your path.
To work with JDE, set the variables
- jde-debugger to "jdb"
- jde-sourcepath to directory where your java source resides
Then start up your java app as above. and run.
Jdb->External Process->Attach to
There are variable to control various options (like the socket to use,
default is 4444; variable name is jde-db-option-connect-address).
I've sometimes encountered problems where jdb doesn't seem to work
right, and it causes jdb-mode to complain when it parses the
output. E.g. I would print a variable with "print foo", and there
would be a blank response. I type the command again and then it
works. This is obviously a jdb bug. But the JDE complain parsing the
output. I've seen "dump foo" fail also. I have to retry the command
several times before it responds. this popping up of the *Warning*
buffer is annoying, but I do understand it is jdb's fault, not JDE.
Here is a sample prj.el:
(jde-project-file-version "1.0")
(jde-set-variables
'(jde-debugger (quote ("jdb")))
'(jde-sourcepath (quote ("/tmp/ffj")))
)
Personal Comments
=================
- The jdb method also feels a lot more familiar, because it is more
like good old gud-mode. It also feels a lot less "heavy". For
instance, I like being able to type commands to jdb directly.
References:
- How to use JDEbug (no link from the JDE home page)
http://jdee.sunsite.dk/jdedoc/jdebug/ug/jdebug-ug.html
- Using jpda debugger agent - attaching to java processes for debugging
http://java.sun.com/j2se/1.3/docs/guide/jpda/conninv.html
- Using jdb mode in JDE
http://jdee.sunsite.dk/jdedoc/ug/jdb-guide.html
- Doesn't mention setting jde-debugger variable (probably because
jdb is the default).
XEmacs distributions of JDE (latest is jde package 1.38) also has the
documentation under xemacs-packages/etc/jde/doc/html/...