Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: build/android/pylib/symbols/stack_symbolizer.py

Issue 2974163002: Fix the stack script issue when symbolizing tombstones. (Closed)
Patch Set: remove changes in gcc_toolchain and change GNGen instead Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 logging
6 import os
7 import re
8 import shutil
9 import tempfile
10
11 from devil.utils import cmd_helper
12 from pylib import constants
13
14 STACK_TOOL = os.path.join(os.path.dirname(__file__), '..', '..', '..', '..',
agrieve 2017/07/26 01:26:10 nit: prefix with _
BigBossZhiling 2017/07/26 17:36:26 Done.
15 'third_party', 'android_platform', 'development',
16 'scripts', 'stack')
17 ABI_REG = re.compile('ABI: \'(.+?)\'')
18
agrieve 2017/07/26 01:26:10 nit: 2 blank lines
BigBossZhiling 2017/07/26 17:36:26 Done.
19 def _DeviceAbiToArch(device_abi):
20 # The order of this list is significant to find the more specific match
21 # (e.g., arm64) before the less specific (e.g., arm).
22 arches = ['arm64', 'arm', 'x86_64', 'x86_64', 'x86', 'mips']
23 for arch in arches:
24 if arch in device_abi:
25 return arch
26 raise RuntimeError('Unknown device ABI: %s' % device_abi)
27
28
29 class Symbolizer(object):
30 """ A helper class to symbolize stack. """
agrieve 2017/07/26 01:26:10 nit: remove spaces before/after """
BigBossZhiling 2017/07/26 17:36:27 Done.
31
32 def __init__(self, apk_under_test=None,
33 enable_relocation_packing=None):
34 self.apk_under_test = apk_under_test
agrieve 2017/07/26 01:26:10 nit: prefix with _ unless you need these to be pub
BigBossZhiling 2017/07/26 17:36:26 Done.
35 self.enable_relocation_packing = enable_relocation_packing
36 self.libs_dir = None
37 self.apk_libs = []
38 self.has_unzipped = False
39
40
41 def __del__(self):
42 self.CleanUp()
agrieve 2017/07/26 01:26:10 Maybe log a warning if CleanUp() has not already b
BigBossZhiling 2017/07/26 17:36:27 Done.
43
44
45 def CleanUp(self):
46 """ Clean up the temporary directory of apk libs. """
47 if self.libs_dir:
48 shutil.rmtree(self.libs_dir)
49 self.libs_dir = None
50
51
52 def UnzipAPKIfNecessary(self):
53 """ Unzip apk if packed relocation is enabled. """
54 if (self.has_unzipped
55 or not self.enable_relocation_packing
56 or not self.apk_under_test):
57 return
58 self.libs_dir = tempfile.mkdtemp()
59 cmd_helper.GetCmdOutput(
agrieve 2017/07/26 01:26:10 Python's zipfile module makes extracting easy. You
BigBossZhiling 2017/07/26 17:36:26 Done.
60 ['unzip', '-o', self.apk_under_test, '-d', self.libs_dir])
61 self.has_unzipped = True
62 if os.path.exists(os.path.join(self.libs_dir, 'lib')):
63 for root, _, files in os.walk(os.path.join(self.libs_dir,
64 'lib')):
65 for file_name in files:
66 if file_name.endswith('.so'):
67 self.apk_libs.append(os.path.join(root, file_name))
68
69
70 def ResolveSymbols(self, data_to_symbolize, device_abi, include_stack=True):
agrieve 2017/07/26 01:26:10 This is somewhat misleading. While the stack tool
BigBossZhiling 2017/07/26 17:36:26 Done.
71 """Run the stack tool for given input.
72
73 Args:
74 data_to_symbolize: a list of strings to symbolize.
75 include_stack: boolean whether to include stack data in output.
76 device_abi: the default ABI of the device which generated the tombstone.
77
78 Yields:
79 A string for each line of resolved stack output.
80 """
81 self.UnzipAPKIfNecessary()
82 # Check if the data_to_symbolize has an ABI listed,
83 # if so use this in preference to the device's default ABI.
84 for line in data_to_symbolize:
85 found_abi = ABI_REG.match(line)
agrieve 2017/07/26 01:26:10 The stack script already does this logic: https://
BigBossZhiling 2017/07/26 17:36:26 Done.
86 if found_abi:
87 device_abi = found_abi.group(1)
88 arch = _DeviceAbiToArch(device_abi)
89 if not arch:
90 logging.warning('No device_abi can be found.')
91 return
92
93 cmd = [STACK_TOOL, '--arch', arch, '--output-directory',
94 constants.GetOutDirectory()]
95 if self.enable_relocation_packing and self.apk_libs:
96 for apk_lib in self.apk_libs:
97 cmd.extend(['--packed-lib', apk_lib])
98 with tempfile.NamedTemporaryFile() as f:
99 f.write('\n'.join(data_to_symbolize))
100 f.flush()
101 _, output = cmd_helper.GetCmdStatusAndOutput(cmd + [f.name])
102 for line in output.splitlines():
103 if not include_stack and 'Stack Data:' in line:
agrieve 2017/07/26 01:26:10 Won't this skip over other stack traces that are i
BigBossZhiling 2017/07/26 17:36:27 My understanding is that stack trace and stack dat
agrieve 2017/07/26 17:50:38 Actually, it looks like these lines are added only
BigBossZhiling 2017/07/26 18:36:58 Acknowledged. I didn't notice there is a more-info
104 break
105 yield line
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698