[置顶] Android中使用addr2line来分析native信息

系统:Ubuntu12.04

手机系统:Android5.0

在Android的开发过程中有会有很多的native bug必须要用addr2line来分析,并且这个工具也非常的好用。下面我们来看看具体的使用。

烧录到手机上的版本和你电脑上的编译出的版本要一致,这个数据才是准确的,才好定位到那一行。

首先找到自己电脑可用的addr2line,用命令find . -name *addr2line。我的如下

@njws19:~/qcom8974_l_row/LINUX/android$ find . -name *addr2line
./external/chromium_org/build/android/pylib/symbols/mock_addr2line
./external/chromium_org/build/android/pylib/symbols/mock_addr2line/mock_addr2line
./prebuilts/gcc/darwin-x86/arm/arm-linux-androideabi-4.8/bin/arm-linux-androideabi-addr2line
./prebuilts/gcc/darwin-x86/arm/arm-eabi-4.8/bin/arm-eabi-addr2line

/prebuilts/gcc/darwin-x86/x86/x86_64-linux-android-4.8/bin/x86_64-linux-android-addr2line
./prebuilts/gcc/darwin-x86/mips/mipsel-linux-android-4.8/bin/mipsel-linux-android-addr2line
./prebuilts/gcc/darwin-x86/mips/mips64el-linux-android-4.8/bin/mips64el-linux-android-addr2line
./prebuilts/gcc/darwin-x86/mips/mips64el-linux-android-4.9/bin/mips64el-linux-android-addr2line
./prebuilts/gcc/darwin-x86/aarch64/aarch64-linux-android-4.8/bin/aarch64-linux-android-addr2line
./prebuilts/gcc/darwin-x86/aarch64/aarch64-linux-android-4.9/bin/aarch64-linux-android-addr2line
./prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.8/bin/arm-linux-androideabi-addr2line
./prebuilts/gcc/linux-x86/arm/arm-eabi-4.8/bin/arm-eabi-addr2line
./prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.8/bin/x86_64-linux-android-addr2line
./prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.9/bin/x86_64-linux-android-addr2line
./prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.6/bin/x86_64-linux-addr2line
./prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.8/bin/x86_64-linux-addr2line
./prebuilts/gcc/linux-x86/host/x86_64-w64-mingw32-4.8/bin/x86_64-w64-mingw32-addr2line
./prebuilts/gcc/linux-x86/mips/mipsel-linux-android-4.8/bin/mipsel-linux-android-addr2line
./prebuilts/gcc/linux-x86/mips/mips64el-linux-android-4.8/bin/mips64el-linux-android-addr2line
./prebuilts/gcc/linux-x86/mips/mips64el-linux-android-4.9/bin/mips64el-linux-android-addr2line
./prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.8/bin/aarch64-linux-android-addr2line
./prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin/aarch64-linux-android-addr2line
./prebuilts/tools/gcc-sdk/addr2line

你自己随便找一个可用的addr2line使用,我这里选用的是./prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.6/bin/x86_64-linux-addr2line

 

首先是在电脑上编译出一个eng版本,烧录到手机,在测试或调试的过程中出错了,查看出错信息如下:

 

