1. 程式人生 > >Android——DEBUG 堆棧

Android——DEBUG 堆棧

ini dsm googl sha edi 部分 對齊 char please

當android系統執行出現死機等致命錯誤的時候。通常會有堆棧的DEBUG信息打印,一般直接看根本看不出問題是出在哪裏!記錄下我android4.2 的DEBUG 堆棧log的方法.


撰寫不易,轉載請註明出處:http://blog.csdn.net/jscese/article/details/38232667


一.DEBUG log

這是我出現錯誤的堆棧信息:

01-01 08:00:03.376 I/DEBUG   (  929):     r0 0000000e  r1 00000000  r2 00000002  r3 00000000
01-01 08:00:03.376 I/DEBUG   (  929):     r4 404cd890  r5 00000002  r6 00000000  r7 0000000e
01-01 08:00:03.376 I/DEBUG   (  929):     r8 404ccddc  r9 404cd414  sl 404cd414  fp 404cd894
01-01 08:00:03.376 I/DEBUG   (  929):     ip 00000073  sp 404ccd20  lr 4012aec1  pc 40124570  cpsr 20000010
01-01 08:00:03.376 I/DEBUG   (  929):     d0  7664206e69207961  d1  656c646e61682020
01-01 08:00:03.376 I/DEBUG   (  929):     d2  6f69746974726150  d3  332064656464416e
01-01 08:00:03.376 I/DEBUG   (  929):     d4  30636d6d2f30636d  d5  6c622f313030303a
01-01 08:00:03.376 I/DEBUG   (  929):     d6  62636d6d2f6b636f  d7  62636d6d2f306b6c
01-01 08:00:03.376 I/DEBUG   (  929):     d8  0000000000000000  d9  0000000000000000
01-01 08:00:03.376 I/DEBUG   (  929):     d10 0000000000000000  d11 0000000000000000
01-01 08:00:03.376 I/DEBUG   (  929):     d12 0000000000000000  d13 0000000000000000
01-01 08:00:03.376 I/DEBUG   (  929):     d14 0000000000000000  d15 0000000000000000
01-01 08:00:03.376 I/DEBUG   (  929):     d16 000000000c7f0000  d17 000000000c800000
01-01 08:00:03.376 I/DEBUG   (  929):     d18 4163fc8780000000  d19 0000000000000000
01-01 08:00:03.376 I/DEBUG   (  929):     d20 0000000000000000  d21 0000000000000000
01-01 08:00:03.376 I/DEBUG   (  929):     d22 0000000000000000  d23 0000000000000000
01-01 08:00:03.376 I/DEBUG   (  929):     d24 0000000000000000  d25 0000000000000000
01-01 08:00:03.376 I/DEBUG   (  929):     d26 0000000000000000  d27 0000000000000000
01-01 08:00:03.376 I/DEBUG   (  929):     d28 0000000000000000  d29 0000000000000000
01-01 08:00:03.376 I/DEBUG   (  929):     d30 0000000000000000  d31 0000000000000000
01-01 08:00:03.376 I/DEBUG   (  929):     scr 00000010
01-01 08:00:03.380 I/DEBUG   (  929): 
01-01 08:00:03.380 I/DEBUG   (  929): backtrace:
01-01 08:00:03.380 I/DEBUG   (  929):     #00  pc 00019570  /system/lib/libc.so (strlen+16)
01-01 08:00:03.380 I/DEBUG   (  929):     #01  pc 0001febd  /system/lib/libc.so (__vfprintf+2124)
01-01 08:00:03.380 I/DEBUG   (  929):     #02  pc 00021303  /system/lib/libc.so (vsnprintf+70)
01-01 08:00:03.380 I/DEBUG   (  929):     #03  pc 0000139d  /system/lib/liblog.so (__android_log_buf_print+44)
01-01 08:00:03.380 I/DEBUG   (  929):     #04  pc 0000cfd7  /system/bin/vold
01-01 08:00:03.380 I/DEBUG   (  929): 
01-01 08:00:03.380 I/DEBUG   (  929): stack:
01-01 08:00:03.380 I/DEBUG   (  929):          404ccce0  404cd474  
01-01 08:00:03.380 I/DEBUG   (  929):          404ccce4  40128f73  /system/lib/libc.so
01-01 08:00:03.380 I/DEBUG   (  929):          404ccce8  404cd414  
01-01 08:00:03.380 I/DEBUG   (  929):          404cccec  404ccd98  
01-01 08:00:03.380 I/DEBUG   (  929):          404cccf0  00000000  
01-01 08:00:03.380 I/DEBUG   (  929):          404cccf4  404ccd98  
01-01 08:00:03.380 I/DEBUG   (  929):          404cccf8  00000001  
01-01 08:00:03.384 I/DEBUG   (  929):          404cccfc  4001d821  /system/bin/vold
01-01 08:00:03.384 I/DEBUG   (  929):          404ccd00  0000002d  
01-01 08:00:03.384 I/DEBUG   (  929):          404ccd04  404ccddc  
01-01 08:00:03.384 I/DEBUG   (  929):          404ccd08  404cd414  
01-01 08:00:03.384 I/DEBUG   (  929):          404ccd0c  ffffffff  
01-01 08:00:03.388 I/DEBUG   (  929):          404ccd10  00000001  
01-01 08:00:03.388 I/DEBUG   (  929):          404ccd14  4012a667  /system/lib/libc.so
01-01 08:00:03.388 I/DEBUG   (  929):          404ccd18  df0027ad  
01-01 08:00:03.388 I/DEBUG   (  929):          404ccd1c  00000000  
01-01 08:00:03.388 I/DEBUG   (  929):     #00  404ccd20  00000000  
01-01 08:00:03.388 I/DEBUG   (  929):          ........  ........
01-01 08:00:03.388 I/DEBUG   (  929):     #01  404ccd20  00000000  
01-01 08:00:03.388 I/DEBUG   (  929):          404ccd24  00000000  
01-01 08:00:03.388 I/DEBUG   (  929):          404ccd28  00000000  
01-01 08:00:03.388 I/DEBUG   (  929):          404ccd2c  00000000  
01-01 08:00:03.388 I/DEBUG   (  929):          404ccd30  00000000  
01-01 08:00:03.388 I/DEBUG   (  929):          404ccd34  00000073  
01-01 08:00:03.388 I/DEBUG   (  929):          404ccd38  00000000  
01-01 08:00:03.388 I/DEBUG   (  929):          404ccd3c  ffffffff  
01-01 08:00:03.388 I/DEBUG   (  929):          404ccd40  404ccddc  
01-01 08:00:03.388 I/DEBUG   (  929):          404ccd44  4001d85a  /system/bin/vold
01-01 08:00:03.388 I/DEBUG   (  929):          404ccd48  00000000  
01-01 08:00:03.388 I/DEBUG   (  929):          404ccd4c  00000034  
01-01 08:00:03.388 I/DEBUG   (  929):          404ccd50  00000000  
01-01 08:00:03.388 I/DEBUG   (  929):          404ccd54  00000000  
01-01 08:00:03.388 I/DEBUG   (  929):          404ccd58  4001d824  /system/bin/vold
01-01 08:00:03.388 I/DEBUG   (  929):          404ccd5c  00000000  
01-01 08:00:03.388 I/DEBUG   (  929):          ........  ........
01-01 08:00:03.388 I/DEBUG   (  929):     #02  404cd400  00000000  
01-01 08:00:03.388 I/DEBUG   (  929):          404cd404  00000000  
01-01 08:00:03.388 I/DEBUG   (  929):          404cd408  00000000  
01-01 08:00:03.388 I/DEBUG   (  929):          404cd40c  00000000  
01-01 08:00:03.388 I/DEBUG   (  929):          404cd410  00004000  
01-01 08:00:03.388 I/DEBUG   (  929):          404cd414  404cd474  
01-01 08:00:03.388 I/DEBUG   (  929):          404cd418  4014d498  /system/lib/libc.so
01-01 08:00:03.388 I/DEBUG   (  929):          404cd41c  000003ff  
01-01 08:00:03.388 I/DEBUG   (  929):          404cd420  ffff0208  [vectors]
01-01 08:00:03.388 I/DEBUG   (  929):          404cd424  404cd474  
01-01 08:00:03.388 I/DEBUG   (  929):          404cd428  000003ff  
01-01 08:00:03.388 I/DEBUG   (  929):          404cd42c  4001d578  /system/bin/vold
01-01 08:00:03.388 I/DEBUG   (  929):          404cd430  00000003  
01-01 08:00:03.388 I/DEBUG   (  929):          404cd434  404cd474  
01-01 08:00:03.388 I/DEBUG   (  929):          404cd438  00000003  
01-01 08:00:03.388 I/DEBUG   (  929):          404cd43c  401072a3  /system/lib/liblog.so (__android_log_buf_write+186)
01-01 08:00:03.388 I/DEBUG   (  929):          ........  ........
01-01 08:00:03.392 I/DEBUG   (  929): 
01-01 08:00:03.392 I/DEBUG   (  929): memory near r4:
01-01 08:00:03.392 I/DEBUG   (  929):     404cd870 404cdb7c 689886ea 40021d88 404cd8b4  
01-01 08:00:03.392 I/DEBUG   (  929):     404cd880 404cd9fc 404cdb7c 40010fdb 4001d824  
01-01 08:00:03.392 I/DEBUG   (  929):     404cd890 0000000e 00000000 00000000 00000000  
01-01 08:00:03.392 I/DEBUG   (  929):     404cd8a0 00000000 40584a00 40584af8 40584be8  
01-01 08:00:03.392 I/DEBUG   (  929):     404cd8b0 00000000 0000000e 000000b3 0000000e  
01-01 08:00:03.392 I/DEBUG   (  929):     404cd8c0 40584bb6 00000000 00000000 00000000  
01-01 08:00:03.392 I/DEBUG   (  929):     404cd8d0 401815fc 000000f9 000000c0 000000bf  
01-01 08:00:03.392 I/DEBUG   (  929):     404cd8e0 0000655f 40021d88 00000001 40129b39  
01-01 08:00:03.392 I/DEBUG   (  929):     404cd8f0 404cd968 00000000 00000000 00000000  
01-01 08:00:03.392 I/DEBUG   (  929):     404cd900 00004000 404cd9f0 00000000 7fffffdb  
01-01 08:00:03.392 I/DEBUG   (  929):     404cd910 ffff0208 689886ea 7fffffff 689886ea  
01-01 08:00:03.392 I/DEBUG   (  929):     404cd920 00000000 00000000 00000000 00000000  
01-01 08:00:03.392 I/DEBUG   (  929):     404cd930 00000000 00000000 404cda0c 404cd9fc  
01-01 08:00:03.392 I/DEBUG   (  929):     404cd940 404cdb7c 4057217c 40572158 40021d88  
01-01 08:00:03.392 I/DEBUG   (  929):     404cd950 00000001 40129aeb 404cd9cc 00000000  
01-01 08:00:03.392 I/DEBUG   (  929):     404cd960 404cd9d4 00000000 00000000 404cda60  
01-01 08:00:03.392 I/DEBUG   (  929): 
01-01 08:00:03.392 I/DEBUG   (  929): memory near r8:
01-01 08:00:03.392 I/DEBUG   (  929):     404ccdbc 00000000 00000000 00000000 00000000  
01-01 08:00:03.392 I/DEBUG   (  929):     404ccdcc 00000000 00000000 4001d824 00000034  
01-01 08:00:03.392 I/DEBUG   (  929):     404ccddc 00000000 00000000 00000000 00000000  
01-01 08:00:03.392 I/DEBUG   (  929):     404ccdec 00000000 00000000 00000000 00000000  
01-01 08:00:03.392 I/DEBUG   (  929):     404ccdfc 00000000 00000000 00000000 00000000  
01-01 08:00:03.392 I/DEBUG   (  929):     404cce0c 00000000 00000000 00000000 00000000  
01-01 08:00:03.392 I/DEBUG   (  929):     404cce1c 00000000 404cd60f 40128f73 404cd5ed  
01-01 08:00:03.392 I/DEBUG   (  929):     404cce2c 40128f73 404cd55c 404ccee0 00000000  
01-01 08:00:03.392 I/DEBUG   (  929):     404cce3c 404ccee0 00000002 4001d68f 00000001  
01-01 08:00:03.392 I/DEBUG   (  929):     404cce4c 404ccf24 404cd55c ffffffff fffffff7  
01-01 08:00:03.392 I/DEBUG   (  929):     404cce5c 4012a667 404cd9dc 4012b88d 00000000  
01-01 08:00:03.392 I/DEBUG   (  929):     404cce6c 00000000 00000000 00000073 00000000  
01-01 08:00:03.392 I/DEBUG   (  929):     404cce7c 00000073 00000008 00000000 00000009  
01-01 08:00:03.392 I/DEBUG   (  929):     404cce8c 4001d68e 00000000 00000032 00000000  
01-01 08:00:03.392 I/DEBUG   (  929):     404cce9c 00000000 4001d664 00000000 4014d498  
01-01 08:00:03.392 I/DEBUG   (  929):     404cceac 4014d4a8 00000000 40156228 00000000  
01-01 08:00:03.392 I/DEBUG   (  929): 
01-01 08:00:03.392 I/DEBUG   (  929): memory near r9:
01-01 08:00:03.392 I/DEBUG   (  929):     404cd3f4 40021d88 00000001 4012c307 00000000  
01-01 08:00:03.392 I/DEBUG   (  929):     404cd404 00000000 00000000 00000000 00004000  
01-01 08:00:03.392 I/DEBUG   (  929):     404cd414 404cd474 4014d498 000003ff ffff0208  
01-01 08:00:03.392 I/DEBUG   (  929):     404cd424 404cd474 000003ff 4001d578 00000003  
01-01 08:00:03.392 I/DEBUG   (  929):     404cd434 404cd474 00000003 401072a3 00000000  
01-01 08:00:03.392 I/DEBUG   (  929):     404cd444 404cd404 404cd444 00000001 4001d578  
01-01 08:00:03.396 I/DEBUG   (  929):     404cd454 0000000d 404cd474 0000002e 40156228  
01-01 08:00:03.396 I/DEBUG   (  929):     404cd464 4001d578 40156228 401073a1 404cd890  
01-01 08:00:03.396 I/DEBUG   (  929):     404cd474 6563736a 64206573 6c707369 69207961  
01-01 08:00:03.396 I/DEBUG   (  929):     404cd484 7664206e 61682020 656c646e 74726150  
01-01 08:00:03.396 I/DEBUG   (  929):     404cd494 6f697469 6464416e 33206465 0000000a  
01-01 08:00:03.396 I/DEBUG   (  929):     404cd4a4 00000000 00000000 38663735 62353536  
01-01 08:00:03.396 I/DEBUG   (  929):     404cd4b4 00000000 00000000 00000000 00000000  
01-01 08:00:03.396 I/DEBUG   (  929):     404cd4c4 00000000 00000000 00000000 00000000  
01-01 08:00:03.396 I/DEBUG   (  929):     404cd4d4 00000000 00000000 00000000 00000000  
01-01 08:00:03.396 I/DEBUG   (  929):     404cd4e4 00000000 00000000 00000000 00000000 

