Java远程调试,它在技术上是如何工作的?
我非常喜欢 JVM 的远程调试功能。但我想知道它的内部是如何运作的。
我的假设:它是通过 JVM 功能完成的,其中运行的进程正在下载/使用来自附加远程调试器(如 IDE)的源代码它知道当前堆栈跟踪的行,然后可以跳转到相应的 IDE断点。然后,通过套接字或共享内存(远程调试器的设置)完成堆栈跟踪的通信和应用程序状态的内省。
有任何有趣的链接/资源吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
JVM 的调试功能通过 Java 平台调试器架构 (JPDA )。
JPDA 本身由以下部分组成:
JPDA 架构结构中列出的图表是一个好的起点。其他需要查找的地方是JPDA 页面中列出的指南。
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 调试从所谓的代理开始。
运行已编译的“.class”源代码的 JVM 有一个功能,允许在运行时将外部库(用 Java 或 C++ 编写)注入到 JVM 中。这些外部库称为代理,它们能够修改已运行的 .class 文件的内容。这些代理可以访问 JVM 的功能,而这些功能是无法从 JVM 内运行的常规 Java 代码访问的,并且它们可用于执行有趣的操作,例如注入和修改正在运行的源代码、分析等。一些工具,如 JRebel(使用用于代码的热替换)利用这个功能来实现它们的魔力。
要将代理库传递到 JVM,您可以通过启动参数执行此操作,使用 -
我们实际上将名为 jdwp 的代理库传递到运行 Tomcat 的 JVM。 jdwp 是 JDWP(Java 调试线协议)的 JVM 特定的可选实现,用于定义调试器和正在运行的 JVM 之间的通信。它的实现(如果存在)作为 JVM 的本机库提供为 jdwp.so 或 jdwp.dll
那么它有什么作用呢?简单来说,我们传递的 jdwp 代理基本上提供运行应用程序的 JVM 实例和调试器(可以位于远程或本地)之间的链接的功能。既然它是一个Agent Library,它确实有能力拦截正在运行的代码,在JVM和调试器之间建立桥梁,并具有应用在JVM上的调试器的功能。由于在 JVM 架构中,调试功能不在 JVM 本身内找到,而是被抽象到外部工具(恰当地称为调试器)中,因此这些工具可以驻留在运行正在调试的 JVM 的本地计算机上,也可以运行来自外部机器。正是这种解耦的模块化架构允许我们在远程机器上运行 JVM 并使用 JDWP,让远程调试器能够与其通信。
简而言之,这就是 Eclipse 调试器的工作原理。
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 -
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.
Java 的调试架构称为 JPDA。您可能想阅读 JPDA 文档。特别是演练部分< /a> 给出了 IDE 与 JDI 接口以获取堆栈上的值的示例。
Java's debugging architecture is called JPDA. You probably want to read the JPDA documentation. In particular, the Walk-through section gives an example of an IDE interfacing with the JDI to obtain a value on the stack.