OLD | NEW |
---|---|
(Empty) | |
1 # 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.
| |
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 shutil | |
8 import tempfile | |
9 | |
10 from devil.utils import cmd_helper | |
11 from pylib import constants | |
12 | |
13 STACK_TOOL = os.path.join(os.path.dirname(__file__), '..', '..', '..', '..', | |
14 'third_party', 'android_platform', 'development', | |
15 'scripts', 'stack') | |
16 | |
17 def _DeviceAbiToArch(device_abi): | |
18 # The order of this list is significant to find the more specific match | |
19 # (e.g., arm64) before the less specific (e.g., arm). | |
20 arches = ['arm64', 'arm', 'x86_64', 'x86_64', 'x86', 'mips'] | |
21 for arch in arches: | |
22 if arch in device_abi: | |
23 return arch | |
24 raise RuntimeError('Unknown device ABI: %s' % device_abi) | |
25 | |
26 | |
27 class Symbolizer(object): | |
28 """ A helper class to symbolize stack. """ | |
29 | |
30 def __init__(self, apk_under_test=None, | |
31 enable_relocation_packing=None): | |
32 self.apk_under_test = apk_under_test | |
33 self.enable_relocation_packing = enable_relocation_packing | |
34 self.libs_dir = tempfile.mkdtemp() | |
35 self.apk_libs = [] | |
36 self.has_unzipped = False | |
37 | |
38 | |
39 def __del__(self): | |
40 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
| |
41 shutil.rmtree(self.libs_dir) | |
42 | |
43 | |
44 def UnzipAPK(self): | |
jbudorick
2017/07/21 13:46:23
nit: add a docstring for this.
BigBossZhiling
2017/07/21 18:38:13
Done.
| |
45 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.
| |
46 ['unzip', '-o', self.apk_under_test, '-d', self.libs_dir]) | |
47 self.has_unzipped = True | |
48 if os.path.exists(os.path.join(self.libs_dir, 'lib')): | |
49 for root, _, files in os.walk(os.path.join(self.libs_dir, | |
50 'lib')): | |
51 for file_name in files: | |
52 if file_name.endswith('.so'): | |
53 self.apk_libs.append(os.path.join(root, file_name)) | |
54 | |
55 | |
56 def ResolveSymbols(self, data_to_symbolize, device_abi, include_stack=True): | |
57 """Run the stack tool for given input. | |
58 | |
59 Args: | |
60 data_to_symbolize: a list of strings to symbolize. | |
61 include_stack: boolean whether to include stack data in output. | |
62 device_abi: the default ABI of the device which generated the tombstone. | |
63 | |
64 Yields: | |
65 A string for each line of resolved stack output. | |
66 """ | |
67 # 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.
| |
68 # if so use this in preference to the device's default ABI. | |
69 for line in data_to_symbolize: | |
70 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.
| |
71 if found_abi: | |
72 device_abi = found_abi.group(1) | |
73 arch = _DeviceAbiToArch(device_abi) | |
74 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.
| |
75 return | |
76 | |
77 cmd = [STACK_TOOL, '--arch', arch, '--output-directory', | |
78 constants.GetOutDirectory()] | |
79 if self.enable_relocation_packing and self.apk_libs: | |
80 for apk_lib in self.apk_libs: | |
81 cmd.extend(['--packed-lib', apk_lib]) | |
82 with tempfile.NamedTemporaryFile() as f: | |
83 f.write('\n'.join(data_to_symbolize)) | |
84 f.flush() | |
85 _, output = cmd_helper.GetCmdStatusAndOutput(cmd + [f.name]) | |
86 for line in output.splitlines(): | |
87 if not include_stack and 'Stack Data:' in line: | |
88 break | |
89 yield line | |
OLD | NEW |