两步使用arm-linux-androideabi-addr2line定位JNI动态库中C代码错误位置
1、使用Android Studio调试APP代码时,出现如下错误,很明显是C代码报错了
1 11-28 15:39:37.197 7208-7208/? A/DEBUG: Build fingerprint: 'Xiaomi/cancro_lte_ct/cancro:6.0.1/MMB29M/6.8.4:user/release-keys' 2 11-28 15:39:37.199 7208-7208/? A/DEBUG: Revision: '0' 3 11-28 15:39:37.200 7208-7208/? A/DEBUG: ABI: 'arm' 4 11-28 15:39:37.203 7208-7208/? A/DEBUG: pid: 29614, tid: 29712, name: shihujiaoserver >>> ruijie.hushihujiaoserver <<< 5 11-28 15:39:37.204 7208-7208/? A/DEBUG: signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr -------- 6 11-28 15:39:37.255 7208-7208/? A/DEBUG: Abort message: 'Invalid address 0x9a2e3928 passed to free: value not allocated' 7 11-28 15:39:37.255 7208-7208/? A/DEBUG: r0 00000000 r1 00007410 r2 00000006 r3 9a2e3978 8 11-28 15:39:37.255 7208-7208/? A/DEBUG: r4 9a2e3980 r5 9a2e3930 r6 00000002 r7 0000010c 9 11-28 15:39:37.255 7208-7208/? A/DEBUG: r8 9fe7f688 r9 b6ca1594 sl 00000001 fp 9a407b55 10 11-28 15:39:37.255 7208-7208/? A/DEBUG: ip 00000006 sp 9a2e31d0 lr b6c6ac51 pc b6c6d040 cpsr 400f0010 11 11-28 15:39:37.272 7208-7208/? A/DEBUG: backtrace: 12 11-28 15:39:37.273 7208-7208/? A/DEBUG: #00 pc 00042040 /system/lib/libc.so (tgkill+12) 13 11-28 15:39:37.273 7208-7208/? A/DEBUG: #01 pc 0003fc4d /system/lib/libc.so (pthread_kill+32) 14 11-28 15:39:37.273 7208-7208/? A/DEBUG: #02 pc 0001c3fb /system/lib/libc.so (raise+10) 15 11-28 15:39:37.273 7208-7208/? A/DEBUG: #03 pc 000195ad /system/lib/libc.so (__libc_android_abort+34) 16 11-28 15:39:37.273 7208-7208/? A/DEBUG: #04 pc 00017500 /system/lib/libc.so (abort+4) 17 11-28 15:39:37.274 7208-7208/? A/DEBUG: #05 pc 0001b00f /system/lib/libc.so (__libc_fatal+16) 18 11-28 15:39:37.274 7208-7208/? A/DEBUG: #06 pc 00055463 /system/lib/libc.so (ifree+202) 19 11-28 15:39:37.274 7208-7208/? A/DEBUG: #07 pc 00058347 /system/lib/libc.so (je_free+374) 20 11-28 15:39:37.274 7208-7208/? A/DEBUG: #08 pc 00099d2f /data/app/ruijie.hushihujiaoserver-1/lib/arm/libserver-jni.so 21 11-28 15:39:37.274 7208-7208/? A/DEBUG: #09 pc 000284db /data/app/ruijie.hushihujiaoserver-1/lib/arm/libserver-jni.so (sqlite3_free+86) 22 11-28 15:39:37.275 7208-7208/? A/DEBUG: #10 pc 00015f0d /data/app/ruijie.hushihujiaoserver-1/lib/arm/libserver-jni.so 23 11-28 15:39:37.275 7208-7208/? A/DEBUG: #11 pc 0001669b /data/app/ruijie.hushihujiaoserver-1/lib/arm/libserver-jni.so (db_init_sysconfig_head+62) 24 11-28 15:39:37.275 7208-7208/? A/DEBUG: #12 pc 000148db /data/app/ruijie.hushihujiaoserver-1/lib/arm/libserver-jni.so (sysconfig_init+10) 25 11-28 15:39:37.275 7208-7208/? A/DEBUG: #13 pc 00024ebf /data/app/ruijie.hushihujiaoserver-1/lib/arm/libserver-jni.so (server_task+874) 26 11-28 15:39:37.276 7208-7208/? A/DEBUG: #14 pc 0003f54f /system/lib/libc.so (_ZL15__pthread_startPv+30) 27 11-28 15:39:37.276 7208-7208/? A/DEBUG: #15 pc 00019c2f /system/lib/libc.so (__start_thread+6) 28 11-28 15:39:37.686 7208-7208/? A/DEBUG: Tombstone written to: /data/tombstones/tombstone_08 29 11-28 15:39:37.686 7208-7208/? E/DEBUG: AM write failed: Broken pipe 30 11-28 15:39:37.699 4412-4963/? E/octvm_klo: read: Unexpected EOF!
2、如何定位呢?可以使用SDK目录中的arm-linux-androideabi-addr2line工具,我本地的目录如下:
**\androidsdk\ndk-bundle\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64\bin\arm-linux-androideabi-addr2line.exe
使用方法:
第一步:cmd到报错的动态库目录下,位置在obj目录下,并非libs目录下生成的so文件,我的目录是**(项目目录)\jnilib\src\main\obj\local\armeabi\**
第二步:使用如下命令定位错误:**\androidsdk\ndk-bundle\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64\bin\arm-linux-androideabi-addr2line -C -f -e libxxx.so 0x#####(address)