您的位置:首页 > 移动开发 > Android开发

android debug

2015-07-31 20:54 537 查看

android app 问题分析方法

Force close: 会在main log中有FATAL EXCEPTION
ANR会有trace文件生成
tombstone一般是由Dalvik错误、状态监视调试器、C层代码以及libc的一些问题导致的

1. trace文件生成

命令:kill -3 pid
保存路径:/data/anr/traces.txt
包含的信息:包含所有的java和native线程的堆栈
作用:

怀疑会有线程卡死,比如ANR的时候,多打印几次trace,如果调用堆栈一直不变,证明有卡死。
分析binder调用线程,里面会有类似transact、onTransact、talkWithDriver的调用



2. kernel log

root@:/ # dmesg

root@:/ # cat /proc/kmsg

root@:/ # cat /proc/kmsg > /sdcard/kernel_log.txt &

root@:/ # cat /proc/sys/kernel/printk
7       4       1       7
(7=Current level, 4=Default level, 1=Minimum level, 7=Boot up level)

If you want to see all logs in the kernel log then echo “8” to the printk node.
To see only the super-critical messages echo “1”.

貌似日志级别不影响/proc/kmsg和dmesg

3. tombstone

内核在加载可执行映像时,会先执行/system/bin/linker(参考android linker相关的资料),在linker中设置进程的信号处理函数。信号如下:

sigaction(SIGABRT, &action, NULL);
sigaction(SIGBUS, &action, NULL);
sigaction(SIGFPE, &action, NULL);
sigaction(SIGILL, &action, NULL);
sigaction(SIGPIPE, &action, NULL);
sigaction(SIGSEGV, &action, NULL);
#if defined(SIGSTKFLT)
sigaction(SIGSTKFLT, &action, NULL);
#endif
sigaction(SIGTRAP, &action, NULL);


时序图如下:



debuggerd,位置system/core/debuggerd/debuggerd.c

debuggerd收到某个进程的DEBUGGER_ACTION_CRASH请求,然后:
PTRACE_ATTACH到那个进程
发送SIGSTOP给那个进程,让它的所有线程都停止运行
打开tomestone文件,dump CRASH信息
如果这个property "ro.debuggable" 是置位的,则dump该进程的 system和main log

ptrace 参考 http://blog.csdn.net/myarrow/article/details/9617673
如何调试tomestone 参考 http://blog.csdn.net/lizzy115/article/details/13296979
                                         http://blog.csdn.net/helldevil/article/details/6682211
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: