Java验尸调试? [英] Java post-mortem debugging?

查看:109
本文介绍了Java验尸调试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在Java中进行验证(或异常后)调试会话?解决方案(如果没有解决方案已经有)?

Is it possible to have a post-mortem ( or post-exception ) debugging session in Java ? What would the workarounds be ( if there isn't a solution for this already ) ?

推荐答案

您可以将调试器附加到java进程,并在收到特定的
异常时设置断点。这是你需要的吗?

You can attach the debugger to a java process and set a breakpoint when a specific exception is received. Is this what you need?


http://java.sun.com/j2se/1.5.0/docs/tooldocs/solaris/jdb.html


当一个异常发生在哪里
没有一个catch语句任何地方
一个Java程序的堆栈,Java
运行时通常会转储一个例外
trace并退出。但是,当在
jdb下运行时,该异常是
被视为不可恢复的
断点,并且jdb停止在
违规指令。如果该类
用-g选项编译,则
实例和局部变量可以打印
,以确定
异常的原因。

When an exception occurs for which there isn't a catch statement anywhere up a Java program's stack, the Java runtime normally dumps an exception trace and exits. When running under jdb, however, that exception is treated as a non-recoverable breakpoint, and jdb stops at the offending instruction. If that class was compiled with the -g option, instance and local variables can be printed to determine the cause of the exception.

可以使用任何IDE(如Eclipse)设置此类型的断点。使用eclipse,您也可以在特定的异常类型上设置一个断点,即使它在正常代码中被捕获。

This type of breakpoints can be set with any IDE, such as Eclipse. Using eclipse you can also set a breakpoint on a specific exception type, even if it is caught in the normal code.

如果你有像多线程服务器的运行,并且为客户端服务的其中一个线程会引发未处理的异常,那么您将可以检查调试器,看看会发生什么。我不认为这是生产的东西,但是在测试时肯定有帮助。

If you have something like a multi-threaded server running, and one of the threads servicing a client throws an unhandled exception, then you would be able to check the debugger and see what happens. I don't think this is something for production, but definitively helps when testing.

应用程序不必从调试器运行,但可以使用调试选项作为参数:

The application does not have to run from the debugger, but it can be launched with the debug options as arguments:

-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=XXXX

应用程序正常运行,但当断点被击中时切换到解释模式,至少在更现代版本的JVM。所以性能不受影响。

The application runs normally, but switches into "interpreted" mode when a breakpoint is hit, at least in more modern versions of the JVM. So the performance is not affected.

查看有关 HotSpot VM的全速调试


全速调试

Full Speed Debugging

Java HotSpot VM现在使用
全速调试。在以前的
版本的VM中,当调试启用
时,使用
执行的程序只有解释器。现在,HotSpot
技术的全部
性能优势可用于程序,
甚至编译代码。改进的
性能允许长时间运行的
程序更容易调试。
它还允许测试以
全速进行。一旦有
异常,调试器启动
完全可见的代码源。

The Java HotSpot VM now uses full-speed debugging. In previous version of the VM, when debugging was enabled, the program executed using only the interpreter. Now, the full performance advantage of HotSpot technology is available to programs, even with compiled code. The improved performance allows long-running programs to be more easily debugged. It also allows testing to proceed at full speed. Once there is an exception, the debugger launches with full visibility to code sources.

这篇关于Java验尸调试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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