Context
分析日志定位到崩溃对应的代码行
原始日志
11-15 21:09:56.679 2573 2573 F libc : Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 2573 (now.graphicdemo)
11-15 21:09:56.681 210 210 W : debuggerd: handling request: pid=2573 uid=10042 gid=10042 tid=2573
11-15 21:09:56.761 2590 2590 F DEBUG : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
11-15 21:09:56.762 2590 2590 F DEBUG : Build fingerprint: 'Android/rk3399_mid/rk3399_mid:7.1.2/NHG47K/xshuo09190102:userdebug/test-keys'
11-15 21:09:56.762 2590 2590 F DEBUG : Revision: '0'
11-15 21:09:56.762 2590 2590 F DEBUG : ABI: 'arm64'
11-15 21:09:56.762 2590 2590 F DEBUG : pid: 2573, tid: 2573, name: now.graphicdemo >>> com.albertsnow.graphicdemo <<<
11-15 21:09:56.762 2590 2590 F DEBUG : signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0
11-15 21:09:56.762 2590 2590 F DEBUG : x0 0000000000000000 x1 0000000000000000 x2 0000000000000000 x3 0000007119295a00
11-15 21:09:56.762 2590 2590 F DEBUG : x4 0000007ffc721fb8 x5 00000070fe9fb70f x6 0000000000000001 x7 0000000000000000
11-15 21:09:56.762 2590 2590 F DEBUG : x8 0000000000000000 x9 0000007117d854eb x10 0000000000430000 x11 000000711d3a1b30
11-15 21:09:56.762 2590 2590 F DEBUG : x12 00000000000000c4 x13 00000000000000b7 x14 000000711d29bf50 x15 ca7060666c5c8585
11-15 21:09:56.762 2590 2590 F DEBUG : x16 0000007117da0d00 x17 0000007117d69154 x18 0000000000000000 x19 0000007119295a00
11-15 21:09:56.762 2590 2590 F DEBUG : x20 0000007118ca8cb0 x21 0000007119295a00 x22 0000007ffc721dec x23 00000070fe9fb70f
11-15 21:09:56.762 2590 2590 F DEBUG : x24 0000000000000004 x25 8a85e323113882ec x26 0000007119295a98 x27 8a85e323113882ec
11-15 21:09:56.762 2590 2590 F DEBUG : x28 0000000000000001 x29 0000007ffc721ae0 x30 0000007117d69914
11-15 21:09:56.762 2590 2590 F DEBUG : sp 0000007ffc721ac0 pc 0000007117d69170 pstate 0000000020000000
11-15 21:09:56.768 2590 2590 F DEBUG :
11-15 21:09:56.768 2590 2590 F DEBUG : backtrace:
11-15 21:09:56.768 2590 2590 F DEBUG : #00 pc 000000000000e170 /data/app/com.albertsnow.graphicdemo-2/lib/arm64/libnative-lib.so (_ZN7_JNIEnv12NewStringUTFEPKc+28)
11-15 21:09:56.768 2590 2590 F DEBUG : #01 pc 000000000000e910 /data/app/com.albertsnow.graphicdemo-2/lib/arm64/libnative-lib.so
11-15 21:09:56.768 2590 2590 F DEBUG : #02 pc 000000000000e8d8 /data/app/com.albertsnow.graphicdemo-2/lib/arm64/libnative-lib.so (Java_com_albertsnow_graphicdemo_SecondActivity_testException+24)
11-15 21:09:56.768 2590 2590 F DEBUG : #03 pc 00000000003cb7a0 /data/app/com.albertsnow.graphicdemo-2/oat/arm64/base.odex (offset 0x37e000)
使用ndk-stack
- 命令
adb logcat | ndk-stack -sym obj/arm64-v8a
-sym后面是unstripped versions of your app’s shared libraries(未做优化处理的so库)。类似于 混淆后的release包bug栈信息乱码,需要的map文件来去混淆。 - 工作目录
GraphicDemo/app/build/intermediates/cmake/debug(在该目录下运行)
GraphicDemo是我的项目名称,工作目录下有 obj/arm64-v8a/libnative-lib.so
libnative-lib.so是我的so库
arm64-v8a 是机器的CPU架构
********** Crash dump: **********
Build fingerprint: 'Android/rk3399_mid/rk3399_mid:7.1.2/NHG47K/xshuo09190102:userdebug/test-keys'
pid: 2573, tid: 2573, name: now.graphicdemo >>> com.albertsnow.graphicdemo <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0
Stack frame #00 pc 000000000000e170 /data/app/com.albertsnow.graphicdemo-2/lib/arm64/libnative-lib.so (_ZN7_JNIEnv12NewStringUTFEPKc+28): Routine _JNIEnv::NewStringUTF(char const*) at /home/albertsnow/Android/Sdk/ndk-bundle/sysroot/usr/include/jni.h:841
Stack frame #01 pc 000000000000e910 /data/app/com.albertsnow.graphicdemo-2/lib/arm64/libnative-lib.so: Routine func1(_JNIEnv*) at /home/albertsnow/WorkSpace/GraphicDemo/app/src/main/cpp/native-lib.cpp:87
Stack frame #02 pc 000000000000e8d8 /data/app/com.albertsnow.graphicdemo-2/lib/arm64/libnative-lib.so (Java_com_albertsnow_graphicdemo_SecondActivity_testException+24): Routine Java_com_albertsnow_graphicdemo_SecondActivity_testException at /home/albertsnow/WorkSpace/GraphicDemo/app/src/main/cpp/native-lib.cpp:94
Stack frame #03 pc 00000000003cb7a0 /data/app/com.albertsnow.graphicdemo-2/oat/arm64/base.odex (offset 0x37e000)
可以看到就是第87行崩溃的。
其他调用方法
先存log文件,然后过滤
adb logcat > /tmp/foo.txt
ndk-stack -sym obj/arm64-v8a -dump foo.txt