Geeks With Blogs
Rahul Anand's Blog If my mind can conceive it, and my heart can believe it, I know I can achieve it.

Most of the JAVA IDE like Eclipse or InteliJ allow configuring the application through Debug configuration to attach a remote JVM and debug the code libraries.

Let’s walk over this configuration and understand how this debugging works. Coming from MS Visual Studio background, I always missed the easy way of attaching your code by launching the Debug -> “Attach to process” and selecting the target process which is actually executing the library.

Under JAVA this needs to be done in two steps. First you will launch the application (debuggee) with some debug options to allow a client to connect to the socket on a given port. Next you need to launch the code library (debugger) under Java Debugger which will attach at the same port.

The debuggee is the process being debugged, under this process the back-end of debugger runs. The back-end communicates with the debuggee VM using the Java Virtual Machine Debug Interface (JVM DI), and it communicates with the front-end (debugger) over a communication channel using the Java Debug Wire Protocol (JDWP). This communication channel is the link between the front-end and back-end of debugger and it consists of two mechanisms – Connector and Transport.

The Java Platform Debugger Architecture (JPDA) defines three types of connector:

1. Listening Connector

2. Attaching Connector

3. Launching Connector

A java debugger client (front end) can be launched in “Listen” or “Attach” mode depending on whether the debugger client is started before the debuggee application or after. Alternatively it can also be configured to launch the debuggee process when the debugger is started. The front-end implements the Java Debug Interface (JDI) which is responsible for all communication about the actions taken in GUI to back-end and information from the back-end to GUI.

In establishing a connection between a debugger application and target VM, one side acts as a server and listens for a connection. At some later time, the other side attaches to the listener and establishes a connection. The connections allow the debugger application or the target VM to act as a server. The communications among processes can be running on one machine or different machines.

Most common way to start a debugger is to attach the debugger on the port used while launching the debuggee. Under this option the target VM (debuggee) will be the host for debugging and must be started first. Use the following options while invoking a debuggee and run the debugger in attach mode specifying the server IP and port of remote debuggee VM:

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

 

And if you want to host the debugging in debugger then use listening mode and launch the debuggee (after starting debugger) with following command specifying the debugger server IP and port:

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

 

Under JAVA 1.5 or later you may use -agentlib instead of “-Xdebug -Xrunjdwp”, for example:

-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005

 

And if you want to use shared memory as transport:

-agentlib:jdwp=transport=dt_shmem,server=y,suspend=n,address=javadebug

Posted on Monday, October 19, 2015 7:25 PM Java | Back to top


Comments on this post: Debugging - Remote JVM

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Rahul Anand | Powered by: GeeksWithBlogs.net