5

I'm trying to connect my best debugger to a remote Glassfish instance (by remote I mean not running on the same physical machine, and not only not in the same VM).

My glassfish domain configuration has the "debug" flag checked, and server.log reports during startup

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

Which indicates (to my mind), debugging is indeed enabled.

However, when I try to connect a debugger, it fails. The following session is an example (done with PuTTy) :

$ jdb -connect com.sun.jdi.SocketAttach:port=9009
java.net.ConnectException: Connection refused
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:385)
    at java.net.Socket.connect(Socket.java:529)
    at com.sun.tools.jdi.SocketTransportService.attach(SocketTransportService.java:204)
    at com.sun.tools.jdi.GenericAttachingConnector.attach(GenericAttachingConnector.java:98)
    at com.sun.tools.jdi.SocketAttachingConnector.attach(SocketAttachingConnector.java:72)
    at com.sun.tools.example.debug.tty.VMConnection.attachTarget(VMConnection.java:358)
    at com.sun.tools.example.debug.tty.VMConnection.open(VMConnection.java:168)
    at com.sun.tools.example.debug.tty.Env.init(Env.java:64)
    at com.sun.tools.example.debug.tty.TTY.main(TTY.java:1010)

Fatal error:
Unable to attach to target VM.

What could cause that behaviour ?

EDIT

Notice this jdb command-line has been given as an example of Glassfish debug testing on the web, here is why I used it

Also notice I'm doing this jdb debug session locally (that's to say when connected to that machine using PuTTy, so invoking jdb on the machine Glassifh is running on).

Community
  • 1
  • 1
Riduidel
  • 22,052
  • 14
  • 85
  • 185
  • 1
    Can you run `ps -ef | grep java` as a quick sanity check that glassfish is starting with your jvm params. Also a netstat for the state of that port? – nsfyn55 May 09 '12 at 13:05
  • 1
    When you said 'by running I mean not running' did you mean this 'by REMOTE I mean not running'? – vkraemer May 09 '12 at 20:11
  • @vkraemer Indeed. I changed the question accordingly. – Riduidel May 11 '12 at 07:35
  • this looks like a similar circumstance... and has an accepted answer... http://stackoverflow.com/questions/4220174/failed-to-attach-to-the-remote-vm-connecting-jdb-to-the-android-emulator-on-wi – vkraemer May 12 '12 at 23:03

2 Answers2

0

Since you're on the same machine, try jdb -attach 9009 instead.

If that doesn't work, have a look at the jdb documentation because it uses very different options to prepare the VM for debugging.

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
0

If the JVM that you want to debug is on a remote machine (a machine with a different IP address) you have to include the host name or IP address as part of the attach option.

jdb -attach <hostname-or-address>:<port-number>

jdb is smart, but it won't search your network just to find a port that is waiting for a JPDA client.

You may want to look at this document about jdb.

vkraemer
  • 9,864
  • 2
  • 30
  • 44