Author: Xu jianxiang (netpirate@gmail.com)
Date: 2010/03/06
Web: http://www.anymobile.org
The debugging procedure is as follows:
1. Save the abnormal address information to a text file and store it in the project root directory;
2. Use panic. py to parse the file;
3. debug the program based on the returned information (file name; row number; method name.
Take the Touch input Method of a third party as an example. The process is as follows:
# The English and handwriting of the input method are OK. When you operate the Chinese input method, an exception occurs and the keyboard disappears. The exception log is as follows:
02-05 06:41:19. 834 D/dalvikvm (751): Trying to load lib/system/lib/libimezi. so 0x43e2a788
02-05 06:41:19. 874 D/dalvikvm (751): Added shared lib/system/lib/libimezi. so 0x43e2a788
02-05 06:41:20. 035 I/DEBUG (551 ): **************************************** ********
02-05 06:41:20. 035 I/DEBUG (551): Build fingerprint: 'unknown'
02-05 06:41:20. 035 I/DEBUG (551): pid: 751, tid: 751 >>> com. htc. android. cime <
02-05 06:41:20. 045 I/DEBUG (551): signal 11 (SIGSEGV), fault addr 00000003
02-05 06:41:20. 045 I/DEBUG (551): r0 00000000 r1 00000000 r2 807248ec r3 807248ec
02-05 06:41:20. 055 I/debug (551): R4 00252d80 R5 00000004 R6 00000001 R7 00000000
02-05 06:41:20. 055 I/debug (551): R8 beff8550 R9 41459d28 10 41459d18 FP 00000000
02-05 06:41:20. 055 I/debug (551): IP 8072430c SP beff84f0 LR 80716b4f PC 80717bce CPSR 60000030
02-05 06:41:20. 135 I/debug (551): #00 PC 00017bce/system/lib/libimezi. So
02-05 06:41:20. 135 I/debug (551): #01 PC 00010f80/system/lib/libimezi. So
02-05 06:41:20. 145 I/debug (551): Stack:
02-05 06:41:20. 155 I/debug (551): beff84b0 ad083e10
02-05 06:41:20. 155 I/DEBUG (551): beff84b4 ad05d44f/system/lib/libdvm. so
02-05 06:41:20. 155 I/DEBUG (551): beff84b8 ad06b8a0/system/lib/libdvm. so
02-05 06:41:20. 155 I/DEBUG (551): beff84bc ad083e10
02-05 06:41:20. 167 I/DEBUG (551): beff84c0 43e2aa90
02-05 06:41:20. 175 I/DEBUG (551): beff84c4 00000003
02-05 06:41:20. 175 I/DEBUG (551): beff84c8 00000014
02-05 06:41:20. 185 I/DEBUG (551): beff84cc 80716b4f/system/lib/libimezi. so
# Save the exception log as a file: 20100205_ime.txt
02-05 06:41:20. 045 I/debug (551): R0 00000000 R1 00000000 R2 807248ec R3 807248ec
02-05 06:41:20. 055 I/debug (551): R4 00252d80 R5 00000004 R6 00000001 R7 00000000
02-05 06:41:20. 055 I/debug (551): R8 beff8550 R9 41459d28 10 41459d18 FP 00000000
02-05 06:41:20. 055 I/debug (551): IP 8072430c SP beff84f0 LR 80716b4f PC 80717bce CPSR 60000030
02-05 06:41:20. 135 I/debug (551): #00 PC 00017bce/system/lib/libimezi. So
02-05 06:41:20. 135 I/debug (551): #01 PC 00010f80/system/lib/libimezi. So
# Execute scripts
Xujianxiang @ wingdroid-clone :~ /Workspace/xujx/wing15 $./panic. py 20100205_ime.txt
Read file OK
/Home/xujianxiang/workspace/xujx/wing15/prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi-addr2line: '/home/xujianxiang/workspace/xujx/wing15/out/target/product/generic/symbols/system/lib/libimezi. so ': No such file
Traceback (most recent call last ):
File "./panic. py", line 69, in <module>
Print "%-30 s % s" % (list [1], list [0])
IndexError: list index out of range
# The library file is not found, because the file is third-party and is only stored in/out/target/product/generic/system/lib/libimezi. so, copy and save it to/out/target/product/generic/symbols/system/lib/libimezi. so, execute the script again
Xujianxiang @ wingdroid-clone :~ /Workspace/xujx/wing15 $./panic. py 20100205_ime.txt
Read file OK
Zi81keyd. c: 0 Zi8GetTableData
Zi81keyd. c: 0 Zi8InitializeDynamic
# An error occurred while parsing successfully. The zi8 library file is not found. The following library file is updated. The input method supports Chinese pinyin.
/System/lib/zi/Zi8DatPYP_CN.z8d
/System/lib/zi/Zi8DatPYS_CN.z8d
/System/lib/zi/Zi8DatZHA_CN.z8d
/System/lib/zi/Zi8DatZHA_HK.z8d
/System/lib/zi/Zi8DatZHA_TW.z8d
/System/lib/zi/Zi8DatZYP_TW.z8d
/System/lib/zi/Zi8DatZYS_TW.z8d
Attached panic. py:
1 #! /Usr/bin/python
2 # stack symbol parser
3
4 import OS
5 import string
6 import sys
7
8 # define android product name
9 # ANDROID_PRODUCT_NAME = 'generic'
10ANDROID_PRODUCT_NAME = 'smdk6410'
11
12ANDROID_WORKSPACE = OS. getcwd () + "/"
13
14 # addr2line tool path and symbol path
15addr2line_tool = ANDROID_WORKSPACE + 'prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin'
16symbol_dir = ANDROID_WORKSPACE + 'out/target/product/'+ ANDROID_PRODUCT_NAME +'/symbols'
17symbol_bin = symbol_dir + '/system/bin /'
18symbol_lib = symbol_dir + '/system/lib /'
19
20 class ReadLog:
21 def _ init _ (self, filename ):
22 self. logname = filename
23 def parse (self ):
24 f = file (self. logname, 'R ')
25 lines = f. readlines ()
26 if lines! = []:
27 print 'read file OK'
28 else:
29 print 'read file failed'
30 result = []
31 for line in lines:
32 if line. find ('stack ')! =-1:
33 print 'Stop search'
34. break
35 elif line. find ('system ')! =-1:
36 # print 'Find one item' + line
37 result. append (line)
38 return result
39
40 class ParseContent:
41 def _ init _ (self, addr, lib ):
42 self. address = addr # pc address
43 self.exe name = lib # executable or shared library
44 def addr2line (self ):
45 cmd = addr2line_tool + "-C-f-s-e" + symbol_dir + self.exe name + "" + self. address
46 # print cmd
47 stream = OS. popen (cmd)
48 lines = stream. readlines ();
49 list = map (string. strip, lines)
50 return list
51
52 inputarg = sys. argv
53if len (inputarg) <2:
54 print 'Please input panic Log'
55 exit ()
56
57 filename = inputarg [1]
58 readlog = readlog (filename)
59 inputlist = readlog. parse ()
60
61for item in inputlist:
62 itemsplit = item. Split ()
63 test = parsecontent (itemsplit [-2], itemsplit [-1])
64 list = test. addr2line ()
65 print "%-30 S % s" % (list [1], list [0])
66