用于在正在运行的 JVM 中打开调试的 Java API
是否有一种编程方式可以在运行的 JVM 实例中打开调试?我正在寻找一个 API,它可以使运行中的 JVM 成为调试服务器。该 API 的作用相当于
-Xdebug -Xrunjdwp:transport=dt_socket,address=<host:port>,server=y,suspend=n.
Is there a programmatic way to turn on debugging in a running JVM instance? I am looking for an API that would make a running JVM, a debug server. The API would do the equivalent of
-Xdebug -Xrunjdwp:transport=dt_socket,address=<host:port>,server=y,suspend=n.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 Visual VM 连接到任何正在运行的 JVM。请务必下载 1.3.2 版本并安装所有插件。
You can attach to any running JVM using Visual VM. Be sure to download version 1.3.2 and install all the plugins.
提问者提到的调试端口用于源代码调试,例如使用 Eclipse 调试器。 VisualVM 的端口是 JMX 端口,它采用一组不同的 JVM 选项。但也有例外:JRockit 的任务控制使用 jdwp 端口而不是 JMX 端口。
是的,您可以在代码中动态加载 JMX 调试器。它很复杂,但我相信 OSGI 可以动态加载它。 例如,这里是执行此操作的 Jetty 项目的引用。
The debug port that the questioner refers to is for source code debugging, such as with an Eclipse debugger. The port for VisualVM is the JMX port, which takes a different set of JVM options. There are exceptions though: Mission Control for JRockit uses the jdwp port rather than the JMX port.
And yes, you can dynamically load the JMX debugger in code. Its complicated but OSGI can load this dynamically I believe. For example, here is a reference to Jetty project doing this.
这是不可能的。 JVM 必须从一开始就知道它处于调试模式。它运行速度稍慢,但为外部进程提供调试信息和断点,这在 JVM 已经启动时是不可能的。
This is not possible. The JVM has to know from the beginning that it is in debug mode. It runs a bit slower then but provides external processes with debug information and breakpoints which is not possible when the JVM already has been startet.