1. 程式人生 > >JNI崩潰除錯

JNI崩潰除錯

JNI崩潰了,系統日誌會列印堆疊資訊,所以第一步就是取日誌

adb shell  logcat -v threadtime >>d:/log.txt

然後找到日誌裡面的關鍵字backtrace例如我的日誌是這樣的

12-04 06:14:38.362  3773  3773 F DEBUG   : backtrace:

12-04 06:14:38.363  3773  3773 F DEBUG   :     #00 pc 00014d9a  /data/app/com.cloudtv.xdogact-1/lib/arm/liblocalser.so

12-04 06:14:38.363  3773
3773 F DEBUG : #01 pc 0000d741 /data/app/com.cloudtv.xdogact-1/lib/arm/liblocalser.so (_Z9WriteHeadR4CUrl+472) 12-04 06:14:38.363 3773 3773 F DEBUG : #02 pc 0000e895 /data/app/com.cloudtv.xdogact-1/lib/arm/liblocalser.so (_Z6runSerRVb+1176) 12-04 06:14:38.363 3773 3773 F DEBUG : #03 pc 0000a999 /data/app/com.cloudtv.xdogact-1
/lib/arm/liblocalser.so (_Z5DoSerPv+4)

現在想定位第三行,就是0000d741對應程式碼的位置,就只需要把程式碼填入下面的指令碼進替換,然後執行就OK了

#!/bin/bash
dir=$(pwd)
export PATH=$PATH:/android-ndk-r11c/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/
export PATH=$PATH:/android-ndk-r11c/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin
addr
=0000d741 arm-linux-androideabi-addr2line -e $dir/obj/local/armeabi-v7a/liblocalser.so $addr aarch64-linux-android-addr2line -e $dir/obj/local/arm64-v8a/liblocalser.so $addr