Chromium Code Reviews| Index: build/android/pylib/utils/symbolizer.py |
| diff --git a/build/android/pylib/utils/symbolizer.py b/build/android/pylib/utils/symbolizer.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..59c0e46c0a784f88b86333a49c2a388e0171fd18 |
| --- /dev/null |
| +++ b/build/android/pylib/utils/symbolizer.py |
| @@ -0,0 +1,89 @@ |
| +# Copyright 2017 The Chromium Authors. All rights reserved. |
|
agrieve
2017/07/21 14:12:46
nit: there's already a directory in pylib called "
jbudorick
2017/07/21 14:15:07
That sounds fine to me.
At some point, I want to
BigBossZhiling
2017/07/21 18:38:14
Done.
|
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +import os |
| +import re |
| +import shutil |
| +import tempfile |
| + |
| +from devil.utils import cmd_helper |
| +from pylib import constants |
| + |
| +STACK_TOOL = os.path.join(os.path.dirname(__file__), '..', '..', '..', '..', |
| + 'third_party', 'android_platform', 'development', |
| + 'scripts', 'stack') |
| + |
| +def _DeviceAbiToArch(device_abi): |
| + # The order of this list is significant to find the more specific match |
| + # (e.g., arm64) before the less specific (e.g., arm). |
| + arches = ['arm64', 'arm', 'x86_64', 'x86_64', 'x86', 'mips'] |
| + for arch in arches: |
| + if arch in device_abi: |
| + return arch |
| + raise RuntimeError('Unknown device ABI: %s' % device_abi) |
| + |
| + |
| +class Symbolizer(object): |
| + """ A helper class to symbolize stack. """ |
| + |
| + def __init__(self, apk_under_test=None, |
| + enable_relocation_packing=None): |
| + self.apk_under_test = apk_under_test |
| + self.enable_relocation_packing = enable_relocation_packing |
| + self.libs_dir = tempfile.mkdtemp() |
| + self.apk_libs = [] |
| + self.has_unzipped = False |
| + |
| + |
| + def __del__(self): |
| + if self.libs_dir: |
|
jbudorick
2017/07/21 13:46:23
nit: extract this into a separate function that __
BigBossZhiling
2017/07/21 18:38:14
Say this new function is named CleanUp. If the ins
|
| + shutil.rmtree(self.libs_dir) |
| + |
| + |
| + def UnzipAPK(self): |
|
jbudorick
2017/07/21 13:46:23
nit: add a docstring for this.
BigBossZhiling
2017/07/21 18:38:13
Done.
|
| + cmd_helper.GetCmdOutput( |
|
jbudorick
2017/07/21 13:46:23
This function should know the conditions under whi
BigBossZhiling
2017/07/21 18:38:13
Done.
|
| + ['unzip', '-o', self.apk_under_test, '-d', self.libs_dir]) |
| + self.has_unzipped = True |
| + if os.path.exists(os.path.join(self.libs_dir, 'lib')): |
| + for root, _, files in os.walk(os.path.join(self.libs_dir, |
| + 'lib')): |
| + for file_name in files: |
| + if file_name.endswith('.so'): |
| + self.apk_libs.append(os.path.join(root, file_name)) |
| + |
| + |
| + def ResolveSymbols(self, data_to_symbolize, device_abi, include_stack=True): |
| + """Run the stack tool for given input. |
| + |
| + Args: |
| + data_to_symbolize: a list of strings to symbolize. |
| + include_stack: boolean whether to include stack data in output. |
| + device_abi: the default ABI of the device which generated the tombstone. |
| + |
| + Yields: |
| + A string for each line of resolved stack output. |
| + """ |
| + # Check if the data_to_symbolize has an ABI listed, |
|
jbudorick
2017/07/21 13:46:23
I think this function should still attempt to unzi
BigBossZhiling
2017/07/21 18:38:14
Done.
|
| + # if so use this in preference to the device's default ABI. |
| + for line in data_to_symbolize: |
| + found_abi = re.search('ABI: \'(.+?)\'', line) |
|
jbudorick
2017/07/21 13:46:23
nit: compile this regex into a module-scope consta
BigBossZhiling
2017/07/21 18:38:14
Done.
|
| + if found_abi: |
| + device_abi = found_abi.group(1) |
| + arch = _DeviceAbiToArch(device_abi) |
| + if not arch: |
|
jbudorick
2017/07/21 13:46:23
nit: log a warning in this case.
BigBossZhiling
2017/07/21 18:38:14
Done.
|
| + return |
| + |
| + cmd = [STACK_TOOL, '--arch', arch, '--output-directory', |
| + constants.GetOutDirectory()] |
| + if self.enable_relocation_packing and self.apk_libs: |
| + for apk_lib in self.apk_libs: |
| + cmd.extend(['--packed-lib', apk_lib]) |
| + with tempfile.NamedTemporaryFile() as f: |
| + f.write('\n'.join(data_to_symbolize)) |
| + f.flush() |
| + _, output = cmd_helper.GetCmdStatusAndOutput(cmd + [f.name]) |
| + for line in output.splitlines(): |
| + if not include_stack and 'Stack Data:' in line: |
| + break |
| + yield line |