Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 import os | |
| 6 import re | |
| 7 import subprocess | |
| 8 | |
| 9 from pylib import constants | |
| 10 | |
| 11 | |
| 12 def _DeviceAbiToArch(device_abi): | |
| 13 # The order of this list is significant to find the more specific match | |
| 14 # (e.g., arm64) before the less specific (e.g., arm). | |
| 15 arches = ['arm64', 'arm', 'x86_64', 'x86_64', 'x86', 'mips'] | |
| 16 for arch in arches: | |
| 17 if arch in device_abi: | |
| 18 return arch | |
| 19 raise RuntimeError('Unknown device ABI: %s' % device_abi) | |
| 20 | |
| 21 | |
| 22 class Symbolizer(object): | |
| 23 """ A helper class to symbolize stack. """ | |
| 24 | |
| 25 def __init__(self, apk_under_test=None, | |
| 26 enable_relocation_packing=None, libs_dir=None): | |
| 27 self.apk_under_test = apk_under_test | |
| 28 self.enable_relocation_packing = enable_relocation_packing | |
| 29 self.libs_dir = libs_dir | |
| 30 self.packed_libs = [] | |
|
jbudorick
2017/07/20 15:58:04
nit: maybe apk_libs rather than packed_libs, since
BigBossZhiling
2017/07/20 23:11:37
Done.
| |
| 31 self.has_unzipped = False | |
| 32 | |
| 33 | |
| 34 def UnzipAPK(self): | |
|
jbudorick
2017/07/20 15:58:04
I don't think clients should explicitly call this,
BigBossZhiling
2017/07/20 23:11:38
Let the clients call UnzipAPK, so that the clients
| |
| 35 subprocess.check_call( | |
|
jbudorick
2017/07/20 15:58:04
nit: cmd_helper.GetCommandStatusAndOutput, though
BigBossZhiling
2017/07/20 23:11:38
Done.
| |
| 36 ['unzip', '-o', self.apk_under_test, '-d', self.libs_dir]) | |
| 37 self.has_unzipped = True | |
| 38 if os.path.exists(os.path.join(self.libs_dir, 'lib')): | |
| 39 for root, _, files in os.walk(os.path.join(self.libs_dir, | |
| 40 'lib')): | |
| 41 for file_name in files: | |
| 42 if file_name.endswith('.so'): | |
| 43 self.packed_libs.append(os.path.join(root, file_name)) | |
| 44 | |
| 45 | |
| 46 def ResolveSymbols(self, data_to_symbolize, include_stack, device_abi): | |
| 47 """Run the stack tool for given input. | |
| 48 | |
| 49 Args: | |
| 50 data_to_symbolize: a list of strings to symbolize. | |
| 51 include_stack: boolean whether to include stack data in output. | |
|
jbudorick
2017/07/20 15:58:04
Would it make sense for this to have a default?
BigBossZhiling
2017/07/20 23:11:38
Done.
| |
| 52 device_abi: the default ABI of the device which generated the tombstone. | |
| 53 | |
| 54 Yields: | |
| 55 A string for each line of resolved stack output. | |
| 56 """ | |
| 57 | |
| 58 if (not self.has_unzipped and self.enable_relocation_packing | |
| 59 and self.apk_under_test): | |
| 60 self.UnzipAPK() | |
| 61 | |
| 62 # Check if the data_to_symbolize has an ABI listed, | |
| 63 # if so use this in preference to the device's default ABI. | |
| 64 for line in data_to_symbolize: | |
| 65 found_abi = re.search('ABI: \'(.+?)\'', line) | |
| 66 if found_abi: | |
| 67 device_abi = found_abi.group(1) | |
| 68 arch = _DeviceAbiToArch(device_abi) | |
| 69 if not arch: | |
| 70 return | |
| 71 | |
| 72 stack_tool = os.path.join(os.path.dirname(__file__), '..', '..', '..', '..', | |
|
jbudorick
2017/07/20 15:58:04
nit: This should be a constant at module scope.
BigBossZhiling
2017/07/20 23:11:38
Done.
| |
| 73 'third_party', 'android_platform', 'development', | |
| 74 'scripts', 'stack') | |
| 75 cmd = [stack_tool, '--arch', arch, '--output-directory', | |
| 76 constants.GetOutDirectory()] | |
| 77 if self.enable_relocation_packing and self.packed_libs: | |
| 78 for packed_lib in self.packed_libs: | |
| 79 cmd.extend(['--packed-lib', packed_lib]) | |
| 80 proc = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE) | |
|
jbudorick
2017/07/20 15:58:04
Use cmd_helper.GetCommandStatusAndOutput here inst
BigBossZhiling
2017/07/20 23:11:38
Done.
| |
| 81 output = proc.communicate(input='\n'.join(data_to_symbolize))[0] | |
| 82 for line in output.split('\n'): | |
|
jbudorick
2017/07/20 15:58:03
nit: output.splitlines()?
BigBossZhiling
2017/07/20 23:11:38
Done.
| |
| 83 if not include_stack and 'Stack Data:' in line: | |
| 84 break | |
| 85 yield line | |
| OLD | NEW |