调试一个java应用程序,而不用调试参数启动JVM [英] Debug a java application without starting the JVM with debug arguments

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

问题描述

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

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

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



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



只是为了澄清,不可能使用像jdb这样的工具来附加到已经运行的JVM,除非它们被启动调试模式



从JVM手册页


另一种方式使用jdb是通过将其附加到已经运行
的Java VM。要使用jdb调试
的虚拟机必须以
开头,以下选项:



解决方案

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



用法:

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

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


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?

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?

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

from the JVM man page

Another way to use jdb is by attaching it to a Java VM that is already running. A VM that is to be debugged with jdb must be started with the following options:

解决方案

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.

Usage:

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

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

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

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