These two methods are not invented by me. They are all public debugging methods provided by some experts on the Internet, but cannot find the source. So let's sum up here to facilitate debugging in Android:
Brief description:
It is very easy to debug Java in the Android system. Generally, when errors occur, the call relationship of the function is printed in logcat,
When an error occurs in the C library, only some binary information is displayed. It is complicated to use the gdbserver debugging environment.
Method 1:
Next we will introduce a simple method for debugging the library. Of course, the source code of the so library is required.
Example
A) the error message is as follows, which indicates the function call relationship when an error occurs (as shown in the following code)
I/debug (634): #00 PC ipv78e6/system/lib/libmultiplayerservice. So
I/debug (634): #01 PC route 87bc/system/lib/libmultiplayerservice. So
I/debug (634): #02 PC worker e94e/system/lib/libsensorservice. So
I/debug (634): #03 PC plugin a790/system/lib/libsensorservice. So
I/debug (634): #04 PC ipvd4b2/system/lib/libsensorservice. So
I/debug (634): #05 PC route d852/system/lib/libsensorservice. So
I/debug (634): #06 PC 00015ece/system/lib/libutils. So
I/debug (634): #07 PC versions 153a/system/lib/libsystem_server.so
I/debug (634): #08 PC 00001756/system/lib/libsystem_server.so
I/debug (634): #09 PC release adb8/system/lib/libandroid_servers.so
I/debug (634): #10 pc 00011cb4/system/lib/libdvm. So
B) Go to the directory where the so library of the signed table in the source code is located.
$ CD out/target/product/generic/obj/shared_libraries/libmultiplayerservice_intermediates/linked
Note the following:
For executable programs and dynamic libraries, the linked sub-directory is generally a signed Library (without being stripped by symbols). If the executable file does not contain debugging symbols, you will get ?? : 0 as the response.
C) run the addr2line command to find the program location corresponding to the address. The dynamic library is libmultiplayerservice. So.
Arm-eabi-addr2line
201778e6-e libmultiplayerservice. So
Result: The corresponding program file and number of lines are displayed. If it is not the debug version, there may be one or two lines of deviation.
Frameworks/base/services/multiplayerservice/playersocket. cpp row 421
D) Note
The arm-eabi_addr2line is in the prebuild/linux-x86/toolchain/ARM-Eabi-xxx/bin directory,
Run build/envsetup. SH and use it directly. The objdump and NM commands in the same directory are also common Debugging commands.
Method 2:
1. First, an important script file is required:
#! /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'
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.exe name = lib # executable or shared library
Def addr2line (Self ):
Cmd = addr2line_tool + "-C-F-s-e" + symbol_dir + self.exe name + "" + 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 "%-30 S % s" % (list [1], list [0])
Save Hy. Panic. py
2. Storage of related dead-end stack information error.txt
For example:
I/debug (634): #00 PC ipv78e6/system/lib/libmultiplayerservice. So
I/debug (634): #01 PC route 87bc/system/lib/libmultiplayerservice. So
I/debug (634): #02 PC worker e94e/system/lib/libsensorservice. So
I/debug (634): #03 PC plugin a790/system/lib/libsensorservice. So
I/debug (634): #04 PC ipvd4b2/system/lib/libsensorservice. So
I/debug (634): #05 PC route d852/system/lib/libsensorservice. So
I/debug (634): #06 PC 00015ece/system/lib/libutils. So
I/debug (634): #07 PC versions 153a/system/lib/libsystem_server.so
I/debug (634): #08 PC 00001756/system/lib/libsystem_server.so
I/debug (634): #09 PC release adb8/system/lib/libandroid_servers.so
I/debug (634): #10 pc 00011cb4/system/lib/libdvm. So
3. Copy the preceding two files to the android compiling root path and run
Python Hy. Panic. py error.txt
Method 2 is very convenient to use, which is much more efficient than printing. Thank you very much for providing scripts.