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 | 7 |
8 import collections | 8 import collections |
9 import optparse | 9 import optparse |
10 import os | 10 import os |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 return asan_libs | 46 return asan_libs |
47 | 47 |
48 | 48 |
49 def _TranslateLibPath(library, asan_libs): | 49 def _TranslateLibPath(library, asan_libs): |
50 for asan_lib in asan_libs: | 50 for asan_lib in asan_libs: |
51 if os.path.basename(library) == os.path.basename(asan_lib): | 51 if os.path.basename(library) == os.path.basename(asan_lib): |
52 return '/' + asan_lib | 52 return '/' + asan_lib |
53 return symbol.TranslateLibPath(library) | 53 return symbol.TranslateLibPath(library) |
54 | 54 |
55 | 55 |
56 def _Symbolize(input): | 56 def _Symbolize(asan_input): |
57 asan_libs = _FindASanLibraries() | 57 asan_libs = _FindASanLibraries() |
58 libraries = collections.defaultdict(list) | 58 libraries = collections.defaultdict(list) |
59 asan_lines = [] | 59 asan_lines = [] |
60 for asan_log_line in [a.rstrip() for a in input]: | 60 for asan_log_line in [a.rstrip() for a in asan_input]: |
61 m = _ParseAsanLogLine(asan_log_line) | 61 m = _ParseAsanLogLine(asan_log_line) |
62 if m: | 62 if m: |
63 libraries[m['library']].append(m) | 63 libraries[m['library']].append(m) |
64 asan_lines.append({'raw_log': asan_log_line, 'parsed': m}) | 64 asan_lines.append({'raw_log': asan_log_line, 'parsed': m}) |
65 | 65 |
66 all_symbols = collections.defaultdict(dict) | 66 all_symbols = collections.defaultdict(dict) |
67 original_symbols_dir = symbol.SYMBOLS_DIR | |
68 for library, items in libraries.iteritems(): | 67 for library, items in libraries.iteritems(): |
69 libname = _TranslateLibPath(library, asan_libs) | 68 libname = _TranslateLibPath(library, asan_libs) |
70 lib_relative_addrs = set([i['rel_address'] for i in items]) | 69 lib_relative_addrs = set([i['rel_address'] for i in items]) |
71 info_dict = symbol.SymbolInformationForSet(libname, | 70 info_dict = symbol.SymbolInformationForSet(libname, |
72 lib_relative_addrs, | 71 lib_relative_addrs, |
73 True) | 72 True) |
74 if info_dict: | 73 if info_dict: |
75 all_symbols[library]['symbols'] = info_dict | 74 all_symbols[library]['symbols'] = info_dict |
76 | 75 |
77 for asan_log_line in asan_lines: | 76 for asan_log_line in asan_lines: |
78 m = asan_log_line['parsed'] | 77 m = asan_log_line['parsed'] |
79 if not m: | 78 if not m: |
80 print asan_log_line['raw_log'] | 79 print asan_log_line['raw_log'] |
81 continue | 80 continue |
82 if (m['library'] in all_symbols and | 81 if (m['library'] in all_symbols and |
83 m['rel_address'] in all_symbols[m['library']]['symbols']): | 82 m['rel_address'] in all_symbols[m['library']]['symbols']): |
84 s = all_symbols[m['library']]['symbols'][m['rel_address']][0] | 83 s = all_symbols[m['library']]['symbols'][m['rel_address']][0] |
85 print '%s%s %s %s' %(m['prefix'], m['pos'], s[0], s[1]) | 84 print '%s%s %s %s' % (m['prefix'], m['pos'], s[0], s[1]) |
86 else: | 85 else: |
87 print asan_log_line['raw_log'] | 86 print asan_log_line['raw_log'] |
88 | 87 |
89 | 88 |
90 def main(): | 89 def main(): |
91 parser = optparse.OptionParser() | 90 parser = optparse.OptionParser() |
92 parser.add_option('-l', '--logcat', | 91 parser.add_option('-l', '--logcat', |
93 help='File containing adb logcat output with ASan stacks. ' | 92 help='File containing adb logcat output with ASan stacks. ' |
94 'Use stdin if not specified.') | 93 'Use stdin if not specified.') |
95 options, args = parser.parse_args() | 94 options, _ = parser.parse_args() |
96 if options.logcat: | 95 if options.logcat: |
97 input = file(options.logcat, 'r') | 96 asan_input = file(options.logcat, 'r') |
98 else: | 97 else: |
99 input = sys.stdin | 98 asan_input = sys.stdin |
100 _Symbolize(input.readlines()) | 99 _Symbolize(asan_input.readlines()) |
101 | 100 |
102 | 101 |
103 if __name__ == "__main__": | 102 if __name__ == "__main__": |
104 sys.exit(main()) | 103 sys.exit(main()) |
OLD | NEW |