須要分析上面的DEBUG,僅僅須要提取一部分內容然後保存到一個 txt 文本裏面,提取例如以下內容

#00  pc 00019570  /system/lib/libc.so
#01  pc 0001febd  /system/lib/libc.so
#02  pc 00021303  /system/lib/libc.so
#03  pc 0000139d  /system/lib/liblog.so
#04  pc 0000caa9  /system/bin/vold

保存到error.txt,須要註意保存內容的間隔對齊。


二.python

須要一個分析上面提取出來的error.txt DEBUG 信息 DEBUG.py:

#!/usr/bin/python
# stack symbol parser
import os
import string
import sys


#define android product name
ANDROID_PRODUCT_NAME = 'gotechcn'


ANDROID_WORKSPACE = os.getcwd()+"/"


# addr2line tool path and symbol path
addr2line_tool = ANDROID_WORKSPACE + 'prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin/arm-eabi-addr2line'
symbol_dir = ANDROID_WORKSPACE + 'out/target/product/' + ANDROID_PRODUCT_NAME +'/symbols'
symbol_bin = symbol_dir + '/system/bin/'
symbol_lib = symbol_dir + '/system/lib/'




class ReadLog:
    def __init__(self,filename):
        self.logname = filename
    def parse(self):
        f = file(self.logname,'r')
        lines = f.readlines()
        if lines != []:
            print 'read file ok'
        else:
            print 'read file failed'
        result =[]
        for line in lines:
            if line.find('stack') != -1:
                print 'stop search'
                break
            elif line.find('system') != -1:
                #print 'find one item' + line
                result.append(line)
        return result


