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 sys | 10 import sys |
(...skipping 27 matching lines...) Expand all Loading... |
38 script_dir = os.path.dirname(os.path.abspath(__file__)) | 38 script_dir = os.path.dirname(os.path.abspath(__file__)) |
39 # Assume this script resides three levels below src/ (i.e. | 39 # Assume this script resides three levels below src/ (i.e. |
40 # src/tools/valgrind/asan/). | 40 # src/tools/valgrind/asan/). |
41 src_root = os.path.join(script_dir, "..", "..", "..") | 41 src_root = os.path.join(script_dir, "..", "..", "..") |
42 symbolizer_path = os.path.join(src_root, 'third_party', | 42 symbolizer_path = os.path.join(src_root, 'third_party', |
43 'llvm-build', 'Release+Asserts', 'bin', 'llvm-symbolizer') | 43 'llvm-build', 'Release+Asserts', 'bin', 'llvm-symbolizer') |
44 assert(os.path.isfile(symbolizer_path)) | 44 assert(os.path.isfile(symbolizer_path)) |
45 os.environ['LLVM_SYMBOLIZER_PATH'] = os.path.abspath(symbolizer_path) | 45 os.environ['LLVM_SYMBOLIZER_PATH'] = os.path.abspath(symbolizer_path) |
46 | 46 |
47 | 47 |
| 48 # Construct a path to the .dSYM bundle for the given binary. |
| 49 # There are three possible cases for binary location in Chromium: |
| 50 # 1. The binary is a standalone executable or dynamic library in the product |
| 51 # dir, the debug info is in "binary.dSYM" in the product dir. |
| 52 # 2. The binary is a standalone framework or .app bundle, the debug info is in |
| 53 # "Framework.framework.dSYM" or "App.app.dSYM" in the product dir. |
| 54 # 3. The binary is a framework or an .app bundle within another .app bundle |
| 55 # (e.g. Outer.app/Contents/Versions/1.2.3.4/Inner.app), and the debug info |
| 56 # is in Inner.app.dSYM in the product dir. |
| 57 # The first case is handled by llvm-symbolizer, so we only need to construct |
| 58 # .dSYM paths for .app bundles and frameworks. |
| 59 # We're assuming that there're no more than two nested bundles in the binary |
| 60 # path. Only one of these bundles may be a framework and frameworks cannot |
| 61 # contain other bundles. |
| 62 def chrome_dsym_hints(binary): |
| 63 path_parts = binary.split(os.path.sep) |
| 64 app_positions = [] |
| 65 framework_positions = [] |
| 66 for index, part in enumerate(path_parts): |
| 67 if part.endswith('.app'): |
| 68 app_positions.append(index) |
| 69 elif part.endswith('.framework'): |
| 70 framework_positions.append(index) |
| 71 assert len(framework_positions) <= 1, \ |
| 72 "The path contains more than one framework: %s" % binary |
| 73 bundle_positions = app_positions + framework_positions |
| 74 bundle_positions.sort() |
| 75 assert len(bundle_positions) <= 2, \ |
| 76 "The path contains more than two nested bundles: %s" % binary |
| 77 if len(bundle_positions) == 0: |
| 78 # Case 1: this is a standalone executable or dylib. |
| 79 return [] |
| 80 assert (len(bundle_positions) == 1 or |
| 81 len(app_positions) == 2 or |
| 82 app_positions[0] < framework_positions[0]), \ |
| 83 "The path contains an app bundle inside a framework: %s" % binary |
| 84 # Cases 2 and 3. The outermost bundle (which is the only bundle in the case 2) |
| 85 # is located in the product dir. |
| 86 outermost_bundle = bundle_positions[0] |
| 87 product_dir = path_parts[:outermost_bundle] |
| 88 # In case 2 this is the same as |outermost_bundle|. |
| 89 innermost_bundle = bundle_positions[-1] |
| 90 dsym_path = product_dir + [path_parts[innermost_bundle]] |
| 91 result = '%s.dSYM' % os.path.sep.join(dsym_path) |
| 92 return [result] |
| 93 |
| 94 |
48 def main(): | 95 def main(): |
49 disable_buffering() | 96 disable_buffering() |
50 set_symbolizer_path() | 97 set_symbolizer_path() |
51 asan_symbolize.demangle = True | 98 asan_symbolize.demangle = True |
52 asan_symbolize.fix_filename_patterns = sys.argv[1:] | 99 asan_symbolize.fix_filename_patterns = sys.argv[1:] |
53 asan_symbolize.logfile = sys.stdin | 100 asan_symbolize.logfile = sys.stdin |
54 loop = asan_symbolize.SymbolizationLoop() | 101 loop = asan_symbolize.SymbolizationLoop(dsym_hint_producer=chrome_dsym_hints) |
55 loop.process_logfile() | 102 loop.process_logfile() |
56 | 103 |
57 if __name__ == '__main__': | 104 if __name__ == '__main__': |
58 main() | 105 main() |
OLD | NEW |