Created
April 3, 2012 02:37
-
-
Save suapapa/2288906 to your computer and use it in GitHub Desktop.
Android dev: call stack dump line parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# Copyright (C) 2008 The Android Open Source Project | |
# License at http://www.apache.org/licenses/LICENSE-2.0 | |
# Copyright (C) 2012 Homin Lee <[email protected]> | |
import os | |
import sys | |
import string | |
import re | |
SYMBOLS_DIR = os.path.join(os.getenv('OUT'), 'symbols') | |
TOOLCHAIN_PREFIX = './prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi-' | |
def callAddr2Line(lib = '', addr = ''): | |
#print SYMBOLS_DIR | |
#print lib, addr | |
if lib != "": | |
cmd = TOOLCHAIN_PREFIX + 'addr2line' \ | |
+ " -f -e " + SYMBOLS_DIR + lib \ | |
+ " 0x" + addr | |
#print cmd | |
stream = os.popen(cmd) | |
lines = stream.readlines() | |
list = map(string.strip, lines) | |
else: | |
list = [] | |
if list != []: | |
# Name like "move_forward_type<JavaVMOption>" causes troubles | |
mangled_name = re.sub('<', '\<', list[0]); | |
mangled_name = re.sub('>', '\>', mangled_name); | |
#print cmd | |
cmd = TOOLCHAIN_PREFIX + "c++filt" + " "\ | |
+ mangled_name | |
stream = os.popen(cmd) | |
list[0] = stream.readline() | |
stream.close() | |
list = map(string.strip, list) | |
else: | |
list = [ "(unknown)", "(unknown)" ] | |
return list | |
def prQuickfix(li): | |
print li[1]+': '+li[0] | |
if __name__ == '__main__': | |
if len(sys.argv) < 2: | |
print "usage: %s 0001ba0e /system/lib/libc.so"%sys.argv[0] | |
sys.exit(1) | |
if os.path.exists(sys.argv[1]): | |
for line in open(sys.argv[1]): | |
line = line.strip() | |
if not line: continue | |
addr, lib = line.split() | |
prQuickfix(callAddr2Line(lib, addr)) | |
else: | |
prQuickfix(callAddr2Line(sys.argv[2], sys.argv[1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment