调试JNI so所用到的一个脚本

#!/usr/bin/python   
# stack symbol parser   
import os  
import string  
import sys  
  
#define android product name   
ANDROID_PRODUCT_NAME = 'imx51_bbg'  
  
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]) 

1,将以上脚本保存为:panic.py

2,错误信息:

D/==ipodport====Hal===( 2425): *******PAUSESTATUS *******cmd=7b
I/DEBUG   ( 2131): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *
**
I/DEBUG   ( 2131): Build fingerprint: 'unknown'
I/DEBUG   ( 2131): pid: 2425, tid: 2425  >>> cn.skypine.the.ipod <<<
I/DEBUG   ( 2131): signal 11 (SIGSEGV), fault addr 646f7075
I/DEBUG   ( 2131):  r0 00000007  r1 00000001  r2 80b08180  r3 8094e564
I/DEBUG   ( 2131):  r4 646f7049  r5 809a13f4  r6 00000178  r7 80b08180
I/DEBUG   ( 2131):  r8 646f7049  r9 4615af08  10 80b0818c  fp 00000001
I/DEBUG   ( 2131):  ip 80948f60  sp bef1f248  lr 8094e5cb  pc 80948f76  cpsr 800
00030
I/DEBUG   ( 2131):  d0  6472656767756265  d1  2a20535554415453
I/DEBUG   ( 2131):  d2  4208eeec4208ee2a  d3  4208ef544208ef2a
I/DEBUG   ( 2131):  d4  00650074006e006f  d5  007200500074006e
I/DEBUG   ( 2131):  d6  006400690076006f  d7  0000000000720065
I/DEBUG   ( 2131):  d8  0000000043d20000  d9  0000000000000000
I/DEBUG   ( 2131):  d10 0000000000000000  d11 0000000000000000
I/DEBUG   ( 2131):  d12 0000000000000000  d13 0000000000000000
I/DEBUG   ( 2131):  d14 0000000000000000  d15 0000000000000000
I/DEBUG   ( 2131):  d16 000000070000000c  d17 c049000000000000
I/DEBUG   ( 2131):  d18 0000000000000000  d19 0000000000000000
I/DEBUG   ( 2131):  d20 3ff0000000000000  d21 8000000000000000
I/DEBUG   ( 2131):  d22 0000000000000000  d23 0000ed000000e4e0
I/DEBUG   ( 2131):  d24 00000500000004e0  d25 00000500000004e0
I/DEBUG   ( 2131):  d26 00000500000004e0  d27 00000500000004e0
I/DEBUG   ( 2131):  d28 0000000000000000  d29 3ff0000000000000
I/DEBUG   ( 2131):  d30 0000000000000000  d31 3ff0000000000000
I/DEBUG   ( 2131):  scr 80000012
I/DEBUG   ( 2131):
I/DEBUG   ( 2131):          #00  pc 00048f76  /system/lib/libdvm.so
I/DEBUG   ( 2131):          #01  pc 00005d7a  /system/lib/libipodcontrol.so
I/DEBUG   ( 2131):          #02  pc 00016df4  /system/lib/libdvm.so
I/DEBUG   ( 2131):          #03  pc 00045284  /system/lib/libdvm.so
I/DEBUG   ( 2131):          #04  pc 0004a9aa  /system/lib/libdvm.so
I/DEBUG   ( 2131):          #05  pc 0001bd58  /system/lib/libdvm.so
I/DEBUG   ( 2131):          #06  pc 00022754  /system/lib/libdvm.so
I/DEBUG   ( 2131):          #07  pc 000215f4  /system/lib/libdvm.so
I/DEBUG   ( 2131):          #08  pc 0005c74e  /system/lib/libdvm.so
I/DEBUG   ( 2131):          #09  pc 00064d2c  /system/lib/libdvm.so
I/DEBUG   ( 2131):          #10  pc 0001bd58  /system/lib/libdvm.so
I/DEBUG   ( 2131):          #11  pc 00022754  /system/lib/libdvm.so
I/DEBUG   ( 2131):          #12  pc 000215f4  /system/lib/libdvm.so
I/DEBUG   ( 2131):          #13  pc 0005c58c  /system/lib/libdvm.so
I/DEBUG   ( 2131):          #14  pc 00047c56  /system/lib/libdvm.so
I/DEBUG   ( 2131):          #15  pc 0002d8ac  /system/lib/libandroid_runtime.so
I/DEBUG   ( 2131):          #16  pc 0002e9a8  /system/lib/libandroid_runtime.so
I/DEBUG   ( 2131):          #17  pc 00008ca8  /system/bin/app_process
I/DEBUG   ( 2131):          #18  pc 0000d3c0  /system/lib/libc.so
I/DEBUG   ( 2131):
I/DEBUG   ( 2131): code around pc:
I/DEBUG   ( 2131): 80948f54 fffe1c59 bf006900 0c00f20f 460cb5f0
I/DEBUG   ( 2131): 80948f64 4d18b085 46172101 93034465 f0059002
I/DEBUG   ( 2131): 80948f74 6ae3fb1d d0042b07 f01f4620 4606f9a3
I/DEBUG   ( 2131): 80948f84 4620b1c8 9a034639 fbf2f020 b9904606
I/DEBUG   ( 2131): 80948f94 e00cf8dd 490c2003 18694a0c 18aa69a3
I/DEBUG   ( 2131):
I/DEBUG   ( 2131): code around lr:
I/DEBUG   ( 2131): 8094e5a8 00052e90 0000039c 4604b570 b910460d
I/DEBUG   ( 2131): 8094e5b8 ff72f7ff 2d014604 d1026866 f7ff4620
I/DEBUG   ( 2131): 8094e5c8 6065ffc7 bd704630 b087b5f0 f7ff4607
I/DEBUG   ( 2131): 8094e5d8 4d27ff63 4a27a400 58ae192d 46046941
I/DEBUG   ( 2131): 8094e5e8 03c0f8d6 f0129104 9b04f905 d03d4283
I/DEBUG   ( 2131):
I/DEBUG   ( 2131): stack:
I/DEBUG   ( 2131):     bef1f208  00000000
I/DEBUG   ( 2131):     bef1f20c  afd10270  /system/lib/libc.so
I/DEBUG   ( 2131):     bef1f210  afd43724  /system/lib/libc.so
I/DEBUG   ( 2131):     bef1f214  00000040
I/DEBUG   ( 2131):     bef1f218  00000001
I/DEBUG   ( 2131):     bef1f21c  0000a000  [heap]
I/DEBUG   ( 2131):     bef1f220  0000cca0  [heap]
I/DEBUG   ( 2131):     bef1f224  00000001
I/DEBUG   ( 2131):     bef1f228  00000007
I/DEBUG   ( 2131):     bef1f22c  80b08180  /system/lib/libipodcontrol.so
I/DEBUG   ( 2131):     bef1f230  646f7049
I/DEBUG   ( 2131):     bef1f234  8094e5cb  /system/lib/libdvm.so
I/DEBUG   ( 2131):     bef1f238  646f7049
I/DEBUG   ( 2131):     bef1f23c  809a13f4  /system/lib/libdvm.so
I/DEBUG   ( 2131):     bef1f240  df002777
I/DEBUG   ( 2131):     bef1f244  e3a070ad
I/DEBUG   ( 2131): #00 bef1f248  263bec6c
I/DEBUG   ( 2131):     bef1f24c  0000cca0  [heap]
I/DEBUG   ( 2131):     bef1f250  0000cca0  [heap]
I/DEBUG   ( 2131):     bef1f254  80b0818c  /system/lib/libipodcontrol.so
I/DEBUG   ( 2131):     bef1f258  80b08168  /system/lib/libipodcontrol.so
I/DEBUG   ( 2131):     bef1f25c  80b096ac  /system/lib/libipodcontrol.so
I/DEBUG   ( 2131):     bef1f260  0000aa48  [heap]
I/DEBUG   ( 2131):     bef1f264  00000178
I/DEBUG   ( 2131):     bef1f268  80b07adc  /system/lib/libipodcontrol.so
I/DEBUG   ( 2131):     bef1f26c  80b05d7d  /system/lib/libipodcontrol.so
I/DEBUG   ( 2131): #01 bef1f270  bef1f298  [stack]
I/DEBUG   ( 2131):     bef1f274  4208bdc0
I/DEBUG   ( 2131):     bef1f278  4208bda8
I/DEBUG   ( 2131):     bef1f27c  bef1f608  [stack]
I/DEBUG   ( 2131):     bef1f280  00000001
I/DEBUG   ( 2131):     bef1f284  bef1f2b8  [stack]
I/DEBUG   ( 2131):     bef1f288  00000004
I/DEBUG   ( 2131):     bef1f28c  4208bdbc
I/DEBUG   ( 2131):     bef1f290  4208bdc8
I/DEBUG   ( 2131):     bef1f294  80916df8  /system/lib/libdvm.so
I/BootReceiver( 2190): Copying /data/tombstones/tombstone_09 to DropBox (SYSTEM_
TOMBSTONE)
D/Zygote  ( 2133): Process 2425 terminated by signal (11)
D/dalvikvm( 2190): GC_FOR_MALLOC freed 5248 objects / 304232 bytes in 126ms
I/ActivityManager( 2190): Process cn.skypine.the.ipod (pid 2425) has died.
I/WindowManager( 2190): WIN DEATH: Window{461e6af0 cn.skypine.the.ipod/cn.skypin
e.the.ipod.IpodActivity paused=false}
I/UsageStats( 2190): Unexpected resume of com.android.launcher while already res
umed in cn.skypine.the.ipod
D/dalvikvm( 2190): GC_FOR_MALLOC freed 520 objects / 23968 bytes in 118ms
W/InputManagerService( 2190): Got RemoteException sending setActive(false) notif
ication to pid 2425 uid 10013
D/dalvikvm( 2190): GC_FOR_MALLOC freed 75 objects / 4008 bytes in 180ms
I/dalvikvm-heap( 2190): Grow heap (frag case) to 6.691MB for 71588-byte allocati
on
D/dalvikvm( 2190): GC_FOR_MALLOC freed 0 objects / 0 bytes in 114ms
D/dalvikvm( 2190): GC_FOR_MALLOC freed 27 objects / 72704 bytes in 104ms
I/dalvikvm-heap( 2190): Grow heap (frag case) to 6.793MB for 143160-byte allocat
ion
D/dalvikvm( 2190): GC_FOR_MALLOC freed 0 objects / 0 bytes in 113ms
D/dalvikvm( 2190): GC_FOR_MALLOC freed 713 objects / 229904 bytes in 115ms
D/dalvikvm( 2190): GC_FOR_MALLOC freed 55 objects / 2920 bytes in 105ms
I/dalvikvm-heap( 2190): Grow heap (frag case) to 6.845MB for 107788-byte allocat
ion
D/dalvikvm( 2190): GC_FOR_MALLOC freed 0 objects / 0 bytes in 116ms

