How to use jdb for debugging a servlet?

I'm using Apache/JServ with jdk 1.4 (via Textpad on win2K SP 3).

The 'gospel' I'm trying to follow is:

'Start the server manually and record the password for remote debugging

(this is displayed on the console).'

'Start the Java debugger:'

'jdb -host your_host -password the_password'

'You should be able to debug your Java classes now using the jdb

command.'

My problem is that I can't find the password from Apache.

I normally start/restart apache as a windows Service.

If I start it from DOS I get:

'C:\orant9i\Apache\Apache>apache -k start'

'Oracle HTTP Server Powered by Apache/1.3.12 (Win32) ApacheJServ/1.1

mod_ssl/2.6.4 OpenSSL/0.9.5a mod_perl/1.24 running...'

I've searched the log, conf & property files but can't find any password.

I've also searched the Apache website for 'jdb' without luck.

I've printed out (and read!) the 'Using Apache with MS Windows' manual.

I did a Google:

--Someone suggested starting Apache using using the -X flag, but I don't

seem to have this option.

--Someone else suggested changing jvm12.conf, but I don't have one.

I have tried the following, just-in-case I don't really need a password,

but it doesn't tell me a lot, and I would appreciate some help:

JDB -sourcepath E:\javaPackages org.apache.jserv.JServServletManager

C:\orant9i\Apache\Apache>JDB org.apache.jserv.JServServletManager

Initializing jdb ...

> run

run org.apache.jserv.JServServletManager

Set uncaught java.lang.Throwable

Set deferred uncaught java.lang.Throwable

>

VM Started:

Exception occurred: java.lang.ClassNotFoundException (uncaught)"thread=main", java.net.URLClassLoader$1.run(), line=199 bci=72

main[1] list

Source file not found: URLClassLoader.java

main[1]

Thanks,

Peter.

Posted to alt.apache.configuration, comp.lang.java, http://groups.yahoo.com/group/win-apache and

comp.infosystems.www.servers.misc with no response

[2127 byte] By [chattpa] at [2007-9-29 20:10:12]
# 1

You can attach to and debug any process running a modern Java[tm] VM

as long as it is started with valid debug flags such as "-Xdebug -Xrunjdwp:...."

By "modern" I mean 1.2.2 or newer (with a few exceptions noted on the

download page):

http://java.sun.com/products/jpda/download.html

You wrote:

>The 'gospel' I'm trying to follow is:

>'Start the server manually and record the password for remote debugging

>(this is displayed on the console).'

'>Start the Java debugger:'

>'jdb -host your_host -password the_password'

'>You should be able to debug your Java classes now using the jdb

>command.'

This recipie is out of date. That is the description for using the old

sun.tools.debug debugger, which pre-dates the JDI interface.

The old jdb was never compatable with any HotSpot VMs, so it

was removed completely in 1.4 or 1.4.1 (Bug-ID 4341203)

http://developer.java.sun.com/developer/bugParade/bugs/4341203.html

The jdb based on the Java Debug Interface (JDI) does not provide or

require a debug password.

You need to get the VM running your Servlet started with the appropriate

debug flags. Then you will be able to attach jdb to it.

I am not familiar with the specifics of the Apache/JServ configuration,

but there must be a place or config file where you specify the JVM

you want and the run flags you want to use. You need to add flags

like this:

-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,suspend=n,server=y

(Make sure the socket address you select (8000 in this example) is not in use.)

Then, after apache has started and you see the JVM running in your process

display, you will be able to attach jdb to the socket address specified above:

jdb -connect com.sun.jdi.SocketAttach:hostname=localhost,port=8000

For more information, refer to "Connection and Invocation Details":

http://java.sun.com/j2se/1.4.2/docs/guide/jpda/conninv.html

debugging_teama at 2007-7-16 0:23:31 > top of Java-index,Archived Forums,Debugging Tools and Techniques...
# 2

Thanks for your help.

I added the following to jserv.properties:

