script debug native 死机

本篇文章来源于 Linux公社网站(www.linuxidc.com)  原文链接:http://www.linuxidc.com/Linux/2012-06/63026p2.htm

1: 编写script,hy.panic.py 
#!/usr/bin/python
# stack symbol parser
import os
import string
import sys


#define Android product name
ANDROID_PRODUCT_NAME = 'generic'


ANDROID_WORKSPACE = os.getcwd()+"/"


# addr2line tool path and symbol path
addr2line_tool = ANDROID_WORKSPACE + 'prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/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])

2、相关的死机堆栈信息保存 error.txt

例如:
I/DEBUG   (  634):          #00  pc 000078e6  /system/lib/libmultiplayerservice.so
I/DEBUG   (  634):          #01  pc 000087bc  /system/lib/libmultiplayerservice.so
I/DEBUG   (  634):          #02  pc 0000e94e  /system/lib/libsensorservice.so
I/DEBUG   (  634):          #03  pc 0000a790  /system/lib/libsensorservice.so
I/DEBUG   (  634):          #04  pc 0000d4b2  /system/lib/libsensorservice.so
I/DEBUG   (  634):          #05  pc 0000d852  /system/lib/libsensorservice.so
I/DEBUG   (  634):          #06  pc 00015ece  /system/lib/libutils.so
I/DEBUG   (  634):          #07  pc 0000153a  /system/lib/libsystem_server.so
I/DEBUG   (  634):          #08  pc 00001756  /system/lib/libsystem_server.so
I/DEBUG   (  634):          #09  pc 0000adb8  /system/lib/libandroid_servers.so
I/DEBUG   (  634):          #10  pc 00011cb4  /system/lib/libdvm.so

3、将以上两个文件拷贝到android的编译根路径下面,执行

python hy.panic.py error.txt

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值