02-13 14:56:12.140 6180 11596 F libc : Fatal signal 6 (SIGABRT), code -6 in tid 11596 (pool_albumlabel)
02-13 14:56:12.149 4549 4579 D ForegroundUtils: Process died; UID 1000 PID 7721
02-13 14:56:12.149 4549 4579 D ForegroundUtils: Foreground changed, PID: 7721 UID: 1000 foreground: false
02-13 14:56:12.149 4549 4579 D ForegroundUtils: Foreground UID/PID combinations:
02-13 14:56:12.149 4549 4579 D ForegroundUtils: UID: 10031 PID: 6180
02-13 14:56:12.154 6180 11587 E wwf5 : onDrawFrame end
02-13 14:56:12.171 6180 11587 E wwf5 : onDrawFrame end
02-13 14:56:12.185 6180 11587 E wwf5 : onDrawFrame end
02-13 14:56:12.189 298 399 I ThermalEngine: Sensor:tsens_tz_sensor6:77000 mC
02-13 14:56:12.208 275 275 I DEBUG : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
02-13 14:56:12.208 275 275 I DEBUG : Build fingerprint: 'Lenovo/kingdom_row/kingdom_row:5.0.2/LRX22G/K920_S205_150205_ROW:eng/release-keys'
02-13 14:56:12.208 275 275 I DEBUG : Revision: '0'
02-13 14:56:12.208 275 275 I DEBUG : ABI: 'arm'
02-13 14:56:12.208 275 275 I DEBUG : pid: 6180, tid: 11596, name: pool_albumlabel >>> com.xxxx.scg <<<
02-13 14:56:12.208 275 275 I DEBUG : signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
02-13 14:56:12.245 275 275 I DEBUG : r0 00000000 r1 00002d4c r2 00000006 r3 00000000
02-13 14:56:12.245 275 275 I DEBUG : r4 777cddb8 r5 00000006 r6 0000000c r7 0000010c
02-13 14:56:12.245 275 275 I DEBUG : r8 00000004 r9 00000cc0 sl 00000000 fp 00000000
02-13 14:56:12.245 275 275 I DEBUG : ip 00002d4c sp 777cb338 lr b6f510a1 pc b6f7404c cpsr 600f0010
02-13 14:56:12.245 275 275 I DEBUG :
02-13 14:56:12.245 275 275 I DEBUG : backtrace:
02-13 14:56:12.245 275 275 I DEBUG : #00 pc 0003704c /system/lib/libc.so (tgkill+12)
02-13 14:56:12.245 275 275 I DEBUG : #01 pc 0001409d /system/lib/libc.so (pthread_kill+52)
02-13 14:56:12.245 275 275 I DEBUG : #02 pc 00014cbb /system/lib/libc.so (raise+10)
02-13 14:56:12.245 275 275 I DEBUG : #03 pc 00011511 /system/lib/libc.so (__libc_android_abort+36)
02-13 14:56:12.245 275 275 I DEBUG : #04 pc 0000fc94 /system/lib/libc.so (abort+4)
02-13 14:56:12.246 275 275 I DEBUG : #05 pc 0014a1e7 /system/lib/libskia.so (sk_throw()+2)
02-13 14:56:12.246 275 275 I DEBUG : #06 pc 0014a21d /system/lib/libskia.so (sk_malloc_flags(unsigned int, unsigned int)+20)
02-13 14:56:12.246 275 275 I DEBUG : #07 pc 000dd0a5 /system/lib/libskia.so
02-13 14:56:12.246 275 275 I DEBUG : #08 pc 0013b3d5 /system/lib/libskia.so (SkPNGImageDecoder::onDecodeSubset(SkBitmap*, SkIRect const&)+604)
02-13 14:56:12.246 275 275 I DEBUG : #09 pc 00137553 /system/lib/libskia.so (SkImageDecoder::decodeSubset(SkBitmap*, SkIRect const&, SkColorType)+14)
02-13 14:56:12.246 275 275 I DEBUG : #10 pc 0008e383 /system/lib/libandroid_runtime.so
02-13 14:56:12.246 275 275 I DEBUG : #11 pc 0000d189 /data/dalvik-cache/arm/system@[email protected]

 

如果你想找这行错误  02-13 14:56:12.246 275 275 I DEBUG : #08 pc 0013b3d5 /system/lib/libskia.so (SkPNGImageDecoder::onDecodeSubset(SkBitmap*, SkIRect const&)+604)

 

出错代码信息可以在电脑上(在你编译系统的android目录)查找:libskia.so

查找结果如下

@njws19:~/qcom8974_l_row/LINUX/android/out/target$ find  -name libskia.so
./product/kingdom_row/obj/lib/libskia.so
./product/kingdom_row/obj/SHARED_LIBRARIES/libskia_intermediates/LINKED/libskia.so
./product/kingdom_row/obj/PACKAGING/target_files_intermediates/kingdom_row-target_files-K920_S204_150127_ROW/SYSTEM/lib/libskia.so
./product/kingdom_row/obj/PACKAGING/target_files_intermediates/kingdom_row-target_files-K920_S205_150205_ROW/SYSTEM/lib/libskia.so
./product/kingdom_row/symbols/system/lib/libskia.so
./product/kingdom_row/system/lib/libskia.so

有用的信息是这行,带有symbols字样的 ./product/kingdom_row/symbols/system/lib/libskia.so
这样就可以使用addr2line来查找出错的文件行数,

@njws19:~/qcom8974_l_row/LINUX/android$ ./prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.6/bin/x86_64-linux-addr2line -e ../../../qcom8974_l_row/LINUX/android/out/target/product/kingdom_row/symbols/system/lib/libskia.so 0013b3d5
/home/xxx/qcom8974_l_row/LINUX/android/external/skia/src/images/SkImageDecoder_libpng.cpp:907

 

错误在SkImageDecoder_libpng.cpp:907行

 

你可能感兴趣的:([置顶] Android中使用addr2line来分析native信息)