class ParseContent:
    def __init__(self,addr,lib):
            self.address = addr # pc address
            self.exename = lib  # executable or shared library
    def addr2line(self):
        cmd = addr2line_tool + " -C -f -s -e " + symbol_dir + self.exename + " " + self.address
        #print cmd
        stream = os.popen(cmd)
        lines = stream.readlines()
        list = map(string.strip,lines)
        return list
    
inputarg = sys.argv
if len(inputarg) < 2:
    print 'Please input panic log'
    exit()


filename = inputarg[1]
readlog = ReadLog(filename)
inputlist = readlog.parse()


for item in inputlist:
    itemsplit = item.split()
    test = ParseContent(itemsplit[-2],itemsplit[-1])
    list = test.addr2line()
    print "%-30s%s" % (list[1],list[0])

這個python腳本是google提供的,用來分析DEBUG,須要註意的是配置自己相相應的ANDROID_PRODUCT_NAME,用來在你的android源代碼裏面找相應的工具我的product_name 為 “gotechcn”。

addr2line_tool 的路徑各個android 版本號可能也有所不同,須要自己依據自己的源代碼進行配置.

我這android4.2 還須要cp OUT/system/lib/egl/libGLES_android.so 到 OUT/system/lib文件夾下 供上面的腳本使用


三.解析

在上面兩步做好之後。將DEBUG.py 以及 error.txt cp 到 android 源代碼的根文件夾下,運行:

python DEBUG.py error.txt

依據我上面的error.txt 可得到例如以下結果:

read file ok
strlen.c:52                   strlen
string.h:221                  strlen
vsnprintf.c:61                vsnprintf
stdio.h:490                   __android_log_buf_print
DirectVolume.cpp:291          DirectVolume::handleDiskChanged(char const*, NetlinkEvent*)

這就是出問題的根源,可依據這個DEBUG




Android——DEBUG 堆棧