Index: third_party/android_platform/development/scripts/symbol.py |
diff --git a/tools/android_stack_parser/symbol.py b/third_party/android_platform/development/scripts/symbol.py |
similarity index 91% |
copy from tools/android_stack_parser/symbol.py |
copy to third_party/android_platform/development/scripts/symbol.py |
index 5feb45b997fa558212fe9088454d3ee63dd71151..5069d9e0f350687a4e60437940bb838c602ffaa9 100755 |
--- a/tools/android_stack_parser/symbol.py |
+++ b/third_party/android_platform/development/scripts/symbol.py |
@@ -27,7 +27,7 @@ import subprocess |
import zipfile |
CHROME_SRC = os.path.join(os.path.realpath(os.path.dirname(__file__)), |
- os.pardir, os.pardir) |
+ os.pardir, os.pardir, os.pardir, os.pardir) |
ANDROID_BUILD_TOP = CHROME_SRC |
SYMBOLS_DIR = CHROME_SRC |
CHROME_SYMBOLS_DIR = CHROME_SRC |
@@ -64,7 +64,7 @@ def ToolPath(tool, toolchain_info=None): |
toolchain_source = "x86-4.9" |
toolchain_prefix = "i686-linux-android" |
ndk = "ndk" |
- elif ARCH == "x86_64" or ARCH == "x64": |
+ elif ARCH == "x86_64": |
toolchain_source = "x86_64-4.9" |
toolchain_prefix = "x86_64-linux-android" |
ndk = "ndk" |
@@ -110,7 +110,7 @@ def FindToolchain(): |
known_toolchains = [ |
("x86-" + gcc_version, "x86", "i686-linux-android") |
] |
- elif ARCH =="x86_64" or ARCH =="x64": |
+ elif ARCH =="x86_64": |
known_toolchains = [ |
("x86_64-" + gcc_version, "x86_64", "x86_64-linux-android") |
] |
@@ -184,30 +184,32 @@ def PathListJoin(prefix_list, suffix_list): |
os.path.join(prefix, suffix) |
for prefix in prefix_list for suffix in suffix_list ] |
-def GetCandidates(filepart, candidate_fun, relative_dirs=None): |
+def GetCandidates(dirs, filepart, candidate_fun): |
"""Returns a list of candidate filenames. |
Args: |
+ dirs: a list of the directory part of the pathname. |
filepart: the file part of the pathname. |
candidate_fun: a function to apply to each candidate, returns a list. |
- relative_dirs: a list of relative directory names to search from. |
Returns: |
A list of candidate files ordered by modification time, newest first. |
""" |
- candidates = [CHROME_SYMBOLS_DIR] |
- |
- # Add the two possible mojo outdirs. |
- out_dir = os.path.join(CHROME_SYMBOLS_DIR, 'out') |
- candidates += PathListJoin([out_dir], ['android_Debug', 'android_Release']) |
- |
- if relative_dirs: |
- candidates = PathListJoin(candidates, relative_dirs) |
+ out_dir = os.environ.get('CHROMIUM_OUT_DIR', 'out') |
+ out_dir = os.path.join(CHROME_SYMBOLS_DIR, out_dir) |
+ buildtype = os.environ.get('BUILDTYPE') |
+ if buildtype: |
+ buildtype_list = [ buildtype ] |
+ else: |
+ buildtype_list = [ 'Debug', 'Release' ] |
+ candidates = PathListJoin([out_dir], buildtype_list) + [CHROME_SYMBOLS_DIR] |
+ candidates = PathListJoin(candidates, dirs) |
candidates = PathListJoin(candidates, [filepart]) |
candidates = list( |
itertools.chain.from_iterable(map(candidate_fun, candidates))) |
candidates = sorted(candidates, key=os.path.getmtime, reverse=True) |
+ # candidates = ['/usr/local/google/home/qsr/programmes/mojo/src/out/android_Debug/libmojo_shell.so'] |
return candidates |
def GetCandidateApks(): |
@@ -219,7 +221,7 @@ def GetCandidateApks(): |
Returns: |
list of APK filename which could contain the library. |
""" |
- return GetCandidates('*.apk', glob.glob, relative_dirs=['apks']) |
+ return GetCandidates(['apks'], '*.apk', glob.glob) |
def GetCrazyLib(apk_filename): |
"""Returns the name of the first crazy library from this APK. |
@@ -279,22 +281,16 @@ def GetCandidateLibraries(library_name): |
A list of matching library filenames for library_name. |
""" |
return GetCandidates( |
- library_name, |
+ ['', 'lib', 'lib.target'], library_name, |
lambda filename: filter(os.path.exists, [filename])) |
-def TranslatePathFromDeviceToLocal(lib): |
- """Maps a path as seen on the device to a path on the local file system |
- containing symbols. |
- |
- Args: |
- lib: library (or executable) pathname from device. |
- """ |
- |
- # SymbolInformation(lib, addr) receives lib that is either a basename or |
- # the path from symbols root to the symbols file. This needs to be translated |
- # to point to the correct .so path. If the user doesn't explicitly specify |
- # which directory to use, then use the most recently updated one in one of |
- # the known directories. |
+def TranslateLibPath(lib): |
+ # SymbolInformation(lib, addr) receives lib as the path from symbols |
+ # root to the symbols file. This needs to be translated to point to the |
+ # correct .so path. If the user doesn't explicitly specify which directory to |
+ # use, then use the most recently updated one in one of the known directories. |
+ # If the .so is not found somewhere in CHROME_SYMBOLS_DIR, leave it |
+ # untranslated in case it is an Android symbol in SYMBOLS_DIR. |
library_name = os.path.basename(lib) |
# The filename in the stack trace maybe an APK name rather than a library |
@@ -310,8 +306,11 @@ def TranslatePathFromDeviceToLocal(lib): |
library_name = mapping |
candidate_libraries = GetCandidateLibraries(library_name) |
- return (candidate_libraries[0] if candidate_libraries else |
- os.path.join(SYMBOLS_DIR, lib)) |
+ if not candidate_libraries: |
+ return lib |
+ |
+ library_path = os.path.relpath(candidate_libraries[0], SYMBOLS_DIR) |
+ return '/' + library_path |
def SymbolInformation(lib, addr, get_detailed_info): |
"""Look up symbol information about an address. |
@@ -332,7 +331,7 @@ def SymbolInformation(lib, addr, get_detailed_info): |
Usually you want to display the source_location and |
object_symbol_with_offset from the last element in the list. |
""" |
- lib = TranslatePathFromDeviceToLocal(lib) |
+ lib = TranslateLibPath(lib) |
info = SymbolInformationForSet(lib, set([addr]), get_detailed_info) |
return (info and info.get(addr)) or [(None, None, None)] |
@@ -423,12 +422,17 @@ def CallAddr2LineForSet(lib, unique_addrs): |
more than one element with the symbols for the most deeply |
nested inlined location appearing first. |
""" |
- if not lib or not os.path.isfile(lib): |
+ if not lib: |
+ return None |
+ |
+ |
+ symbols = SYMBOLS_DIR + lib |
+ if not os.path.isfile(symbols): |
return None |
(label, platform, target) = FindToolchain() |
cmd = [ToolPath("addr2line"), "--functions", "--inlines", |
- "--demangle", "--exe=" + lib] |
+ "--demangle", "--exe=" + symbols] |
child = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE) |
result = {} |