用于在正在运行的 JVM 中打开调试的 Java API

发布于 2024-11-28 07:27:48 字数 191 浏览 7 评论 0原文

是否有一种编程方式可以在运行的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

瀞厅☆埖开 2024-12-05 07:27:48

您可以使用 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.

絕版丫頭 2024-12-05 07:27:48

提问者提到的调试端口用于源代码调试,例如使用 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.

不乱于心 2024-12-05 07:27:48

这是不可能的。 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文