松鼠Mike的树洞 -- Make Each Day Count
  • 排序
  • 选择时间

如何解决gdb调试jvm是的Segmentation Fault问题

发布日期: 2016-04-08更新日期:2016-04-08

在用gdb调试包含jvm的C++程序时,在走到jvm相关的语句时会出现Segmentation Fault的报错导致调试是无法进行;但是在实际执行的过程中却没有错误。
经过一番查询,在http://stackoverflow.com/questions/27241575/why-does-java-app-crash-in-gdb-but-runs-normally-in-real-life中找到了解决方案。

Because it doesn't actually crash.
Java uses speculative loads. If a pointer points to addressable memory, the load succeeds. Rarely the pointer does not point to addressable memory, and the attempted load generates SIGSEGV ... which java runtime intercepts, makes the memory addressable again, and restarts the load instruction.
When debugging java programs, one has to generally do this:
(gdb) handle SIGSEGV nostop noprint pass
Unfortunately, if there is some JNI code involved, and that code SIGSEGVs, GDB will happily ignore that signal as well, resulting in the death of inferior (being debugged) process. I have not found an acceptable solution for that latter problem.