Original address: http://blog.csdn.net/andyhuabing/article/details/7074979
These two methods are not I invented, are online some of the master public out of the debugging method, but can not find the source of the place, so in this summary, to facilitate the debugging of Android:
Brief description:
Debugging Java in the Android system is very easy, generally encountered errors in the Logcat printing error when the function of the call relationship,
and C library in error only see some binary information, using Gdbserver debugging environment to build and more complex.
Method One:
Under the introduction of a simple debugging library method, 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 at the time of the error (above)
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
b) Enter the directory of the so library with the symbol table in the source code
$ cd out/target/product/generic/obj/shared_libraries/libmultiplayerservice_intermediates/linked
Here's a place to be aware of:
For executables and dynamic libraries, typically in the linked subdirectory is a library with symbols (no sign-off), if the executable file does not include debug symbols, you will get??: 0 as a response.
c) Use the Addr2line command to find the address corresponding to the program location, the dynamic library for libmultiplayerservice.so
arm-eabi-addr2line Span style= "FONT-SIZE:16PX;" >000078e6-e libmultiplayerservice.so
results: shows the corresponding program file and number of lines, if not the debug version, there may be one or two line deviations
frameworks/base/ services/multiplayerservice/playersocket.cpp 421 rows
d) Note
arm-eabi_addr2line in Prebuild/linux-x86/toolchain/arm-eabi-xxx/bin directory,
Method Two:
1, first need an important script file:
#!/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])
Save the above file hy.panic.py
2, the related crash stack information save Error.txt
For example:
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, copy the above two files to the Android root path under the compiler, execute
Python hy.panic.py error.txt
Method 2 is very convenient to use, compared to the printing efficiency greatly improved. Thank you very much for scripting students.
Android Dynamic Library crash debugging method.