8
votes

I have a complicated application with several different JVMs.

JVM 1 does about 5 minutes of work and then fires off another JVM2 to do some extra work.

I want to Debug JVM2. So I turn on a remote socket debugger on JVM2's startup script:

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

And I set up my Eclipse Remote Debug Session like this:

Connection Type: Standard (Socket Attach), Host: localhost, Port: 8000

If I wait for JVM2 to start, then launch the debugger, it works fine.

However it is REALLY hard to pay enough attention to click the debugger after 5 long minutes of waiting.

If I launch the remote debugger before JVM2 is on... I get

Failed to connect to remote VM. Connection refused.
Connection refused: connect

Is there someway to have the Remote Debugger continuously try to connect?

I tried to use the Eclipse Remote Debug Connection Type: Socket Listen but this blocks the port and JVM2 gives this error on startup:

FATAL ERROR in native method: JDWP No transports initialized, jvmtiError=JVMTI_ERROR_INTERNAL(113)
ERROR: transport error 202: bind failed: Address already in use ["transport.c",L41]
ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510) ["debugInit.c",L500]
JDWP exit error JVMTI_ERROR_INTERNAL(113): No transports initialized

How can I have the remote debugger try over and over and over again?

1
This is the way remote debugging works. The connection goes from the debugger to the remote JVM being debugged. If you want you can add the suspend=y option to have the remote JVM pause until the debugger connects. The remote JVM will not initiate an outgoing JDWP connection.Jim Garrison
I'm not expert in this at all, but isn't it possible to specify server=n in the -Xrunjdwp switch and have the debugee connect as a client to the debugger server, per your second setup ("Socket Listen") in eclipse?clstrfsck
@JimGarrison i'm trying that now.Nicholas DiPiazza
@msandiford i'm trying your suggestion next. for some reason IE8 (which i'm stuck using at work) didn't show me your comment until now. That sounds like another acceptible answer. both of your guys' comments are very valid.Nicholas DiPiazza
@msandiford THIS was the answer i was looking for. Worked great.Nicholas DiPiazza

1 Answers

8
votes

Turning comment into answer for folks that come by later:

It's possible to specify server=n in the -Xrunjdwp switch and have the debugee connect as a client to the debugger server.

To make this work, the debugger configuration should be set up with the "Socket Listen" option in eclipse like so:

Eclipse debugger configuration

Client can then be started with:

java -Xdebug -Xrunjdwp:transport=dt_socket,server=n,suspend=n,address=8000 -jar foo.jar

Or similar.