在不使用调试参数启动 JVM 的情况下调试 Java 应用程序 [英] Debug a java application without starting the JVM with debug arguments

查看:29
本文介绍了在不使用调试参数启动 JVM 的情况下调试 Java 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常要将调试器附加到正在运行的 jvm,您需要使用以下参数启动 jvm:

Normally to attach a debuger to a running jvm you would need start the jvm with arguments such as the following:

> java -Xdebug -Xrunjdwp:transport=dt_socket,address=1000,server=y,suspend=n

现在如果我想调试一个没有在调试模式下启动的进程,我该怎么做?

Now if I want to debug a process that wasn't started in debug mode, what can I do?

当生产系统(即在没有调试参数的情况下启动)表现出随机"(我松散地使用该术语)错误时,就会出现这种情况.所以我无法使用适当的参数重新启动 jvm,因为没有人知道如何再次重现该错误.这种情况是不是就不能附加到JVM了?

This situation arrises when a production system (i.e. started without debug args) exhibits a 'random' (I use the term loosely) bug. So I can't restart the jvm with the appropriate arguments, because nobody knows how to reproduce the bug again. Is it impossible to attach to the JVM in this situation?

澄清一下,除非在调试模式下启动,否则不可能使用 jdb 之类的工具附加到已经运行的 JVM

Just to clarify it is not possible to use tools like jdb to attach to already running JVMs unless they were started in debug mode

来自 JVM 手册页

另一种使用 jdb 的方法是将它附加到一个 Java VM已经运行.一个虚拟机用 jdb 调试必须以以下选项:

推荐答案

您可以使用 jsadebugd (JDK) 将调试服务器附加到进程(在 Windows 上可用 调试适用于 Windows 的工具).它被标记为实验性的,因此您可能想先在测试机器上试用.

You may be able to use jsadebugd (JDK) to attach a debug server to the process (available on Windows with the Debugging Tools for Windows). It is marked as experimental, so you may want to try it out on a test machine first.

用法:

jsadebugd <pid>
jdb -connect sun.jvm.hotspot.jdi.SADebugServerAttachingConnector:debugServerName=localhost

可以使用 jdb -listconnectors 找到带有 arg 的连接器名称.

The connector name withe arg can be found using jdb -listconnectors.

这篇关于在不使用调试参数启动 JVM 的情况下调试 Java 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