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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « build/android/asan_symbolize.py ('k') | build/android/symbolize_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 #
3 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6
7 """Symbolizes stack traces generated by Chromium for Android.
8
9 Sample usage:
10 adb logcat chromium:V | symbolize.py
11 """
12
13 import os
14 import re
15 import sys
16
17 from pylib import constants
18
19 # Uses symbol.py from third_party/android_platform, not python's.
20 sys.path.insert(0,
21 os.path.join(constants.DIR_SOURCE_ROOT,
22 'third_party/android_platform/development/scripts'))
23 import symbol
24
25 # Sample output from base/debug/stack_trace_android.cc
26 #00 pc 000634c1 /data/app-lib/org.chromium.native_test-1/libbase_unittests.so
27 TRACE_LINE = re.compile('(?P<frame>\#[0-9]+) pc (?P<addr>[0-9a-f]{8,8}) '
28 '(?P<lib>[^\r\n \t]+)')
29
30 class Symbolizer(object):
31 def __init__(self, file_in, file_out):
32 self.file_in = file_in
33 self.file_out = file_out
34
35 def ProcessInput(self):
36 for line in self.file_in:
37 match = re.search(TRACE_LINE, line)
38 if not match:
39 self.file_out.write(line)
40 self.file_out.flush()
41 continue
42
43 frame = match.group('frame')
44 lib = match.group('lib')
45 addr = match.group('addr')
46
47 # TODO(scherkus): Doing a single lookup per line is pretty slow,
48 # especially with larger libraries. Consider caching strategies such as:
49 # 1) Have Python load the libraries and do symbol lookups instead of
50 # calling out to addr2line each time.
51 # 2) Have Python keep multiple addr2line instances open as subprocesses,
52 # piping addresses and reading back symbols as we find them
53 # 3) Read ahead the entire stack trace until we find no more, then batch
54 # the symbol lookups.
55 #
56 # TODO(scherkus): These results are memoized, which could result in
57 # incorrect lookups when running this script on long-lived instances
58 # (e.g., adb logcat) when doing incremental development. Consider clearing
59 # the cache when modification timestamp of libraries change.
60 sym = symbol.SymbolInformation(lib, addr, False)[0][0]
61
62 if not sym:
63 self.file_out.write(line)
64 self.file_out.flush()
65 continue
66
67 pre = line[0:match.start('frame')]
68 post = line[match.end('lib'):]
69
70 self.file_out.write('%s%s pc %s %s%s' % (pre, frame, addr, sym, post))
71 self.file_out.flush()
72
73
74 def main():
75 symbolizer = Symbolizer(sys.stdin, sys.stdout)
76 symbolizer.ProcessInput()
77
78
79 if __name__ == '__main__':
80 main()
OLDNEW
« 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