wrapper.bin.parameters=-Xdebug

wrapper.bin.parameters=-Xrunjdwp:transport=dt_socket,address=2930,suspend=n,server=y

and it ran the servlet okay.

But I get the following when I try to start jdb:

jdb -connect com.sun.jdi.SocketAttach:hostname=localhost,port=2930 org.apache.jserv.JServServletManager

gives:

Cannot specify command line with connector:

com.sun.jdi.SocketAttach:hostname=localhost,port=2930,

and

jdb -attach localhost:2930 org.apache.jserv.JServServletManager

gives:

Cannot specify command line with connector: com.sun.jdi.SharedMemoryAttach:name=localhost:2930,

I'm going to keep working on it but thought I'd upload this as it's late and I'm not too optimistic.

BTW, am I using the right class?

Thanks again,

Peter.

chattpa at 2007-7-16 0:23:31 > top of Java-index,Archived Forums,Debugging Tools and Techniques...
# 3

[/code]

UPDATE

Well, I got lucky.

After re-reading the Connection and Invocation Details paper you recommended, (and remembering i'm using windows), I tried:

C:\orant9i\Apache\Apache>jdb -connect "com.sun.jdi.CommandLineLaunch:main=org.apache.jserv.JServServletManager

Initializing jdb ...

> run

run org.apache.jserv.JServServletManager

Set uncaught java.lang.Throwable

Set deferred uncaught java.lang.Throwable

>

VM Started:

Exception occurred: java.lang.ClassNotFoundException (uncaught)"thread=main", java.net.URLClassLoader$1.run(), line=199 bci=72

main[1]

This is obviously the right way to make contact, but with what?

It looks like I need a class with a 'main' to connect to, and that sure isn't my servlet, and doesn't seem to be JServServletManager.

Any ideas?

Thanks,

Peter.

[/code]

chattpa at 2007-7-16 0:23:31 > top of Java-index,Archived Forums,Debugging Tools and Techniques...
# 4

Hello

You wrote:

> I added the following to jserv.properties:

>wrapper.bin.parameters=-Xdebug

>wrapper.bin.parameters=-Xrunjdwp:transport=dt_socket,address=2930,suspend=n,server=y

> and it ran the servlet okay.

Fine so far. This means your debugee VM is started and running. The "suspend=n" means it

will start running without waiting for a debugger to attach... so you can attach later whenever you

decide to debug. Note that 'later' could be weeks later, or possibly never.

Now: Time to attach jdb to the victim/debugee process you started above.

You wrote:

> But I get the following when I try to start jdb:

>jdb -connect com.sun.jdi.SocketAttach:hostname=localhost,port=2930 org.apache.jserv.JServServletManager

> gives:

>Cannot specify command line with connector:

>com.sun.jdi.SocketAttach:hostname=localhost,port=2930,

>and

>jdb -attach localhost:2930 org.apache.jserv.JServServletManager

>gives:

>Cannot specify command line with connector: com.sun.jdi.SharedMemoryAttach:name=localhost:2930,

The problem here is that you are trying to supply too much information to jdb.

When you are using the attach connectors, all you need to supply is the

host name and socket (for the socket connectors), or the name of the shared memory

area (for the shared memory connector). The connectors you tried above are throwing

an error because you are trying to supply something extra (the class name).

When doing an attach, the debugee VM is already launched. The debugger will

attach to it and inspect the classes loaded.

If you are still running with the wrapper.bin.parameters you listed above,

then all you need to connect with jdb is:

jdb -connect com.sun.jdi.SocketAttach:hostname=localhost,port=2930

You should get a jdb prompt, and you will be able to inspect the debugee

VM by entering commands such as threads and classes. Typically

the next thing would be to set some breakpoints (stop in package.class.method,

or stop at package.class:line. Then restart the debugee with a resume.

debugging_teama at 2007-7-16 0:23:31 > top of Java-index,Archived Forums,Debugging Tools and Techniques...