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

Side by Side Diff: chrome/tools/build/win/syzygy_instrument.py

Issue 12095105: Add a script to produce a syzygy-instrumented image of Chrome.dll (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Address nits. Created 7 years, 10 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 unified diff | Download patch
« no previous file with comments | « chrome/installer/mini_installer/chrome.release ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
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
4 # found in the LICENSE file.
5
6 """A utility script to help building Syzygy-instrumented Chrome binaries."""
7
8 import logging
9 import optparse
10 import os
11 import shutil
12 import subprocess
13 import sys
14
15
16 # The default instrument executable to use to instrument binaries.
17 _DEFAULT_INSTRUMENTER = os.path.abspath(os.path.join(
18 os.path.dirname(__file__), '../../../..',
19 'third_party/syzygy/binaries/exe/instrument.exe'))
20
21 _LOGGER = logging.getLogger()
22
23 def _Shell(*cmd, **kw):
24 """Shells out to "cmd". Returns a tuple of cmd's stdout, stderr."""
25 _LOGGER.info('Running command "%s".', cmd)
26 prog = subprocess.Popen(cmd, **kw)
27
28 stdout, stderr = prog.communicate()
29 if prog.returncode != 0:
30 raise RuntimeError('Command "%s" returned %d.' % (cmd, prog.returncode))
31
32 return stdout, stderr
33
34
35 def _InstrumentBinary(instrument_exe, mode, executable, symbol, dst_dir):
36 """Instruments the executable found in input_dir, and writes the resultant
37 instrumented executable and symbol files to dst_dir.
38 """
39 cmd = [instrument_exe,
40 '--overwrite',
41 '--mode=%s' % mode,
42 '--input-image=%s' % executable,
43 '--input-pdb=%s' % symbol,
44 '--output-image=%s' % os.path.abspath(
45 os.path.join(dst_dir, os.path.basename(executable))),
46 '--output-pdb=%s' % os.path.abspath(
47 os.path.join(dst_dir, os.path.basename(symbol))),]
48
49 return _Shell(*cmd)
50
51 def _CopyAgentDLL(agent_dll, destination_dir):
52 """Copy the agent DLL to the destination directory."""
53 dirname, agent_name = os.path.split(agent_dll);
54 agent_dst_name = os.path.join(destination_dir, agent_name);
55 shutil.copyfile(agent_dll, agent_dst_name)
56
57 def main(options):
58 logging.basicConfig(level=logging.INFO)
59
60 # Make sure the destination directory exists.
61 if not os.path.isdir(options.destination_dir):
62 _LOGGER.info('Creating destination directory "%s".',
63 options.destination_dir)
64 os.makedirs(options.destination_dir)
65
66 # Instruments the binaries into the destination directory.
67 _InstrumentBinary(options.instrumenter,
68 options.mode,
69 options.input_executable,
70 options.input_symbol,
71 options.destination_dir)
72
73 # Copy the agent DLL to the destination directory.
74 _CopyAgentDLL(options.agent_dll, options.destination_dir);
75
76
77 def _ParseOptions():
78 option_parser = optparse.OptionParser()
79 option_parser.add_option('--input_executable',
80 help='The path to the input executable.')
81 option_parser.add_option('--input_symbol',
82 help='The path to the input symbol file.')
83 option_parser.add_option('--mode',
84 help='Specifies which instrumentation mode is to be used.')
85 option_parser.add_option('--agent_dll',
86 help='The agent DLL used by this instrumentation.')
87 option_parser.add_option('--instrumenter', default=_DEFAULT_INSTRUMENTER,
88 help='Instrumenter executable to use, defaults to "%s"'
89 % _DEFAULT_INSTRUMENTER)
90 option_parser.add_option('-d', '--destination_dir',
91 help='Destination directory for instrumented files, defaults to '
92 'the subdirectory "instrumented" in the output_dir.')
93 options, args = option_parser.parse_args()
94
95 if not options.mode:
96 option_parser.error('You must provide an instrumentation mode.')
97 if not options.agent_dll:
98 option_parser.error('You must provide an agent DLL.')
99 if not options.input_executable:
100 option_parser.error('You must provide an input executable.')
101 if not options.input_symbol:
102 option_parser.error('You must provide an input symbol file.')
103
104 if not options.destination_dir:
105 options.destination_dir = os.path.join(options.output_dir, 'instrumented')
106
107 return options
108
109
110 if '__main__' == __name__:
111 sys.exit(main(_ParseOptions()))
OLDNEW
« no previous file with comments | « chrome/installer/mini_installer/chrome.release ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698