Android开发学习如何进行debuggerd
程序员文章站
2022-03-23 22:46:44
之前是命令行,simpleperf也支持python的...
1.help
raphael:/ # debuggerd -h
usage: debuggerd [-bj] PID
-b, --backtrace just a backtrace rather than a full tombstone
-j collect java traces
tombstone意思是墓碑,搜了下Android下的含义
当一个动态库(native 程序)开始执行时,系统会注册一些连接到 debuggerd 的 signal handlers,当系统 crash 的时候,会保存一个 tombstone 文件到/data/tombstones目录下(Logcat中也会有相应的信息),文件的确就像墓碑一样记录了死亡了的进程的基本信息(例如进程的进程号,线程号),死亡的地址(在哪个地址上发生了 Crash),死亡时的现场是什么样的(记录了一系列的堆栈调用信息)等等。
2.执行
2.1 -b
打印某时刻该进程所有线程堆栈
1|raphael:/ # debuggerd -b 788
----- pid 788 at 2020-11-28 23:52:20 -----
Cmd line: /vendor/bin/hw/android.hardware.wifi@1.0-service
ABI: 'arm64'
"wifi@1.0-servic" sysTid=788
#00 pc 00000000000d1c84 /apex/com.android.runtime/lib64/bionic/libc.so (__ioctl+4) (BuildId: f7f8284982bf528e628529b3fc094df1)
#01 pc 000000000008c1a4 /apex/com.android.runtime/lib64/bionic/libc.so (ioctl+132) (BuildId: f7f8284982bf528e628529b3fc094df1)
#02 pc 0000000000088538 /system/lib64/vndk-sp-29/libhidlbase.so (android::hardware::IPCThreadState::getAndExecuteCommand()+464) (BuildId: 3684cb22817553ecd1e96bdb428ff263)
#03 pc 0000000000089990 /system/lib64/vndk-sp-29/libhidlbase.so (android::hardware::IPCThreadState::joinThreadPool(bool)+96) (BuildId: 3684cb22817553ecd1e96bdb428ff263)
#04 pc 000000000001e444 /vendor/bin/hw/android.hardware.wifi@1.0-service (main+1012) (BuildId: 677781c57b9af9a2d84aa05440675ffe)
#05 pc 000000000007e898 /apex/com.android.runtime/lib64/bionic/libc.so (__libc_init+108) (BuildId: f7f8284982bf528e628529b3fc094df1)
"wifi@1.0-servic" sysTid=3115
#00 pc 00000000000d2ae4 /apex/com.android.runtime/lib64/bionic/libc.so (recvfrom+4) (BuildId: f7f8284982bf528e628529b3fc094df1)
#01 pc 0000000000030644 /vendor/lib64/liblowi_client.so (qc_loc_fw::MessageQueueClientImpl::run_block(qc_loc_fw::MessageQueueServiceCallback*)+300) (BuildId: 94bf550e27e8829c48980f8ab3569c59)
#02 pc 00000000000271bc /vendor/lib64/liblowi_client.so (qc_loc_fw::LOWIClientReceiver::run()+364) (BuildId: 94bf550e27e8829c48980f8ab3569c59)
#03 pc 00000000000203bc /vendor/lib64/liblowi_wifihal.so (qc_loc_fw::ThreadImpl::thread_func(void*)+20) (BuildId: 90e54521a5a5db7590ecda83eef4dced)
#04 pc 00000000000e7470 /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+36) (BuildId: f7f8284982bf528e628529b3fc094df1)
#05 pc 000000000008522c /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+64) (BuildId: f7f8284982bf528e628529b3fc094df1)
"wifi@1.0-servic" sysTid=18284
#00 pc 00000000000d1cc4 /apex/com.android.runtime/lib64/bionic/libc.so (__ppoll+4) (BuildId: f7f8284982bf528e628529b3fc094df1)
#01 pc 000000000008e1b8 /apex/com.android.runtime/lib64/bionic/libc.so (poll+88) (BuildId: f7f8284982bf528e628529b3fc094df1)
#02 pc 000000000002c03c /vendor/lib64/libwifi-hal.so (wifi_event_loop.cfi+268) (BuildId: dfab180e09b121e8511a774224b6353b)
#03 pc 0000000000043fe4 /vendor/bin/hw/android.hardware.wifi@1.0-service (android::hardware::wifi::V1_3::implementation::legacy_hal::WifiLegacyHal::runEventLoop()+56) (BuildId: 677781c57b9af9a2d84aa05440675ffe)
#04 pc 0000000000049d28 /vendor/bin/hw/android.hardware.wifi@1.0-service (BuildId: 677781c57b9af9a2d84aa05440675ffe)
#05 pc 00000000000e7470 /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+36) (BuildId: f7f8284982bf528e628529b3fc094df1)
#06 pc 000000000008522c /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+64) (BuildId: f7f8284982bf528e628529b3fc094df1)
----- end 788 -----
2.2 -j
和-b对应,-j是用来dump java进程的,我dump了下Settings
"main" prio=5 tid=1 Native
| group="main" sCount=1 dsCount=0 flags=1 obj=0x766cd3c8 self=0x763b964000
| sysTid=25740 nice=-10 cgrp=default sched=0/0 handle=0x763cec9ed0
| state=S schedstat=( 176316273947 14423639070 92134 ) utm=16501 stm=1130 core=2 HZ=100
| stack=0x7fc18e3000-0x7fc18e5000 stackSize=8192KB
| held mutexes=
kernel: (couldn't read /proc/self/task/25740/stack)
native: #00 pc 00000000000d1b48 /apex/com.android.runtime/lib64/bionic/libc.so (__epoll_pwait+8)
native: #01 pc 00000000000180bc /system/lib64/libutils.so (android::Looper::pollInner(int)+144)
native: #02 pc 0000000000017f8c /system/lib64/libutils.so (android::Looper::pollOnce(int, int*, int*, void**)+56)
native: #03 pc 000000000013e2dc /system/lib64/libandroid_runtime.so (android::android_os_MessageQueue_nativePollOnce(_JNIEnv*, _jobject*, long, int)+44)
at android.os.MessageQueue.nativePollOnce(Native method)
at android.os.MessageQueue.next(MessageQueue.java:336)
at android.os.Looper.loop(Looper.java:181)
at android.app.ActivityThread.main(ActivityThread.java:7567)
at java.lang.reflect.Method.invoke(Native method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
截取了一小段,看起来和应用anr打印出来的trace很像
2.3 全
raphael:/ # debuggerd 21358
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'Xiaomi/raphael/raphael:10/QKQ1.190825.002/20.03.18:user/test-keys'
Revision: '0'
ABI: 'arm64'
Timestamp: 2020-11-28 23:57:14+0800
pid: 21358, tid: 21358, name: wifi@1.0-servic >>> /vendor/bin/hw/android.hardware.wifi@1.0-service <<<
uid: 1010
signal 35 (<debuggerd signal>), code -1 (SI_QUEUE from pid 21551, uid 0), fault addr --------
x0 0000000000000005 x1 00000000c0306201 x2 0000007fc85db838 x3 0000000000000000
x4 0000000000000000 x5 0000000000000000 x6 0000000000000000 x7 000000000000002c
x8 000000000000001d x9 0000007fc85db758 x10 0000007fc85db720 x11 0000007fc85db758
x12 0000007fc85db7a0 x13 ffffffffffffffff x14 fffffffffffff54f x15 0000007d5a0452d0
x16 0000007dda8ba5b0 x17 0000007dda9b5120 x18 0000007ddc62a000 x19 0000007ddb60e018
x20 0000007d5a02f130 x21 0000007d5a02f0a8 x22 0000007d5a00d458 x23 00000000fffffff7
x24 0000007ddb60e018 x25 0000007fc85db838 x26 0000007d5a00d430 x27 0000000000000000
x28 0000000000000000 x29 0000007fc85db790
sp 0000007fc85db6a0 lr 0000007dda9b51a8 pc 0000007dda9fac84
backtrace
stack
memory near x1:
--------- tail end of log system
--------- tail end of log main
open files:
--------- log system
--------- log main
会把堆栈和log都打印出来,挺好用的,可以看某一时刻的情况
感觉比较适合定位卡死、死循环的问题
本文地址:https://blog.csdn.net/sinat_20059415/article/details/110296636
推荐阅读
-
Android开发之图形图像与动画(一)Paint和Canvas类学习
-
解析Android开发优化之:从代码角度进行优化的技巧
-
Android NDK开发系列教程:如何调用及传参方法
-
Android开发中如何使用BottomTabBar实现底部导航页
-
详解如何使用Android Studio开发Gradle插件
-
Android开发学习之WallPaper设置壁纸详细介绍与实例
-
Android程序开发如何处理图像格式类及图像转换
-
Android开发笔记之:如何屏蔽Button setClickable与setEnabled
-
Android开发笔记之:如何安全中止一个自定义线程Thread的方法
-
解决Fedora14下eclipse进行android开发,ibus提示没有输入窗口的方法详解