OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright 2013 The Chromium Authors. All rights reserved. | 3 # Copyright 2013 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """Symbolizes stack traces generated by Chromium for Android. | 7 """Symbolizes stack traces generated by Chromium for Android. |
8 | 8 |
9 Sample usage: | 9 Sample usage: |
10 adb logcat chromium:V | symbolize.py | 10 adb logcat chromium:V | symbolize.py |
11 """ | 11 """ |
12 | 12 |
13 import os | 13 import os |
14 import re | 14 import re |
15 import sys | 15 import sys |
16 | 16 |
17 from pylib import constants | 17 from pylib import constants |
18 | 18 |
19 # Uses symbol.py from third_party/android_platform, not python's. | 19 # Uses symbol.py from third_party/android_platform, not python's. |
20 sys.path.insert(0, | 20 sys.path.insert(0, |
21 os.path.join(constants.DIR_SOURCE_ROOT, | 21 os.path.join(constants.DIR_SOURCE_ROOT, |
22 'third_party/android_platform/development/scripts')) | 22 'third_party/android_platform/development/scripts')) |
23 import symbol | 23 import symbol |
24 | 24 |
25 # Sample output from base/debug/stack_trace_android.cc | 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 | 26 #00 0x693cd34f /path/to/some/libfoo.so+0x0007434f |
27 TRACE_LINE = re.compile('(?P<frame>\#[0-9]+) pc (?P<addr>[0-9a-f]{8,8}) ' | 27 TRACE_LINE = re.compile('(?P<frame>\#[0-9]+ 0x[0-9a-f]{8,8}) ' |
28 '(?P<lib>[^\r\n \t]+)') | 28 '(?P<lib>[^+]+)\+0x(?P<addr>[0-9a-f]{8,8})') |
29 | 29 |
30 class Symbolizer(object): | 30 class Symbolizer(object): |
31 def __init__(self, file_in, file_out): | 31 def __init__(self, file_in, file_out): |
32 self.file_in = file_in | 32 self.file_in = file_in |
33 self.file_out = file_out | 33 self.file_out = file_out |
34 | 34 |
35 def ProcessInput(self): | 35 def ProcessInput(self): |
36 for line in self.file_in: | 36 for line in self.file_in: |
37 match = re.search(TRACE_LINE, line) | 37 match = re.search(TRACE_LINE, line) |
38 if not match: | 38 if not match: |
(...skipping 19 matching lines...) Expand all Loading... |
58 # (e.g., adb logcat) when doing incremental development. Consider clearing | 58 # (e.g., adb logcat) when doing incremental development. Consider clearing |
59 # the cache when modification timestamp of libraries change. | 59 # the cache when modification timestamp of libraries change. |
60 sym = symbol.SymbolInformation(lib, addr, False)[0][0] | 60 sym = symbol.SymbolInformation(lib, addr, False)[0][0] |
61 | 61 |
62 if not sym: | 62 if not sym: |
63 self.file_out.write(line) | 63 self.file_out.write(line) |
64 self.file_out.flush() | 64 self.file_out.flush() |
65 continue | 65 continue |
66 | 66 |
67 pre = line[0:match.start('frame')] | 67 pre = line[0:match.start('frame')] |
68 post = line[match.end('lib'):] | 68 post = line[match.end('addr'):] |
69 | 69 |
70 self.file_out.write('%s%s pc %s %s%s' % (pre, frame, addr, sym, post)) | 70 self.file_out.write(pre) |
| 71 self.file_out.write(frame) |
| 72 self.file_out.write(' ') |
| 73 self.file_out.write(sym) |
| 74 self.file_out.write(post) |
71 self.file_out.flush() | 75 self.file_out.flush() |
72 | 76 |
73 | 77 |
74 def main(): | 78 def main(): |
75 symbolizer = Symbolizer(sys.stdin, sys.stdout) | 79 symbolizer = Symbolizer(sys.stdin, sys.stdout) |
76 symbolizer.ProcessInput() | 80 symbolizer.ProcessInput() |
77 | 81 |
78 | 82 |
79 if __name__ == '__main__': | 83 if __name__ == '__main__': |
80 main() | 84 main() |
OLD | NEW |