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

Unified Diff: build/android/symbolize.py

Issue 18473004: Android: adds stack symbolization utilities. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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
« no previous file with comments | « build/android/asan_symbolize.py ('k') | build/android/symbolize_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/symbolize.py
diff --git a/build/android/symbolize.py b/build/android/symbolize.py
new file mode 100755
index 0000000000000000000000000000000000000000..909d6615341f29df71fcbdcdc1c390305014b4fd
--- /dev/null
+++ b/build/android/symbolize.py
@@ -0,0 +1,80 @@
+#!/usr/bin/env python
+#
+# Copyright (c) 2013 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.
+
+"""Symbolizes stack traces generated by Chromium for Android.
+
+Sample usage:
+ adb logcat chromium:V | symbolize.py
+"""
+
+import os
+import re
+import sys
+
+from pylib import constants
+
+# Uses symbol.py from third_party/android_platform, not python's.
+sys.path.insert(0,
+ os.path.join(constants.DIR_SOURCE_ROOT,
+ 'third_party/android_platform/development/scripts'))
+import symbol
+
+# Sample output from base/debug/stack_trace_android.cc
+#00 pc 000634c1 /data/app-lib/org.chromium.native_test-1/libbase_unittests.so
+TRACE_LINE = re.compile('(?P<frame>\#[0-9]+) pc (?P<addr>[0-9a-f]{8,8}) '
+ '(?P<lib>[^\r\n \t]+)')
+
+class Symbolizer(object):
+ def __init__(self, file_in, file_out):
+ self.file_in = file_in
+ self.file_out = file_out
+
+ def ProcessInput(self):
+ for line in self.file_in:
+ match = re.search(TRACE_LINE, line)
+ if not match:
+ self.file_out.write(line)
+ self.file_out.flush()
+ continue
+
+ frame = match.group('frame')
+ lib = match.group('lib')
+ addr = match.group('addr')
+
+ # TODO(scherkus): Doing a single lookup per line is pretty slow,
+ # especially with larger libraries. Consider caching strategies such as:
+ # 1) Have Python load the libraries and do symbol lookups instead of
+ # calling out to addr2line each time.
+ # 2) Have Python keep multiple addr2line instances open as subprocesses,
+ # piping addresses and reading back symbols as we find them
+ # 3) Read ahead the entire stack trace until we find no more, then batch
+ # the symbol lookups.
+ #
+ # TODO(scherkus): These results are memoized, which could result in
+ # incorrect lookups when running this script on long-lived instances
+ # (e.g., adb logcat) when doing incremental development. Consider clearing
+ # the cache when modification timestamp of libraries change.
+ sym = symbol.SymbolInformation(lib, addr, False)[0][0]
+
+ if not sym:
+ self.file_out.write(line)
+ self.file_out.flush()
+ continue
+
+ pre = line[0:match.start('frame')]
+ post = line[match.end('lib'):]
+
+ self.file_out.write('%s%s pc %s %s%s' % (pre, frame, addr, sym, post))
+ self.file_out.flush()
+
+
+def main():
+ symbolizer = Symbolizer(sys.stdin, sys.stdout)
+ symbolizer.ProcessInput()
+
+
+if __name__ == '__main__':
+ main()
« no previous file with comments | « build/android/asan_symbolize.py ('k') | build/android/symbolize_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698