![]() |
JSwat ProjectHow To: Remote Debugging |
To debug a program that is already running, you must have started that program using the following command line:
% java -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n <class>
This will start the JPDA debugger back-end and run the given
class. The socket transport will be used and the back-end will act
as the server. This allows JSwat to connect to the debugger
back-end by using the 'attach
' JSwat command.
The debugger back-end will print a four-digit number in the command
shell where you invoked 'java
'. This is the
socket port number that JSwat must connect to.
Once you have started JSwat and the debuggee program is running,
you can type "attach <port>
" to attach
to the debugger back-end through the given port number. JSwat
should say "VM attached" when successful.
To end the remote debugging session, invoke the command
'detach
' or 'close
'.
Either one of these commands will close the connection with the
debuggee VM and leave it running. If you invoke the
'kill
' command instead, this will terminate
the debuggee VM.
In addition to connecting to an already running remote VM, JSwat
can listen for connections from new VMs. This is done using the
'listen
' command. It takes an optional port
number to listen to, or uses a default as generated by the JPDA.
While JSwat is listening for a remote VM to connect, you may launch
the remote debuggee using something like the following:
% java -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=<port> <class>
For the <port>
value, substitute the value
returned from the 'listen
' command. Enter the
name of the class you want to debug in place of the
<class>
argument. Once the remote VM starts up,
JSwat will activate a new debugging session and will be ready for
your input.
Check out the thorough documentation available for the JPDA libraries. These docs come with the JDK documentation for JDK 1.3 and above. Be sure to read up on the JPDA connectors to learn all the options when remotely debugging.