Android Stability - tombstone日志
时间: 2020-07-01来源:OSCHINA
前景提要
Tombstone日志的生成
Android默认是不会抓取coredump文件的,AOSP在进程发生内存访问异常的时候一般会在 data/tombstones/ 下面生成“tombstone_0x”形式命名的文件,这个文件是debuggerd进程来抓取的,在可执行文件被加载的时候会执行到bionic/linker/debugger.cpp这个文件的debuggerd_init函数,在这个函数里面注册了信号处理函数为debuggerd_signal_handler,所以当这个进程接收到SIGABRT、SIGBUS、SIGSEGV等signal的时候kernel都会回调debuggerd_signal_handler这个函数来处理. __LIBC_HIDDEN__ void debuggerd_init ( ) { struct sigaction action ; memset ( & action , 0 , sizeof ( action ) ) ; sigemptyset ( & action . sa_mask ) ; action . sa_sigaction = debuggerd_signal_handler ; action . sa_flags = SA_RESTART | SA_SIGINFO ; // Use the alternate signal stack if available so we can catch stack overflows. action . sa_flags |= SA_ONSTACK ; sigaction ( SIGABRT , & action , nullptr ) ; sigaction ( SIGBUS , & action , nullptr ) ; sigaction ( SIGFPE , & action , nullptr ) ; sigaction ( SIGILL , & action , nullptr ) ; sigaction ( SIGSEGV , & action , nullptr ) ; # if defined(SIGSTKFLT) sigaction ( SIGSTKFLT , & action , nullptr ) ; # endif sigaction ( SIGTRAP , & action , nullptr ) ; }
debuggerd_signal_handler的实现如下,它的作用就是给守护进程发送一个socket请求,由后者通过ptrace调用来获取出错进程的出错地址,出错信号,线程堆栈、/proc/*/maps等信息,也就是上面所讲述的tombstone文件,zygote进程的app_process可执行文件在第一次被加载的时候也会执行上面的debuggerd_init逻辑,得益于Linux的fock调用,所有的zygote的子进程都有这个信号处理过程,不需要再另外添加代码. static void debuggerd_signal_handler ( int signal_number , siginfo_t * info , void * ) { // It's possible somebody cleared the SA_SIGINFO flag, which would mean // our "info" arg holds an undefined value. if ( ! have_siginfo ( signal_number ) ) { info = nullptr ; } log_signal_summary ( signal_number , info ) ; { send_debuggerd_packet ( info ) ; // We need to return from the signal handler so that debuggerd can dump the // thread that crashed, but returning here does not guarantee that the signal // will be thrown again, even for SIGSEGV and friends, since the signal could // have been sent manually. Resend the signal with rt_tgsigqueueinfo(2) to // preserve the SA_SIGINFO contents. signal ( signal_number , SIG_DFL ) ; struct siginfo si ; if ( ! info ) { memset ( & si , 0 , sizeof ( si ) ) ; si . si_code = SI_USER ; si . si_pid = getpid ( ) ; si . si_uid = getuid ( ) ; info = & si ; } else if ( info -> si_code >= 0 || info -> si_code == SI_TKILL ) { // rt_tgsigqueueinfo(2)'s documentation appears to be incorrect on kernels // that contain commit 66dd34a (3.9+). The manpage claims to only allow // negative si_code values that are not SI_TKILL, but 66dd34a changed the // check to allow all si_code values in calls coming from inside the house. } int rc = syscall ( SYS_rt_tgsigqueueinfo , getpid ( ) , gettid ( ) , signal_number , info ) ; if ( rc != 0 ) { __libc_format_log ( ANDROID_LOG_FATAL , "libc" , "failed to resend signal during crash: %s" , strerror ( errno ) ) ; _exit ( 0 ) ; } }
Tombstone日志 pid : 27730 , tid : 27736 , name : thermalloadalgo >> > / vendor / bin / thermalloadalgod << < signal 6 ( SIGABRT ) , code - - - - - - - - , fault addr - - - - - - - - r0 00000000 r1 00006c52 r2 00000006 r3 00000008 r4 f0ce558c r5 00000006 r6 f0ce5534 r7 0000010c r8 05f481e2 r9 f0bfca90 sl 00000000 fp ffea81cc ip 00000002 sp ffea7f70 lr f0896507 pc f0898d64 cpsr 20070010 backtrace : #00 pc 0004ad64 /system/lib/libc.so (tgkill+12) #01 pc 00048503 /system/lib/libc.so (pthread_kill+34) #02 pc 0001d4a5 /system/lib/libc.so (raise+10) #03 pc 00018fe1 /system/lib/libc.so (__libc_android_abort+34) #04 pc 00017044 /system/lib/libc.so (abort+4) #05 pc 0001b49f /system/lib/libc.so (__libc_fatal+22) #06 pc 0001b47f /system/lib/libc.so (__fortify_chk_fail+26) #07 pc 00050cbb /system/lib/libc.so (__sprintf_chk+66) #08 pc 000039fb /system/vendor/lib/libthermalalgo.so (_Z12get_uid_tputi+54) #09 pc 00003b3b /system/vendor/lib/libthermalalgo.so (_Z18update_avg_fg_tputv+14) #10 pc 00002df1 /system/vendor/lib/libthermalalgo.so (_Z3spav+324) #11 pc 000020ed /system/vendor/lib/libthermalalgo.so (libthermal_algo_setup+244) #12 pc 000008df /system/vendor/bin/thermalloadalgod #13 pc 00016c5d /system/lib/libc.so (__libc_init+48) #14 pc 00000770 /system/vendor/bin/thermalloadalgod stack : ffea7f30 f0bfd114 / system / vendor / lib / libthermalalgo . so ffea7f34 00000000 ffea7f38 ffea81cc [ stack ] ffea7f3c f0893dd3 / system / lib / libc . so ( vsnprintf + 138 ) ffea7f40 ffffffff ffea7f44 898045b6 ffea7f48 00000000 ffea7f4c 00000000 ffea7f50 00000000 ffea7f54 00000000 ffea7f58 00000000 ffea7f5c 00000000 ffea7f60 ffffffff ffea7f64 00004000 ffea7f68 f0ce558c ffea7f6c f08964f7 / system / lib / libc . so ( pthread_kill + 22 ) #00 ffea7f70 00000000 . . . . . . . . . . . . . . . . #01 ffea7f70 00000000 ffea7f74 00000006 ffea7f78 00000000 ffea7f7c f0bff168 / system / vendor / lib / libthermalalgo . so ffea7f80 f0bff160 / system / vendor / lib / libthermalalgo . so ffea7f84 f086b4a9 / system / lib / libc . so ( raise + 14 ) . . . . . .
debuggerd守护进程抓取的tombstone文件内容大概如上所示,这个Log具体说明了如下信息: 出错的进程名字为 /vendor/bin/thermalloadalgod ,它的pid是 27730 ,而具体导致接收到这次信号的tid也为 27736 . 进程收到的是SIGABRT信号. 抓取这个日志的时候,每个寄存器的内容,分析问题的时候一般需要结合反汇编代码和这里的寄存器内容分析. 这个线程的函数栈帧信息,也就是backtrace,从中我们可以看到这个线程的函数调用流程,因为tombstone文件一般是在终端抓取的,由于终端的可执行文件和so文件并没有保存有可供调试的符号信息,所以只能看到是哪个函数,但是对应不到对应的代码行,如果有对应的符号信息,可以用addr2line等工具把这里的地址信息对应的代码行,建议用add2line的时候 加上 “-ie”参数,可以把inline函数也打印出来. 这个线程对应的函数栈的内容,函数栈用来保存局部变量、返回地址、SP寄存器等内容.
常见信号 SIGABRT 在Android里面,这个信号一般是进程自己检测到不可恢复的错误之后,主动调用abort函数之后会接收到的一种信号,一般在log里面会打印出调用abort的原因,这种问题相对来说可能容易解决一些,只要根据错误提示信息,就可以去找相应的原因. SIGSEGV 在POSIX兼容的平台上, SIGSEGV 是当一个进程执行了一个无效的内存引用,或发生 段错误 时发送给它的信号,例如访问没有实际物理内存对应的虚拟地址,或者访问的时候出现权限异常,比较常见的就是空指针,对于SIGSEGV这一类信号,在tombstone log里面会给出fault addr,根据汇编代码和寄存器内容,可以接着往下分析. SIGBUS SIGBUS与SIGSEGV有点类似,也都是访问内存的时候出错,他们之间的区别可能在于如果那个地址是正常的(也就是说正常的虚拟地址,而且它也有对应的物理内存),如果访问出错,那么就会上报SIGBUS,否则就上报的是SIGSEGV,例如有些芯片总线访问需要地址是4字节对齐的,如果那个地址不是对齐的,那么就会上报SIGBUS.
这三种信号在Android稳定性问题分析当中是比较常见的,除了这三种信号之外,其实Linux有64种信号,一般来说前面的32种是标准信号,后面32种是新增加的实时信号,对于标准信号,一个进程里面同一时间只能存在一个,而实时信号却没有这个限制,可以存在多个,这里借用 Unix系统中常用的信号含义 这个文章的内容对标准信号做一些简单的介绍 Signal Description 1 - SIGHUP 本信号在用户终端连接(正常或非正常)结束时发出, 通常是在终端的控制进程结束时, 通知同一session内的各个作业, 这时它们与控制终端不再关联。登录Linux时,系统会分配给登录用户一个终端(Session)。在这个终端运行的所有程序,包括前台进程组和后台进程组,一般都属于这个Session。当用户退出Linux登录时,前台进程组和后台有对终端输出的进程将会收到SIGHUP信号。这个信号的默认操作为终止进程,因此前台进程组和后台有终端输出的进程就会中止。不过可以捕获这个信号,比如wget能捕获SIGHUP信号,并忽略它,这样就算退出了Linux登录,wget也能继续下载。此外,对于与终端脱离关系的守护进程,这个信号用于通知它重新读取配置文件。
2 - SIGINT 程序终止(interrupt)信号, 在用户键入INTR字符(通常是Ctrl-C)时发出,用于通知前台进程组终止进程。
3 - SIGQUIT 和SIGINT类似, 但由QUIT字符(通常是Ctrl-)来控制. 进程在因收到SIGQUIT退出时会产生core文件, 在这个意义上类似于一个程序错误信号。
4 - SIGILL 执行了非法指令. 通常是因为可执行文件本身出现错误, 或者试图执行数据段. 堆栈溢出时也有可能产生这个信号。
5 - SIGTRAP 由断点指令或其它trap指令产生. 由debugger使用。
6 - SIGABRT 调用abort函数生成的信号。
7 - SIGBUS 非法地址, 包括内存地址对齐(alignment)出错。比如访问一个四个字长的整数, 但其地址不是4的倍数。它与SIGSEGV的区别在于后者是由于对合法存储地址的非法访问触发的(如访问不属于自己存储空间或只读存储空间)。
8 - SIGFPE 在发生致命的算术运算错误时发出. 不仅包括浮点运算错误, 还包括溢出及除数为0等其它所有的算术的错误。
9 - SIGKILL 用来立即结束程序的运行.本信号不能被阻塞、处理和忽略。如果管理员发现某个进程终止不了,可尝试发送这个信号。
10 - SIGUSR1 留给用户使用
11 - SIGSEGV 试图访问未分配给自己的内存, 或试图往没有写权限的内存地址写数据.
12 - SIGUSR2 留给用户使用
13 - SIGPIPE 管道破裂。这个信号通常在进程间通信产生,比如采用FIFO(管道)通信的两个进程,读管道没打开或者意外终止就往管道写,写进程会收到SIGPIPE信号。此外用Socket通信的两个进程,写进程在写Socket的时候,读进程已经终止。
14 - SIGALRM 时钟定时信号, 计算的是实际的时间或时钟时间. alarm函数使用该信号.
15 - SIGTERM 程序结束(terminate)信号, 与SIGKILL不同的是该信号可以被阻塞和处理。通常用来要求程序自己正常退出,shell命令kill缺省产生这个信号。如果进程终止不了,我们才会尝试SIGKILL。
17 - SIGCHLD 子进程结束时, 父进程会收到这个信号。如果父进程没有处理这个信号,也没有等待(wait)子进程,子进程虽然终止,但是还会在内核进程表中占有表项,这时的子进程称为僵尸进程。这种情况我们应该避免(父进程或者忽略SIGCHILD信号,或者捕捉它,或者wait它派生的子进程,或者父进程先终止,这时子进程的终止自动由init进程来接管)。
18- SIGCONT 让一个停止(stopped)的进程继续执行. 本信号不能被阻塞. 可以用一个handler来让程序在由stopped状态变为继续执行时完成特定的工作. 例如, 重新显示提示符
19 - SIGSTOP 停止(stopped)进程的执行. 注意它和terminate以及interrupt的区别:该进程还未结束, 只是暂停执行. 本信号不能被阻塞, 处理或忽略.
20 - SIGTSTP 停止进程的运行, 但该信号可以被处理和忽略. 用户键入SUSP字符时(通常是Ctrl-Z)发出这个信号
21 - SIGTTIN 当后台作业要从用户终端读数据时, 该作业中的所有进程会收到SIGTTIN信号. 缺省时这些进程会停止执行.
22 - SIGTTOU 类似于SIGTTIN, 但在写终端(或修改终端模式)时收到.
23 - SIGURG 有"紧急"数据或out-of-band数据到达socket时产生.
24 - SIGXCPU 超过CPU时间资源限制. 这个限制可以由getrlimit/setrlimit来读取/改变。
25 - SIGXFSZ 当进程企图扩大文件以至于超过文件大小资源限制。
26 - SIGVTALRM 虚拟时钟信号. 类似于SIGALRM, 但是计算的是该进程占用的CPU时间.
27 - SIGPROF 类似于SIGALRM/SIGVTALRM, 但包括该进程用的CPU时间以及系统调用的时间.
28 - SIGWINCH 窗口大小改变时发出.
29 - SIGIO 文件描述符准备就绪, 可以开始进行输入/输出操作.
30 - SIGPWR 31 - SIGSYS
Power failure 非法的系统调用

objdump工具
tombstone文件抓取的内容比较少,没有coredump文件那么全,分析这种Log的时候,不可缺少的要用到objdump这类反编译工具,objdump能反编译ELF文件,将它的代码段反汇编出来,结合tombstone文件里面的fault addr地址信息、寄存器信息、函数栈帧信息等来分析出问题的原因. Usage : aarch64 - linux - android - objdump < option ( s ) > < file ( s ) > Display information from object < file ( s ) > . At least one of the following switches must be given : - a , -- archive - headers Display archive header information - f , -- file - headers Display the contents of the overall file header - p , -- private - headers Display object format specific file header contents - P , -- private = OPT , OPT . . . Display object format specific contents - h , -- [ section - ] headers Display the contents of the section headers - x , -- all - headers Display the contents of all headers - d , -- disassemble Display assembler contents of executable sections - D , -- disassemble - all Display assembler contents of all sections - S , -- source Intermix source code with disassembly - s , -- full - contents Display the full contents of all sections requested - g , -- debugging Display debug information in object file - e , -- debugging - tags Display debug information using ctags style - G , -- stabs Display ( in raw form ) any STABS info in the file - W [ lLiaprmfFsoRt ] or -- dwarf [ = rawline , = decodedline , = info , = abbrev , = pubnames , = aranges , = macro , = frames , = frames - interp , = str , = loc , = Ranges , = pubtypes , = gdb_index , = trace_info , = trace_abbrev , = trace_aranges , = addr , = cu_index ] Display DWARF info in the file - t , -- syms Display the contents of the symbol table ( s ) - T , -- dynamic - syms Display the contents of the dynamic symbol table - r , -- reloc Display the relocation entries in the file - R , -- dynamic - reloc Display the dynamic relocation entries in the file @ < file > Read options from < file > - v , -- version Display this program's version number - i , -- info List object formats and architectures supported - H , -- help Display this information The following switches are optional : - b , -- target = BFDNAME Specify the target object format as BFDNAME - m , -- architecture = MACHINE Specify the target architecture as MACHINE - j , -- section = NAME Only display information for section NAME - M , -- disassembler - options = OPT Pass text OPT on to the disassembler - EB -- endian = big Assume big endian format when disassembling - EL -- endian = little Assume little endian format when disassembling -- file - start - context Include context from start of file ( with - S ) - I , -- include = DIR Add DIR to search list for source files - l , -- line - numbers Include line numbers and filenames in output - F , -- file - offsets Include file offsets when displaying information - C , -- demangle [ = STYLE ] Decode mangled / processed symbol names The STYLE , if specified , can be `auto ', `gnu' , `lucid ', `arm' , `hp ', `edg' , `gnu - v3 ', `java' or `gnat' - w , -- wide Format output for more than 80 columns - z , -- disassemble - zeroes Do not skip blocks of zeroes when disassembling -- start - address = ADDR Only process data whose address is >= ADDR -- stop - address = ADDR Only process data whose address is <= ADDR -- prefix - addresses Print complete address alongside disassembly -- [ no - ] show - raw - insn Display hex alongside symbolic disassembly -- insn - width = WIDTH Display WIDTH bytes on a single line for - d -- adjust - vma = OFFSET Add OFFSET to all displayed section addresses -- special - syms Include special symbols in symbol dumps -- prefix = PREFIX Add PREFIX to absolute paths for - S -- prefix - strip = LEVEL Strip initial directory names for - S -- dwarf - depth = N Do not display DIEs at depth N or greater -- dwarf - start = N Display DIEs starting with N , at the same depth or deeper -- dwarf - check Make additional dwarf internal consistency checks . aarch64 - linux - android - objdump : supported targets : elf64 - littleaarch64 elf64 - bigaarch64 elf32 - littleaarch64 elf32 - bigaarch64 elf32 - littlearm elf32 - bigarm elf64 - little elf64 - big elf32 - little elf32 - big plugin srec symbolsrec verilog tekhex binary ihex aarch64 - linux - android - objdump : supported architectures : aarch64 aarch64 : ilp32 arm armv2 armv2a armv3 armv3m armv4 armv4t armv5 armv5t armv5te xscale ep9312 iwmmxt iwmmxt2 plugin The following AARCH64 specific disassembler options are supported for use with the - M switch ( multiple options should be separated by commas ) : no - aliases Don't print instruction aliases . aliases Do print instruction aliases . The following ARM specific disassembler options are supported for use with the - M switch : reg - names - special - atpcs Select special register names used in the ATPCS reg - names - atpcs Select register names used in the ATPCS reg - names - apcs Select register names used in the APCS reg - names - std Select register names used in ARM 's ISA documentation reg - names - gcc Select register names used by GCC reg - names - raw Select raw register names force - thumb Assume all insns are Thumb insns no - force - thumb Examine preceding label to determine an insn's type

作者:HuangTao_Zoey
链接:https://www.jianshu.com/p/7bf796415210
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

科技资讯:

科技学院:

科技百科:

科技书籍:

网站大全:

软件大全:

热门排行