Chromium Code Reviews| 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 def chrome_dsym_hints(binary): | |
| 60 path_parts = binary.split(os.path.sep) | |
| 61 app_positions = [] | |
| 62 framework_positions = [] | |
| 63 for index, part in enumerate(path_parts): | |
| 64 if part.endswith('.app'): | |
| 65 app_positions.append(index) | |
| 66 elif part.endswith('.framework'): | |
| 67 framework_positions.append(index) | |
| 68 assert len(framework_positions) < 2, \ | |
|
earthdok
2014/12/16 17:43:43
<=1 for consistency
Alexander Potapenko
2014/12/16 17:52:07
Done.
| |
| 69 "The path contains more than one framework: %s" % binary | |
| 70 bundles = app_positions + framework_positions | |
|
earthdok
2014/12/16 17:43:43
I think this should be named bundle_positions.
Alexander Potapenko
2014/12/16 17:52:07
Done.
| |
| 71 bundles.sort() | |
| 72 assert len(bundles) <= 2, \ | |
| 73 "The path contains more than two nested bundles: %s" % binary | |
| 74 if len(bundles) == 0: | |
| 75 # Case 1: this is a standalone executable or dylib. | |
| 76 return [] | |
| 77 assert (len(bundles) == 1 or | |
|
earthdok
2014/12/16 17:43:43
Please add those assertions to the comment above.
Alexander Potapenko
2014/12/16 17:52:07
Done.
| |
| 78 len(app_positions) == 2 or | |
| 79 app_positions[0] < framework_positions[0]), \ | |
| 80 "The path contains an app bundle inside a framework: %s" % binary | |
| 81 # Cases 2 and 3. The outermost bundle (which is the only bundle in the case 2) | |
| 82 # is located in the product dir. | |
| 83 outermost_bundle = bundles[0] | |
| 84 product_dir = path_parts[:outermost_bundle] | |
| 85 # In case 2 this is the same as |outermost_bundle|. | |
| 86 innermost_bundle = bundles[-1] | |
| 87 dsym_path = product_dir + [path_parts[innermost_bundle]] | |
| 88 result = '%s.dSYM' % os.path.sep.join(dsym_path) | |
| 89 return [result] | |
| 90 | |
| 91 | |
| 48 def main(): | 92 def main(): |
| 49 disable_buffering() | 93 disable_buffering() |
| 50 set_symbolizer_path() | 94 set_symbolizer_path() |
| 51 asan_symbolize.demangle = True | 95 asan_symbolize.demangle = True |
| 52 asan_symbolize.fix_filename_patterns = sys.argv[1:] | 96 asan_symbolize.fix_filename_patterns = sys.argv[1:] |
| 53 asan_symbolize.logfile = sys.stdin | 97 asan_symbolize.logfile = sys.stdin |
| 54 loop = asan_symbolize.SymbolizationLoop() | 98 loop = asan_symbolize.SymbolizationLoop(dsym_hint_producer=chrome_dsym_hints) |
| 55 loop.process_logfile() | 99 loop.process_logfile() |
| 56 | 100 |
| 57 if __name__ == '__main__': | 101 if __name__ == '__main__': |
| 58 main() | 102 main() |
| OLD | NEW |