在不使用调试参数启动 JVM 的情况下调试 Java 应用程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/376201/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Debug a java application without starting the JVM with debug arguments
提问by hhafez
Normally to attach a debuger to a running jvm you would need start the jvm with arguments such as the following:
通常要将调试器附加到正在运行的 jvm,您需要使用以下参数启动 jvm:
> 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?
当生产系统(即在没有调试参数的情况下启动)表现出“随机”(我松散地使用该术语)错误时,就会出现这种情况。所以我无法使用适当的参数重新启动 jvm,因为没有人知道如何再次重现该错误。在这种情况下是否无法附加到 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
只是为了澄清,除非它们在调试模式下启动,否则不可能使用 jdb 之类的工具附加到已经运行的 JVM
from the JVM man page
来自 JVM 手册页
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:
使用 jdb 的另一种方法是将其附加到已经运行的 Java VM。要使用 jdb 调试的 VM 必须使用以下选项启动:
采纳答案by McDowell
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( JDK) 将调试服务器附加到进程(在 Windows 上可用Debugging Tools for Windows)。它被标记为实验性的,因此您可能想先在测试机器上试用它。
Usage:
用法:
jsadebugd <pid>
jdb -connect sun.jvm.hotspot.jdi.SADebugServerAttachingConnector:debugServerName=localhost
The connector name withe arg can be found using jdb -listconnectors
.
可以使用 找到带有 arg 的连接器名称jdb -listconnectors
。
回答by OscarRyz
You can always use jdb and debug by hand :P
您始终可以使用 jdb 并手动调试:P
回答by sk.
回答by Vijay
回答by potted plant
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
只是为了澄清,不可能使用 jdb 之类的工具附加到已经运行的 JVM > > 除非它们在调试模式下启动
in soviet russia source reads you
在苏联俄罗斯的消息来源读你
jdb -connect sun.jvm.hotspot.jdi.SAPIDAttachingConnector:pid=9426