Remote Debugging with Eclipse

You can use SSH port tunneling to in conjunction with Eclipse's Java debugger locally to debug stuff running on the NLP machines. It beats using jdb, and is much more responsive than trying to use a graphical utility over X11.

Suppose you've logged in and then ssh'd into Jar (as running big stuff on Jamie/Jacob is a sure fire way of decreasing the gross happiness index of the group):

  1. On Jar, add the following cmd options to your java call:
         -Xdebug -Xnoagent -Djava.compiler=None -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=9009
    
    This'll cause your app to start up in debug mode, and will listen on port 9009 for a remote debugger to attach to it.
  2. On your local machine, ssh to jamie (or jacob), but create a tunnel to the machine your app will run on (i.e. jar).

         ssh -LPORT:MACHINE:PORT USERNAME@jamie.stanford.edu
    
    i.e.
         ssh -L9009:jar:9009 yeh1@jamie.stanford.edu
    

    This will cause calls to localhost:9009 to be redirected to jar:9009 (the remote debug port), via your connection to jamie.

  3. On your local machine, in Eclipse, open the "Run->Open Debug Dialog" menu item, select "Remote Java Application", and choose a new configuration. Set the Project to be the JavaNLP project you want to debug, set "Host" to be "localhost", and port to be "9009". Make sure "Connection Type" is "Standard (Socket Attach)"

  4. Make sure your ssh tunnel session is active, start your app on the NLP machine. In your local Eclipse instance, start debugging with the remote app configuration from step 3. It'll take a few seconds to attach, and then you can break/operate over the remote app on jar using the Eclipse instance.

It'll help to make sure your JavaNLP checkout and the remote checkout you're running on are sync'd. Also, running in debug mode can be a little slower, but it beats trying to debug the RTE system on my poor Macbook. Being able to use the graphical debugger is nicer than JDB or the guess/println/compile/test cycle, and Eclipse's "Display" feature makes for a nice pseudo-REPL in a running JVM.

The debug mechanism used is a Java standard, so nothing prevents you from using the port tunneling trick to attach using another debugger.