如何在.so库中找到错误的根本原因

时间:2018-03-18 08:22:04

标签: c debugging jvm shared-libraries

我写了一个hook.so文件,用libc.so.6拦截JVM对LD_PRELOAD的调用。但是当我使用截获的JVM在JVM上运行某些应用程序时,它报告了如下错误:

Aborted (core dumped)
vim /home/hs_err_pid635.log
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007fb3e9cd6927, pid=635, tid=0x00007fb3baa8c700
#
# JRE version: OpenJDK Runtime Environment (8.0_151-b12) (build 1.8.0_151- 8u151-b12-0ubuntu0.16.04.2-b12)
# Java VM: OpenJDK 64-Bit Server VM (25.151-b12 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C  [hook.so+0x8927]  find_job+0x33
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

---------------  T H R E A D  ---------------

如何根据信息C [hook.so+0x8927] find_job+0x33找到错误代码行? 谢谢。

1 个答案:

答案 0 :(得分:1)

使用调试信息构建hook.so库:gcc -gclang -g 然后使用-XX:+ShowMessageBoxOnError选项运行JVM。

当JVM下次崩溃时,它会提示您附加调试器。 gdb将在源代码中显示位置,本地变量值等。