I really like the remote debugging facilities of the JVM. But I wonder how it works internally.
My assumption: It is done through a JVM feature where the running process is downloading/using the source-code from the attached remote-debugger (like IDE) It knows the line of the current stack-trace and then can jump to the respective IDE breakpoint. The communication of stack-trace and introspection of the application state is then done either through sockets or shared-memory (setting of remote debugger).
Has anybody interesting links/resources on that?
Remote debugging is when you debug an application running in a place or environment different from your local machine in a way that resembles local debugging. The point of this is for developers to debug components of distributed systems without difficulty.
Remote Java Debugging is the process of debugging a Java program or application running on another machine or a server environment.
Debugging allows you to run a program interactively while watching the source code and the variables during the execution. A breakpoint in the source code specifies where the execution of the program should stop during debugging. Once the program is stopped you can investigate variables, change their content, etc.
The debugging features of the JVM are provided via the Java Platform Debugger Architecture (JPDA).
The JPDA itself is composed of the following:
The diagram listed in the JPDA architecture structure is a good starting point. Additional places to look for would be the guides listed in the JPDA page.
Eclipse debugging starts with what is referred to as Agents.
The JVM, which runs the complied ".class" sources has a feature that allows external libraries (written in Java or C++) to be injected into the JVM, during runtime. These external libraries are referred to as Agents and they have the ability to modify the content of the .class files been run. These Agents have access to functionality of the JVM that is not accessible from within a regular Java code running inside the JVM and they can be used to do interesting stuff like injecting and modify the running source code, profiling etc. Some tools like JRebel(used for hot replacement of code) makes use of this piece of functionality to achieve their magic.
And to pass an Agent Lib to a JVM, you do so via start up arguments, using the -
agentlib:libname[=options]
We were actually passing an Agent Lib named jdwp to the JVM running Tomcat. The jdwp is a JVM specific, optional implementation of the JDWP (Java Debug Wire Protocol) that is used for defining communication between a debugger and a running JVM. It’s implementation, if present is supplied as a native library of the JVM as either jdwp.so or jdwp.dll
So what does it do? In simple terms, the jdwp agent we pass is basically serving the function of being a link between the JVM instance running an application and a Debugger (which can be located either remote or local). Since it is an Agent Library, It does have the ability to intercept the running code, create a bridge between the JVM and a debugger, and have the functionality of a debugger applied on the JVM. Since in the JVM architecture, the debugging functionality is not found within the JVM itself but is abstracted away into external tools (that are aptly referred to as debuggers), these tools can either reside on the local machine running the JVM being debugged or be run from am external machine. It is this de-coupled, modular architecture that allows us to have a JVM running on a remote machine and using the JDWP, have a remote debugger be able to communicate with it.
That is how Eclipse debugger works in short.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With