Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1604)

Unified Diff: tools/find_runtime_symbols/prepare_symbol_info.py

Issue 10826008: Load static symbol information lazily with some clean-ups. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/find_runtime_symbols/prepare_symbol_info.py
diff --git a/tools/find_runtime_symbols/prepare_symbol_info.py b/tools/find_runtime_symbols/prepare_symbol_info.py
index 57fcfbc3a83d046641379504c93727c61113b911..85497ce9152e4de24159134756be4b252b5f84ac 100755
--- a/tools/find_runtime_symbols/prepare_symbol_info.py
+++ b/tools/find_runtime_symbols/prepare_symbol_info.py
@@ -16,6 +16,25 @@ from parse_proc_maps import parse_proc_maps
from util import executable_condition
+def _dump_command_result(command, output_dir_path, basename, suffix):
+ with tempfile.NamedTemporaryFile(
+ prefix=basename + '.', suffix=suffix, delete=False, mode='w',
+ dir=output_dir_path) as f:
+ filename = os.path.realpath(f.name)
+ try:
M-A Ruel 2012/07/27 13:38:14 You should use tempfile.mkstemp() in that case; ha
Dai Mikurube (NOT FULLTIME) 2012/07/30 04:18:38 Done.
+ subprocess.check_call('%s > %s' % (command, filename), shell=True)
+ except:
+ os.remove(filename)
+
+ if os.path.exists(filename) and os.path.getsize(filename) == 0:
+ os.remove(filename)
+ return None
+ if not os.path.exists(filename):
+ return None
+
+ return filename
+
+
def prepare_symbol_info(maps_path, output_dir_path=None, loglevel=logging.WARN):
log = logging.getLogger('prepare_symbol_info')
log.setLevel(loglevel)
@@ -58,42 +77,31 @@ def prepare_symbol_info(maps_path, output_dir_path=None, loglevel=logging.WARN):
maps = parse_proc_maps(f)
log.debug('Listing up symbols.')
- nm_files = {}
+ files = {}
for entry in maps.iter(executable_condition):
log.debug(' %016x-%016x +%06x %s' % (
entry.begin, entry.end, entry.offset, entry.name))
- with tempfile.NamedTemporaryFile(
- prefix=os.path.basename(entry.name) + '.',
- suffix='.nm', delete=False, mode='w', dir=output_dir_path) as f:
- nm_filename = os.path.realpath(f.name)
- nm_succeeded = False
- cppfilt_succeeded = False
- p_nm = subprocess.Popen(
- 'nm -n --format bsd %s' % entry.name, shell=True,
- stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- p_cppfilt = subprocess.Popen(
- 'c++filt', shell=True,
- stdin=p_nm.stdout, stdout=f, stderr=subprocess.PIPE)
-
- if p_nm.wait() == 0:
- nm_succeeded = True
- for line in p_nm.stderr:
- log.debug(line.rstrip())
- if p_cppfilt.wait() == 0:
- cppfilt_succeeded = True
- for line in p_cppfilt.stderr:
- log.debug(line.rstrip())
-
- if nm_succeeded and cppfilt_succeeded:
- nm_files[entry.name] = {
+ nm_filename = _dump_command_result(
+ 'nm -n --format bsd %s | c++filt' % entry.name,
M-A Ruel 2012/07/27 13:38:14 Please do not use the shell if possible. You can c
Dai Mikurube (NOT FULLTIME) 2012/07/30 04:18:38 I avoided self-made pipes to avoid subprocess.PIPE
+ output_dir_path, os.path.basename(entry.name), '.nm')
+ if not nm_filename:
+ continue
+ readelf_e_filename = _dump_command_result(
+ 'readelf -e %s' % entry.name,
+ output_dir_path, os.path.basename(entry.name), '.readelf-e')
+ if not readelf_e_filename:
+ continue
+
+ files[entry.name] = {}
+ files[entry.name]['nm'] = {
'file': os.path.basename(nm_filename),
'format': 'bsd',
'mangled': False}
- else:
- os.remove(nm_filename)
+ files[entry.name]['readelf-e'] = {
+ 'file': os.path.basename(readelf_e_filename)}
- with open(os.path.join(output_dir_path, 'nm.json'), 'w') as f:
- json.dump(nm_files, f, indent=2, sort_keys=True)
+ with open(os.path.join(output_dir_path, 'files.json'), 'w') as f:
+ json.dump(files, f, indent=2, sort_keys=True)
log.info('Collected symbol information at "%s".' % output_dir_path)
return 0
« no previous file with comments | « tools/find_runtime_symbols/find_runtime_symbols.py ('k') | tools/find_runtime_symbols/procedure_boundaries.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698