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
5 # found in the LICENSE file.
7 from third_party import asan_symbolize
12 class LineBuffered(object):
13 """Disable buffering on a file object."""
14 def __init__(self, stream):
17 def write(self, data):
18 self.stream.write(data)
22 def __getattr__(self, attr):
23 return getattr(self.stream, attr)
26 def disable_buffering():
27 """Makes this process and child processes stdout unbuffered."""
28 if not os.environ.get('PYTHONUNBUFFERED'):
29 # Since sys.stdout is a C++ object, it's impossible to do
30 # sys.stdout.write = lambda...
31 sys.stdout = LineBuffered(sys.stdout)
32 os.environ['PYTHONUNBUFFERED'] = 'x'
35 def set_symbolizer_path():
36 """Set the path to the llvm-symbolize binary in the Chromium source tree."""
37 if not os.environ.get('LLVM_SYMBOLIZER_PATH'):
38 script_dir = os.path.dirname(os.path.abspath(__file__))
39 # Assume this script resides three levels below src/ (i.e.
40 # src/tools/valgrind/asan/).
41 src_root = os.path.join(script_dir, "..", "..", "..")
42 symbolizer_path = os.path.join(src_root, 'third_party',
43 'llvm-build', 'Release+Asserts', 'bin', 'llvm-symbolizer')
44 assert(os.path.isfile(symbolizer_path))
45 os.environ['LLVM_SYMBOLIZER_PATH'] = os.path.abspath(symbolizer_path)
51 asan_symbolize.demangle = True
52 asan_symbolize.fix_filename_patterns = sys.argv[1:]
53 asan_symbolize.logfile = sys.stdin
54 loop = asan_symbolize.SymbolizationLoop()
55 loop.process_logfile()
57 if __name__ == '__main__':