3,将错误中的:

I/DEBUG   ( 2131):          #00  pc 00048f76  /system/lib/libdvm.so
I/DEBUG   ( 2131):          #01  pc 00005d7a  /system/lib/libipodcontrol.so
I/DEBUG   ( 2131):          #02  pc 00016df4  /system/lib/libdvm.so
I/DEBUG   ( 2131):          #03  pc 00045284  /system/lib/libdvm.so
I/DEBUG   ( 2131):          #04  pc 0004a9aa  /system/lib/libdvm.so
I/DEBUG   ( 2131):          #05  pc 0001bd58  /system/lib/libdvm.so
I/DEBUG   ( 2131):          #06  pc 00022754  /system/lib/libdvm.so
I/DEBUG   ( 2131):          #07  pc 000215f4  /system/lib/libdvm.so
I/DEBUG   ( 2131):          #08  pc 0005c74e  /system/lib/libdvm.so
I/DEBUG   ( 2131):          #09  pc 00064d2c  /system/lib/libdvm.so
I/DEBUG   ( 2131):          #10  pc 0001bd58  /system/lib/libdvm.so
I/DEBUG   ( 2131):          #11  pc 00022754  /system/lib/libdvm.so
I/DEBUG   ( 2131):          #12  pc 000215f4  /system/lib/libdvm.so
I/DEBUG   ( 2131):          #13  pc 0005c58c  /system/lib/libdvm.so
I/DEBUG   ( 2131):          #14  pc 00047c56  /system/lib/libdvm.so
I/DEBUG   ( 2131):          #15  pc 0002d8ac  /system/lib/libandroid_runtime.so
I/DEBUG   ( 2131):          #16  pc 0002e9a8  /system/lib/libandroid_runtime.so
I/DEBUG   ( 2131):          #17  pc 00008ca8  /system/bin/app_process
I/DEBUG   ( 2131):          #18  pc 0000d3c0  /system/lib/libc.so

保存到一个文件中:log.txt

 

4, 将你的so文件COPY到 :out/target/product/imx51_bbg/symbols/system/lib/目录下

5,执行./panic.py log.txt  会列出相对应的信息,是哪个文件哪行报的错。一看就明白

6,执行./panic.py之前你得先配好环境,要不然会报:prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi-addr2line: not found

收藏

 http://lfp001.iteye.com/blog/741558

你可能感兴趣的:(调试JNI so所用到的一个脚本)