Getting JDB to work with my own JPDA connector

Ok, I am now officially confused...

I read http://java.sun.com/j2se/1.5.0/docs/guide/jpda/jpda_spis.html,

and deployed my connector (for now, just to see that it works,

Sun's sample one) as they specified (created a jar with

META-INF/services/com.sun.jdi.connect.Connector file, and

placed it in jre/lib/ext -- I then also tried placing it in other folders,

nothing worked).

I then tried to do connect to it with JPDA (as specified in

http://java.sun.com/j2se/1.5.0/docs/guide/jpda/conninv.html#JDB).

I tried using -connect option, but it said

invalid option: -connect=org.hrum.dbdb.DbdbLaunchingConnector

(and gave me a usage screen which included -connect).

I then tried to just do jdb -listconnectors, and,

I got

java.lang.NoClassDefFoundError: com/sun/jdi/connect/LaunchingConnector (even though I

specified tools.jar in -classpath option)

and then a list of connectors (which didn't include mine).

Now, when I reread "Connecting with JDB" paragraph, the phrase

"The example implementation of JDB provided with the JPDA"

caught my eye. I then thought that I need another JDB, the

reference one that comes with JPDA download, not the one included

with JDK. But then, http://java.sun.com/products/jpda/download.html

claims JPDA is already included with the download. So what's up?

[1441 byte] By [juntaa] at [2007-10-2 0:52:55]
# 1
Im only learning the JPDA myself so im not going to be much help to you other than to suggest you read http://java.sys-con.com/read/36221.htm which has been of some help to myself.
javakicksassa at 2007-7-15 18:12:37 > top of Java-index,Archived Forums,Debugging Tools and Techniques...
# 2

Taking your last question first, for anything newer than 1.2.2, the

most recent jdb is included in your JDK download. The

executable code is baked in (via the jdb launcher and the classes in

tools.jar). If you want to take a look at the source code, that is

also available in $JAVA_HOME/demo/jpda/examples.jar. Unpack

this .jar file to see the sources:

jar -xvf $JAVA_HOME/demo/jpda/examples.jar

In a 5.0/Tiger (or later) environment, a jdb -listconnectors

command should enumerate the connectors available:

Try this:

% jdb -J-showversion -listconnectors

java version "1.5.0"

Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)

Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode)

Available connectors are:

Connector: com.sun.jdi.CommandLineLaunch Transport: dt_socket

description: Launches target using Sun Java VM command line and attaches to it

Argument: home Default value: /export/u4/opt/jdk-1_5_0-fcs-b64/jre

description: Home directory of the SDK or runtime environment used to launch the application

Argument: options (no default)

description: Launched VM options

Required Argument: main (no default)

description: Main class and arguments, or if -jar is an option, the main jar file and arguments

Argument: suspend Default value: true

description: All threads will be suspended before execution of main

Required Argument: quote Default value: "

description: Character used to combine space-delimited text into a single command line argument

Required Argument: vmexec Default value: java

description: Name of the Java VM launcher

Connector: com.sun.jdi.RawCommandLineLaunch Transport: dt_socket

description: Launches target using user-specified command line and attaches to it

Required Argument: command (no default)

description: Raw command to start the debugged application VM

...

I added -J-showversion to the jdb command line to make sure I

was running the environment I was expecting.

What is the output of java -version and jdb -J-showversion

-listconnectors in your environment?

Forgive me for starting with these first principles - but anything

else is wasted time unless the basic environment is OK.

timbella at 2007-7-15 18:12:37 > top of Java-index,Archived Forums,Debugging Tools and Techniques...
# 3

Ah, I think the problem is on this page:

thttp://java.sun.com/j2se/1.5.0/docs/guide/jpda/jpda_spis.html

It suggests copying the JAR file to the extensions directory. As the JDI classes are in tools.jar it means they are on the system class path. This is why you get the "java.lang.NoClassDefFoundError: com/sun/jdi/connect/LaunchingConnector" error.

To fix the problem I suggest doing:

1. Remove your JAR file from the extensions directory.

2. Try this:

jdb -classpath <YOUR-JAR-FILE> -listconnectors

If this lists your Connector then you are in business. Then you can use "jdb -connect <connector>...". I see in your post that you have "-connect=<connector>" but that is not the right syntax.

The syntax is "jdb -connect <connector>:<name=value>...." . It looks like you have "jdb -connect=<connector>"

alan.batemana at 2007-7-15 18:12:37 > top of Java-index,Archived Forums,Debugging Tools and Techniques...
# 4

Ok, I've figured out what's going on for now...

1. I had to put tools.jar from the JRE's home (as different from

JAVA_HOME, which, apparently, is assumed to be JRE's home -- to wit,

if you have JDK installed, it's, e.g., D:\jdk1.5.0\jre rather than

D:\jdk1.5.0). In other words, dropping the tools.jar into the jre/lib/ext

folder in addition to it's righteous place in <JDK_INSTALL_DIR>lib did

the trick of getting rid of that pesky ClassDefFoundError. .

2. You should properly override name() of the Connector you're

implementing correctly for diagnostic (so that you're not confused by

the output of jdb -listconnectors) but that's a minor thing...

And to follow up:

1. javakicksass: Nice link, btw...

2. timbell: thanks for the -J-showversion tip

3. alan.bateman: See above (I tried the -classpath thingie, didn't

seem to work...)

juntaa at 2007-7-15 18:12:37 > top of Java-index,Archived Forums,Debugging Tools and Techniques...
# 5

The reason it is working for your now is that tools.jar and your Connector are in the extensions directory and hence loaded by the extensions class loader. You don't need to do this. The error in the jpda_spis page is that it suggests copying the Connector to the extensions directory - that is an error. So if you remove these from the extensions directory and just put tools.jar and your Connector on the classpath then it should just work.

alan.batemana at 2007-7-15 18:12:37 > top of Java-index,Archived Forums,Debugging Tools and Techniques...
# 6
Well, actually, no...What do you mean by "on classpath"? the -classpath optionto JDB is not for JDB, it's for whatever JDB is debugging. It hasno effect as far as JDB finding connector. If you mean justputting it in JAVA_HOME/lib, that has no effect either...
juntaa at 2007-7-15 18:12:37 > top of Java-index,Archived Forums,Debugging Tools and Techniques...
# 7

jdb is just a native wrapper that executes com.sun.tools.examples.debug.TTY. The native wrapper is compiled with the classpath set to tools.jar (plus sa-jdi.jar Solaris/Linux).

For you to have your Connector visible to jdb then you need to put it on jdb's classpath which you can do with:

jdb -J-classpath -J$JAVA_HOME/lib/tools.jar:MyConnector.jar -listconnectors

(if you are on Windows then it will be something like "jdb -J-classpath -J%JAVA_HOME%\lib\tools.jar;MyConnector.jar -listconnectors")

Alternatively, this should do it too:

java -classpath $JAVA_HOME/lib/tools.jar:MyConnector.jar com.sun.tools.examples.debug.TTY -listconnectors

alan.batemana at 2007-7-15 18:12:37 > top of Java-index,Archived Forums,Debugging Tools and Techniques...
# 8
> 1. javakicksass: Nice link, btw...No problem, glad it was useful, it certainly helped me get started on my project.
javakicksassa at 2007-7-15 18:12:37 > top of Java-index,Archived Forums,Debugging Tools and Techniques...