JNI 崩溃日志:使用堆栈跟踪输出确定源文件行

JNI crashlog: source file line determination with stacktrace output

当本机代码在用户设备上崩溃时,google Play 开发者控制台的崩溃和 ANR 部分会提供此类反馈:

*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: '...'
Revision: '...'
ABI: 'arm'
pid: ...., tid: ...., name: ....  >>> com.package <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0
<registers>
backtrace:
    #00 pc 003ba9be  /data/app/com.package/lib/arm/libx.so (sl_setVolumeSound(unsigned int, float)+105)
    #01 pc 003b9db7  /data/app/com.package/lib/arm/libx.so (Audio::setVolumeSound(unsigned int, float)+106)

到目前为止,还不错。但是如何从字节码偏移量(?)中确定源代码行,例如上面示例输出中 sl_setVolumeSound 函数的 +105?

我特别希望有一个解决方案可以完全在 macosx 命令行中运行,无需使用 IDE。

ndk-stack is specially suited for this purpose. Note, that to get it working you need a non-stripped versions of your native libraries. More details here.