Why Remote Debugging?
Debugging is very important to find out problems in the software system. It is good idea to find all the bugs and glitches in the system in development period, but no one can guarantee that a system is "bug-free". Nowadays, we have advanced Integrated Development Environments(IDE's) which makes development and debugging very easy. So, if we find out the problem of the software in the development phase, IDE make it easy to find out. But what if we find out the problem in the software system that is deployed to the client's computer where we can't(not allowed to) install our development environment. It sometimes is impossible to install IDE to a system with low resources(such as low memory or processor power etc.).
Remote debugging covers the problems mentioned above. We can remotely debug the software system installed in a computer anywhere in the network. Remote debugging is quite useful to find out system specific bugs. There are many real examples of bugs which do not exist in the development system, however, they exist in the client's system where we deploy our software.
How Remote Debugging?
Well, we will discuss remote debugging in Java (It is possible in other programming language also) with Eclipse as IDE (I guess it is the most popular IDE). To make the process simple, I have divided whole process into steps. The whole process can be divided into two parts:
For class file
To enable remote debugging for a software as a class file ( e.g. HelloWorld.class ), we use the following command to execute.
java -Xdebug -Xrunjdwp:transport=dt_socket,address=4444,server=y,suspend=y HelloWorld
For JAR file
To enable remote debugging for a software as a JAR file ( e.g. HelloWorld.jar ), we use the following command:
java -Xdebug -Xrunjdwp:transport=dt_socket,address=4444,server=y,suspend=y -jar HelloWorld.jar
For Tomcat Server
If the application is running under tomcat server, we have to modify catalina.sh file in $CATALINA_BASE directory.
Open the file, and you will see CATALINA_OPTS, just un-comment it and replace with this:
And you have to stop the tomcat server if it is already started:
service tomcat stop
Go to bin directory under $CATALINA_BASE (e.g. /opt/tomcat/bin) and execute the following command(
catalina.sh jpda start
Eclipse configuration is quite straight-forward.
1. Select the project you want to remote debug.
2. Go to "Debug Configurations..." under Run menu.
3. Create a new Remote Java Application.
Connection Type: Standard(Socket Attach).
Host: Remote hostname or IP ( e.g. 192.168.1.83 )
Let the option "Allow termination of remote VM" as disselected. That's it.