| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import json | 6 import json |
| 7 import logging | 7 import logging |
| 8 import os | 8 import os |
| 9 import re | 9 import re |
| 10 import shutil | 10 import shutil |
| 11 import subprocess | 11 import subprocess |
| 12 import sys | 12 import sys |
| 13 import tempfile | 13 import tempfile |
| 14 | 14 |
| 15 from parse_proc_maps import parse_proc_maps | 15 from proc_maps import ProcMaps |
| 16 from util import executable_condition | |
| 17 | 16 |
| 18 | 17 |
| 19 def _dump_command_result(command, output_dir_path, basename, suffix, log): | 18 def _dump_command_result(command, output_dir_path, basename, suffix, log): |
| 20 handle_out, filename_out = tempfile.mkstemp( | 19 handle_out, filename_out = tempfile.mkstemp( |
| 21 suffix=suffix, prefix=basename + '.', dir=output_dir_path) | 20 suffix=suffix, prefix=basename + '.', dir=output_dir_path) |
| 22 handle_err, filename_err = tempfile.mkstemp( | 21 handle_err, filename_err = tempfile.mkstemp( |
| 23 suffix=suffix + '.err', prefix=basename + '.', dir=output_dir_path) | 22 suffix=suffix + '.err', prefix=basename + '.', dir=output_dir_path) |
| 24 error = False | 23 error = False |
| 25 try: | 24 try: |
| 26 subprocess.check_call( | 25 subprocess.check_call( |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 else: | 80 else: |
| 82 log.info('Creating a new directory at "%s".' % output_dir_path) | 81 log.info('Creating a new directory at "%s".' % output_dir_path) |
| 83 os.mkdir(output_dir_path) | 82 os.mkdir(output_dir_path) |
| 84 | 83 |
| 85 if output_dir_path_exists: | 84 if output_dir_path_exists: |
| 86 return 1 | 85 return 1 |
| 87 | 86 |
| 88 shutil.copyfile(maps_path, os.path.join(output_dir_path, 'maps')) | 87 shutil.copyfile(maps_path, os.path.join(output_dir_path, 'maps')) |
| 89 | 88 |
| 90 with open(maps_path, mode='r') as f: | 89 with open(maps_path, mode='r') as f: |
| 91 maps = parse_proc_maps(f) | 90 maps = ProcMaps.load(f) |
| 92 | 91 |
| 93 log.debug('Listing up symbols.') | 92 log.debug('Listing up symbols.') |
| 94 files = {} | 93 files = {} |
| 95 for entry in maps.iter(executable_condition): | 94 for entry in maps.iter(ProcMaps.executable): |
| 96 log.debug(' %016x-%016x +%06x %s' % ( | 95 log.debug(' %016x-%016x +%06x %s' % ( |
| 97 entry.begin, entry.end, entry.offset, entry.name)) | 96 entry.begin, entry.end, entry.offset, entry.name)) |
| 98 nm_filename = _dump_command_result( | 97 nm_filename = _dump_command_result( |
| 99 'nm -n --format bsd %s | c++filt' % entry.name, | 98 'nm -n --format bsd %s | c++filt' % entry.name, |
| 100 output_dir_path, os.path.basename(entry.name), '.nm', log) | 99 output_dir_path, os.path.basename(entry.name), '.nm', log) |
| 101 if not nm_filename: | 100 if not nm_filename: |
| 102 continue | 101 continue |
| 103 readelf_e_filename = _dump_command_result( | 102 readelf_e_filename = _dump_command_result( |
| 104 'readelf -e %s' % entry.name, | 103 'readelf -eW %s' % entry.name, |
| 105 output_dir_path, os.path.basename(entry.name), '.readelf-e', log) | 104 output_dir_path, os.path.basename(entry.name), '.readelf-e', log) |
| 106 if not readelf_e_filename: | 105 if not readelf_e_filename: |
| 107 continue | 106 continue |
| 108 | 107 |
| 109 files[entry.name] = {} | 108 files[entry.name] = {} |
| 110 files[entry.name]['nm'] = { | 109 files[entry.name]['nm'] = { |
| 111 'file': os.path.basename(nm_filename), | 110 'file': os.path.basename(nm_filename), |
| 112 'format': 'bsd', | 111 'format': 'bsd', |
| 113 'mangled': False} | 112 'mangled': False} |
| 114 files[entry.name]['readelf-e'] = { | 113 files[entry.name]['readelf-e'] = { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 134 elif len(sys.argv) == 2: | 133 elif len(sys.argv) == 2: |
| 135 sys.exit(prepare_symbol_info(sys.argv[1], loglevel=logging.INFO)) | 134 sys.exit(prepare_symbol_info(sys.argv[1], loglevel=logging.INFO)) |
| 136 else: | 135 else: |
| 137 sys.exit(prepare_symbol_info(sys.argv[1], sys.argv[2], | 136 sys.exit(prepare_symbol_info(sys.argv[1], sys.argv[2], |
| 138 loglevel=logging.INFO)) | 137 loglevel=logging.INFO)) |
| 139 return 0 | 138 return 0 |
| 140 | 139 |
| 141 | 140 |
| 142 if __name__ == '__main__': | 141 if __name__ == '__main__': |
| 143 sys.exit(main()) | 142 sys.exit(main()) |
| OLD | NEW |