对运行停止Crash问题进行分析时,可通过addr2line来对backtrace进行问题定位。如下以蓝牙停止运行为例:
蓝牙接收文件概率性出现“蓝牙共享停止运行”,打印Logcat如下:
--------- beginning of crash
01-18 16:53:36.984 1245 1271 F libc : system/bt/hci/src/hci_hal_h4.c:241: event_uart_has_bytes: assertion "false && "Unknown HCI message type"" failed
01-18 16:53:36.986 625 625 D PhoneStatusBar: disable: < expand ICONS alerts SYSTEM_INFO back HOME* RECENT* clock SEARCH* quick_settings >
01-18 16:53:36.987 1245 1271 F libc : Fatal signal 6 (SIGABRT), code -6 in tid 1271 (bluetooth wake)
01-18 16:53:36.991 194 194 W : debuggerd: handling request: pid=1245 uid=1002 gid=1002 tid=1271
01-18 16:53:37.240 625 861 D GRALLOC-ROCKCHIP: enter, w : 1366, h : 768, format : 0x1, usage : 0xb00.
01-18 16:53:37.306 1417 1417 F DEBUG : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
01-18 16:53:37.308 1417 1417 F DEBUG : Build fingerprint: 'Android/rk3288/rk3288:7.1.2/NHG47K/user.aaa.20181026.141547:user/release-keys'
01-18 16:53:37.309 1417 1417 F DEBUG : Revision: '0'
01-18 16:53:37.310 1417 1417 F DEBUG : ABI: 'arm'
01-18 16:53:37.312 1417 1417 F DEBUG : pid: 1245, tid: 1271, name: bluetooth wake >>> com.android.bluetooth <<<
01-18 16:53:37.315 1417 1417 F DEBUG : signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
01-18 16:53:37.387 1417 1417 F DEBUG : Abort message: 'system/bt/hci/src/hci_hal_h4.c:241: event_uart_has_bytes: assertion "false && "Unknown HCI message type"" failed'
01-18 16:53:37.388 1417 1417 F DEBUG : r0 00000000 r1 000004f7 r2 00000006 r3 00000008
01-18 16:53:37.389 1417 1417 F DEBUG : r4 8a693978 r5 00000006 r6 8a693920 r7 0000010c
01-18 16:53:37.389 1417 1417 F DEBUG : r8 00000000 r9 8a6934b0 sl 9862adb0 fp 9db9333c
01-18 16:53:37.390 1417 1417 F DEBUG : ip 00000000 sp 8a693410 lr a5ed8857 pc a5edb0c0 cpsr 600f0010
01-18 16:53:37.523 1417 1417 F DEBUG :
01-18 16:53:37.523 1417 1417 F DEBUG : backtrace:
01-18 16:53:37.524 1417 1417 F DEBUG : #00 pc 0004a0c0 /system/lib/libc.so (tgkill+12)
01-18 16:53:37.525 1417 1417 F DEBUG : #01 pc 00047853 /system/lib/libc.so (pthread_kill+34)
01-18 16:53:37.526 1417 1417 F DEBUG : #02 pc 0001d8b5 /system/lib/libc.so (raise+10)
01-18 16:53:37.526 1417 1417 F DEBUG : #03 pc 00019401 /system/lib/libc.so (__libc_android_abort+34)
01-18 16:53:37.527 1417 1417 F DEBUG : #04 pc 00017048 /system/lib/libc.so (abort+4)
01-18 16:53:37.527 1417 1417 F DEBUG : #05 pc 0001b8b3 /system/lib/libc.so (__libc_fatal+22)
01-18 16:53:37.528 1417 1417 F DEBUG : #06 pc 000195fb /system/lib/libc.so (__assert2+18)
01-18 16:53:37.528 1417 1417 F DEBUG : #07 pc 0007dc15 /system/lib/hw/bluetooth.default.so
01-18 16:53:37.529 1417 1417 F DEBUG : #08 pc 000e55b3 /system/lib/hw/bluetooth.default.so
01-18 16:53:37.530 1417 1417 F DEBUG : #09 pc 000e637b /system/lib/hw/bluetooth.default.so
01-18 16:53:37.530 1417 1417 F DEBUG : #10 pc 00047323 /system/lib/libc.so (_ZL15__pthread_startPv+22)
01-18 16:53:37.530 1417 1417 F DEBUG : #11 pc 00019e5d /system/lib/libc.so (__start_thread+6)
01-18 16:53:37.790 625 861 D GRALLOC-ROCKCHIP: enter, w : 1366, h : 768, format : 0x1, usage : 0xb00.
01-18 16:53:37.876 625 625 I Choreographer: Skipped 48 frames! The application may be doing too much work on its main thread.
01-18 16:53:47.010 194 194 E : debuggerd: worker process 1417 timed out
01-18 16:53:47.041 517 675 E NativeCrashListener: Unable to read from debuggerd
01-18 16:53:47.044 194 194 E : debuggerd: killing target 1245
01-18 16:53:47.061 517 535 I BootReceiver: Copying /data/tombstones/tombstone_00 to DropBox (SYSTEM_TOMBSTONE)
01-18 16:53:47.220 625 625 D BluetoothA2dp: Proxy object disconnected
01-18 16:53:47.221 747 747 D BluetoothA2dp: Proxy object disconnected
01-18 16:53:47.227 625 625 D BluetoothPan: BluetoothPAN Proxy object disconnected
01-18 16:53:47.228 625 625 D PanProfile: Bluetooth service disconnected
01-18 16:53:47.229 625 625 D BluetoothInputDevice: Proxy object disconnected
01-18 16:53:47.230 625 625 D HidProfile: Bluetooth service disconnected
一、在SDK里查找可用的add2line,执行查看命令:
aaa@server:~/rk3288-7.1-w/Android$ find -name *addr2line
...
./prebuilts/gcc/linux-x86/arm/arm-eabi-4.8/bin/arm-eabi-addr2line
./prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/bin/x86_64-linux-addr2line (选择使用这个)
./prebuilts/gcc/linux-x86/host/x86_64-w64-mingw32-4.8/bin/x86_64-w64-mingw32-addr2line
...
aaa@server:~/rk3288-7.1-w/Android$
二、查看Logcat中与BT相关的crash backtrace
01-18 16:53:37.528 F/DEBUG ( 1417): #07 pc 0007dc15 /system/lib/hw/bluetooth.default.so
01-18 16:53:37.529 F/DEBUG ( 1417): #08 pc 000e55b3 /system/lib/hw/bluetooth.default.so
01-18 16:53:37.530 F/DEBUG ( 1417): #09 pc 000e637b /system/lib/hw/bluetooth.default.so
要想找出以上三个错误信息,得先在源码out目录下找到bluetooth.default.so这个库(),执行以下命令:
aaa@server:~/rk3288-7.1-w/Android$ find ./out/target/product/rk3288/ -name bluetooth.default.so
./out/target/product/rk3288/symbols/system/lib/hw/bluetooth.default.so
./out/target/product/rk3288/system/lib/hw/bluetooth.default.so
./out/target/product/rk3288/obj/lib/bluetooth.default.so
...
aaa@server:~/rk3288-7.1-w/Android$
有用的信息是带symbols目录的这行 ./out/target/product/rk3288/symbols/system/lib/hw/bluetooth.default.so
三、根据第一步的addr2line和第二步的bluetooth.default.so库,执行以下命令(addr2line -e so绝对路径 错误地址)可以查到源码出错的位置:
aaa@server1:~/rk3288-7.1-w/Android$ ./prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/bin/x86_64-linux-addr2line -e /home/aaa/rk3288-7.1-w/Android/out/target/product/rk3288/symbols/system/lib/hw/bluetooth.default.so 0007dc15
/proc/self/cwd/system/bt/hci/src/hci_hal_h4.c:214
aaa@server:~/rk3288-7.1-w/Android$
在SDK源码里找到system/bt/hci/src/hci_hal_h4.c:214,hci_hal_h4.c文件第214行,即是出错位置。
针对报错位置做相应处理。