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

How to find the root cause of a bug in a .so library

我写了一个 hook.so 文件来拦截 JVM 对 libc.so.6LD_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定位到错误代码行? 谢谢你。

构建 hook.so 包含调试信息的库:gcc -gclang -g
然后 运行 JVM with -XX:+ShowMessageBoxOnError option.

下次JVM崩溃时,会提示你附加调试器。 gdb 将显示源代码中的位置、局部变量值等