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