OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2012 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 from third_party import asan_symbolize | 7 from third_party import asan_symbolize |
8 | 8 |
9 import os | 9 import os |
10 import re | 10 import re |
11 import sys | 11 import sys |
12 | 12 |
13 def fix_filename(file_name): | 13 def fix_filename(file_name): |
14 for path_to_cut in sys.argv[1:]: | 14 for path_to_cut in sys.argv[1:]: |
15 file_name = re.sub(".*" + path_to_cut, "", file_name) | 15 file_name = re.sub(".*" + path_to_cut, "", file_name) |
16 file_name = re.sub(".*asan_[a-z_]*.cc:[0-9]*", "_asan_rtl_", file_name) | 16 file_name = re.sub(".*asan_[a-z_]*.cc:[0-9]*", "_asan_rtl_", file_name) |
17 file_name = re.sub(".*crtstuff.c:0", "???:0", file_name) | 17 file_name = re.sub(".*crtstuff.c:0", "???:0", file_name) |
18 return file_name | 18 return file_name |
19 | 19 |
20 | |
20 class LineBuffered(object): | 21 class LineBuffered(object): |
21 """Disable buffering on a file object.""" | 22 """Disable buffering on a file object.""" |
22 def __init__(self, stream): | 23 def __init__(self, stream): |
23 self.stream = stream | 24 self.stream = stream |
24 | 25 |
25 def write(self, data): | 26 def write(self, data): |
26 self.stream.write(data) | 27 self.stream.write(data) |
27 if '\n' in data: | 28 if '\n' in data: |
28 self.stream.flush() | 29 self.stream.flush() |
29 | 30 |
30 def __getattr__(self, attr): | 31 def __getattr__(self, attr): |
31 return getattr(self.stream, attr) | 32 return getattr(self.stream, attr) |
32 | 33 |
33 | 34 |
34 def disable_buffering(): | 35 def disable_buffering(): |
35 """Makes this process and child processes stdout unbuffered.""" | 36 """Makes this process and child processes stdout unbuffered.""" |
36 if not os.environ.get('PYTHONUNBUFFERED'): | 37 if not os.environ.get('PYTHONUNBUFFERED'): |
37 # Since sys.stdout is a C++ object, it's impossible to do | 38 # Since sys.stdout is a C++ object, it's impossible to do |
38 # sys.stdout.write = lambda... | 39 # sys.stdout.write = lambda... |
39 sys.stdout = LineBuffered(sys.stdout) | 40 sys.stdout = LineBuffered(sys.stdout) |
40 os.environ['PYTHONUNBUFFERED'] = 'x' | 41 os.environ['PYTHONUNBUFFERED'] = 'x' |
41 | 42 |
42 | 43 |
44 def set_symbolizer_path(): | |
45 """Set the path to the llvm-symbolize binary in the Chromium source tree.""" | |
46 if not os.environ.get('LLVM_SYMBOLIZER_PATH'): | |
47 script_dir = os.path.dirname(os.path.abspath(__file__)) | |
48 # Assuming this script resides in src/tools/valgrind/asan. | |
Alexander Potapenko
2014/09/19 13:08:06
Can you please assert this and/or check that symbo
| |
49 src_root = os.path.join(script_dir, "..", "..", "..") | |
50 symbolizer_path = os.path.join(src_root, 'third_party', | |
51 'llvm-build', 'Release+Asserts', 'bin', 'llvm-symbolizer') | |
52 os.environ['LLVM_SYMBOLIZER_PATH'] = os.path.abspath(symbolizer_path) | |
53 | |
54 | |
43 def main(): | 55 def main(): |
44 disable_buffering() | 56 disable_buffering() |
57 set_symbolizer_path() | |
45 asan_symbolize.demangle = True | 58 asan_symbolize.demangle = True |
46 loop = asan_symbolize.SymbolizationLoop(binary_name_filter=fix_filename) | 59 loop = asan_symbolize.SymbolizationLoop(binary_name_filter=fix_filename) |
47 loop.process_stdin() | 60 loop.process_stdin() |
48 | 61 |
49 if __name__ == '__main__': | 62 if __name__ == '__main__': |
50 main() | 63 main() |
OLD | NEW |