您的位置:首页 > 移动开发 > Android开发

Android下调试.so库类的bug

2013-12-04 16:29 519 查看
在做dlna应用时遇到系统无法播放视频和音频文件,打印了一些debug信息,

I/DEBUG   (  795): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
I/DEBUG   (  795): Build fingerprint: 'unknown'
I/DEBUG   (  795): pid: 2830, tid: 3185, name: DOWNLOADMODULE  >>> /system/bin/mediaserver <<<
I/DEBUG   (  795): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000014
I/DEBUG   (  795):     r0 00000000  r1 00000000  r2 00000000  r3 fefeff00
I/DEBUG   (  795):     r4 4cc87008  r5 4d79e890  r6 425727c8  r7 00000000
I/DEBUG   (  795):     r8 4cc636bc  r9 40153a4c  sl 417bc2a0  fp 417bc2bc
I/DEBUG   (  795):     ip 4ccb9008  sp 4ce80d78  lr 417b6a6d  pc 417b6acc  cpsr 40000030
I/DEBUG   (  795):     d0  363731366334302e  d1  353665363736396d
I/DEBUG   (  795):     d2  3134303264323070  d3  3536333639366333
I/DEBUG   (  795):     d4  3436323731363336  d5  3337353764366632
I/DEBUG   (  795):     d6  3134663233363936  d7  6336393632373637
I/DEBUG   (  795):     d8  0000000000000000  d9  0000000000000000
I/DEBUG   (  795):     d10 0000000000000000  d11 0000000000000000
I/DEBUG   (  795):     d12 0000000000000000  d13 0000000000000000
I/DEBUG   (  795):     d14 0000000000000000  d15 0000000000000000
I/DEBUG   (  795):     d16 000000000d01e2ee  d17 000000000d01e0fa
I/DEBUG   (  795):     d18 00000000001591fe  d19 0000000000000000
I/DEBUG   (  795):     d20 0000000000000000  d21 0000000000000000
I/DEBUG   (  795):     d22 0000000000000000  d23 0000000000000000
I/DEBUG   (  795):     d24 0000000000000000  d25 0000000000000000
I/DEBUG   (  795):     d26 0000000000000000  d27 0000000000000000
I/DEBUG   (  795):     d28 0000000000000000  d29 0000000000000000
I/DEBUG   (  795):     d30 0000000000000000  d31 0000000000000000
I/DEBUG   (  795):     scr 20000010
I/DEBUG   (  795):
I/DEBUG   (  795): backtrace:
I/DEBUG   (  795):     #00  pc 000d8acc  /system/lib/libmmp.so
I/DEBUG   (  795):     #01  pc 00036d4f  /system/lib/libmmp.so
I/DEBUG   (  795):     #02  pc 00012bb0  /system/lib/libc.so (__thread_entry+48)
I/DEBUG   (  795):     #03  pc 00012308  /system/lib/libc.so (pthread_create+172)
I/DEBUG   (  795):
I/DEBUG   (  795): stack:
I/DEBUG   (  795):          4ce80d38  00000068
I/DEBUG   (  795):          4ce80d3c  4012de49  /system/lib/libc.so (__system_property_find+56)
I/DEBUG   (  795):          4ce80d40  4ce80d98  [stack:3185]
I/DEBUG   (  795):          4ce80d44  4012de8b  /system/lib/libc.so (__system_property_read+46)
I/DEBUG   (  795):          4ce80d48  c2060a42
I/DEBUG   (  795):          4ce80d4c  4cc87008
I/DEBUG   (  795):          4ce80d50  4ce80d98  [stack:3185]
I/DEBUG   (  795):          4ce80d54  00000000
I/DEBUG   (  795):          4ce80d58  00000000
I/DEBUG   (  795):          4ce80d5c  4cc636bc
I/DEBUG   (  795):          4ce80d60  40153a4c
I/DEBUG   (  795):          4ce80d64  40174573  /system/lib/libcutils.so (property_get+10)
I/DEBUG   (  795):          4ce80d68  4cc87008
I/DEBUG   (  795):          4ce80d6c  4d79e890
I/DEBUG   (  795):          4ce80d70  df0027ad
I/DEBUG   (  795):          4ce80d74  00000000
I/DEBUG   (  795):     #00  4ce80d78  00000000
I/DEBUG   (  795):          4ce80d7c  00000000
I/DEBUG   (  795):          4ce80d80  4014c54c
I/DEBUG   (  795):          4ce80d84  4011825b  /system/lib/libc.so (dlmalloc+5326)
I/DEBUG   (  795):          4ce80d88  00001000
I/DEBUG   (  795):          4ce80d8c  00000000
I/DEBUG   (  795):          4ce80d90  00000000
I/DEBUG   (  795):          4ce80d94  40153a4c
I/DEBUG   (  795):          4ce80d98  00000031
I/DEBUG   (  795):          4ce80d9c  40118571  /system/lib/libc.so (dlfree+56)
I/DEBUG   (  795):          4ce80da0  40118539  /system/lib/libc.so (dlfree)
I/DEBUG   (  795):          4ce80da4  00000000
I/DEBUG   (  795):          4ce80da8  00000000
I/DEBUG   (  795):          4ce80dac  00000000
I/DEBUG   (  795):          4ce80db0  00000001
I/DEBUG   (  795):          4ce80db4  42270698
I/DEBUG   (  795):          ........  ........
I/DEBUG   (  795):     #01  4ce80e20  00000000
I/DEBUG   (  795):          4ce80e24  00000000
I/DEBUG   (  795):          4ce80e28  00000000
I/DEBUG   (  795):          4ce80e2c  00000000
I/DEBUG   (  795):          4ce80e30  00000000
I/DEBUG   (  795):          4ce80e34  00000000
I/DEBUG   (  795):          4ce80e38  00000001
I/DEBUG   (  795):          4ce80e3c  00000001
I/DEBUG   (  795):          4ce80e40  4d79e890
I/DEBUG   (  795):          4ce80e44  00000000
I/DEBUG   (  795):          4ce80e48  00000000
I/DEBUG   (  795):          4ce80e4c  00000000
I/DEBUG   (  795):          4ce80e50  417c0a7a  /system/lib/libmmp.so
I/DEBUG   (  795):          4ce80e54  40153a4c
I/DEBUG   (  795):          4ce80e58  00001005
I/DEBUG   (  795):          4ce80e5c  00000030
I/DEBUG   (  795):          ........  ........
I/DEBUG   (  795):     #02  4ce80ef0  422703f0
I/DEBUG   (  795):          4ce80ef4  4ce80f00  [stack:3185]
I/DEBUG   (  795):          4ce80ef8  be807830  [stack]
I/DEBUG   (  795):          4ce80efc  4011530c  /system/lib/libc.so (pthread_create+176)
I/DEBUG   (  795):
I/DEBUG   (  795): memory near r4:
I/DEBUG   (  795):     4cc86fe8 4cc64fe0 00000001 00000000 00000007  .O.L............
I/DEBUG   (  795):     4cc86ff8 00000007 00000007 00000001 00032ff2  ............./..
I/DEBUG   (  795):     4cc87008 00000000 00000000 00000000 00000000  ................
I/DEBUG   (  795):     4cc87018 00000000 00000000 00000000 00000000  ................
I/DEBUG   (  795):     4cc87028 00000000 00000000 41815700 00000000  .........W.A....
I/DEBUG   (  795):
I/DEBUG   (  795): memory near r5:
I/DEBUG   (  795):     4d79e870 417b3f19 417b6a29 417b4cbd 417b3fb1  .?{A)j{A.L{A.?{A
I/DEBUG   (  795):     4d79e880 417b40ed 417b4241 417b44f1 4cc87008  .@{AAB{A.D{A.p.L
I/DEBUG   (  795):     4d79e890 00000000 00000000 00000000 00000000  ................
I/DEBUG   (  795):     4d79e8a0 00000000 00000000 00000000 00000000  ................
I/DEBUG   (  795):     4d79e8b0 00000000 00000000 00000000 00000000  ................
I/DEBUG   (  795):
I/DEBUG   (  795): memory near r6:
I/DEBUG   (  795):     425727a8 425728b0 42572940 4cb4e000 0000008b  .(WB@)WB...L....
I/DEBUG   (  795):     425727b8 00000001 0000006d 4170f4e5 4170f5bb  ....m.....pA..pA
I/DEBUG   (  795):     425727c8 70747468 312f2f3a 312e3239 312e3836  http://192.168.1 I/DEBUG   (  795):     425727d8 3931312e 3738343a 66322f31 65366436  .119:4871/2f6d6e
I/DEBUG   (  795):     425727e8 66323437 34363337 31363336 34363237  742f736463617264
I/DEBUG   (  795):


出现这样的log信息,一般都是c或c++代码的问题,只看这些log信息根本无法确定出错的代码。 这些log其实就是程序运行过程中函数调用在堆栈中的地址信息,直接通过那些地址我们是无法得知错误出在哪里,不过我们可以有种方式直接告诉我们是在调用库文件里面的哪个函数处出了问题。

调试过程如下:

1、首先取以上log信息中的从#00开始连续的那一部分,保存到一个文件里,再次将文件命名为log.txt 。



I/DEBUG   (  795):     #00  pc 000d8acc  /system/lib/libmmp.so
I/DEBUG   (  795):     #01  pc 00036d4f  /system/lib/libmmp.so


保存到log.txt文件中

2、使用panic.py解析该文件。

3、根据返回的信息调试程序。

运行该脚本返回的如下信息。

read file ok
BFD: Dwarf Error: mangled line number section.
mp4_config2.c:0               init_omx_aud_decoder
BFD: Dwarf Error: mangled line number section.
mp4_config2.c:0               handle_read_rebuffer


从返回的信息中可以知道错误出现在mp4_config2.c文件中的handle_read_rebuffer和init_omx_aud_decoderchu 这两个函数

panic.py脚本

#!/usr/bin/python
# stack symbol parser
import os
import string
import sys

#define android product name
ANDROID_PRODUCT_NAME = 'test'

ANDROID_WORKSPACE = os.getcwd()+"/"

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


注:ANDROID_PRODUCT_NAME 这个变量的值要根据你的项目名来设置,这个值可以在out目录的子目录下确定。

out/target/product/test/system 注意红色字体的位置,就是你们产品的项目名。将红色字体位置的名字赋给ANDROID_PRODUCT_NAME这个变量就行了。

也要注意arm-eabi-addr2line这个命令的位置,不同版本的android用的arm-eabi的编译版本不同,根据自己android编译工具的版本修改所在的目录

补充:

解决出现 ??:0 , 没法展示源代码行数的问题

在Android.mk 文件中:LOCAL_CFLAGS := -D__STDC_CONSTANT_MACROS -Wl,-Map=test.map -g

补充2个编译参数

-Wl,-Map=test.map -g

增加gcc警告和调试标志
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: