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

Unified Diff: build/android/pylib/utils/symbolizer.py

Issue 2974163002: Fix the stack script issue when symbolizing tombstones. (Closed)
Patch Set: created symbolizer.py 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 side-by-side diff with in-line comments
Download patch
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..f9496f6ae22dbb2bc3ea66554ad9e3960e7b98a3
--- /dev/null
+++ b/build/android/pylib/utils/symbolizer.py
@@ -0,0 +1,85 @@
+# Copyright 2017 The Chromium Authors. All rights reserved.
+# 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 subprocess
+
+from pylib import constants
+
+
+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, libs_dir=None):
+ self.apk_under_test = apk_under_test
+ self.enable_relocation_packing = enable_relocation_packing
+ self.libs_dir = libs_dir
+ 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.
+ self.has_unzipped = False
+
+
+ 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
+ subprocess.check_call(
jbudorick 2017/07/20 15:58:04 nit: cmd_helper.GetCommandStatusAndOutput, though
BigBossZhiling 2017/07/20 23:11:38 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.packed_libs.append(os.path.join(root, file_name))
+
+
+ def ResolveSymbols(self, data_to_symbolize, include_stack, device_abi):
+ """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.
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.
+ device_abi: the default ABI of the device which generated the tombstone.
+
+ Yields:
+ A string for each line of resolved stack output.
+ """
+
+ if (not self.has_unzipped and self.enable_relocation_packing
+ and self.apk_under_test):
+ self.UnzipAPK()
+
+ # Check if the data_to_symbolize has an ABI listed,
+ # if so use this in preference to the device's default ABI.
+ for line in data_to_symbolize:
+ found_abi = re.search('ABI: \'(.+?)\'', line)
+ if found_abi:
+ device_abi = found_abi.group(1)
+ arch = _DeviceAbiToArch(device_abi)
+ if not arch:
+ return
+
+ 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.
+ 'third_party', 'android_platform', 'development',
+ 'scripts', 'stack')
+ cmd = [stack_tool, '--arch', arch, '--output-directory',
+ constants.GetOutDirectory()]
+ if self.enable_relocation_packing and self.packed_libs:
+ for packed_lib in self.packed_libs:
+ cmd.extend(['--packed-lib', packed_lib])
+ 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.
+ output = proc.communicate(input='\n'.join(data_to_symbolize))[0]
+ for line in output.split('\n'):
jbudorick 2017/07/20 15:58:03 nit: output.splitlines()?
BigBossZhiling 2017/07/20 23:11:38 Done.
+ if not include_stack and 'Stack Data:' in line:
+ break
+ yield line

Powered by Google App Engine
This is Rietveld 408576698