1 : // Copyright 2012 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 : //
15 : // Defines the InstrumentApp class, which implements the command-line
16 : // "instrument" tool.
17 :
18 : #ifndef SYZYGY_INSTRUMENT_INSTRUMENT_APP_H_
19 : #define SYZYGY_INSTRUMENT_INSTRUMENT_APP_H_
20 :
21 : #include "base/command_line.h"
22 : #include "base/string_piece.h"
23 : #include "base/time.h"
24 : #include "base/files/file_path.h"
25 : #include "syzygy/common/application.h"
26 : #include "syzygy/pe/pe_relinker.h"
27 :
28 : namespace instrument {
29 :
30 : // Implements the "instrument" command-line application.
31 : //
32 : // Refer to kUsageFormatStr (referenced from InstrumentApp::Usage()) for
33 : // usage information.
34 : class InstrumentApp : public common::AppImplBase {
35 : public:
36 :
37 : // A list of known clients libraries.
38 : static const char kAgentDllAsan[];
39 : static const char kAgentDllBasicBlockEntry[];
40 : static const char kAgentDllCoverage[];
41 : static const char kAgentDllProfile[];
42 : static const char kAgentDllRpc[];
43 :
44 : // The mode of the instrumenter.
45 : enum Mode {
46 : kInstrumentInvalidMode,
47 : kInstrumentAsanMode,
48 : kInstrumentBasicBlockEntryMode,
49 : kInstrumentCallTraceMode,
50 : kInstrumentCoverageMode,
51 : kInstrumentProfileMode,
52 : };
53 :
54 : InstrumentApp()
55 : : common::AppImplBase("Instrumenter"),
56 : mode_(kInstrumentInvalidMode),
57 : allow_overwrite_(false),
58 : new_decomposer_(false),
59 : no_augment_pdb_(false),
60 : no_parse_debug_info_(false),
61 : no_strip_strings_(false),
62 : debug_friendly_(false),
63 : instrument_unsafe_references_(true),
64 : module_entry_only_(false),
65 : use_liveness_analysis_(false),
66 : remove_redundant_checks_(false),
67 E : inline_fast_path_(false) {
68 E : }
69 :
70 : // @name Implementation of the AppImplBase interface.
71 : // @{
72 : bool ParseCommandLine(const CommandLine* command_line);
73 : int Run();
74 : // @}
75 :
76 : protected:
77 : // @name Utility members.
78 : // @{
79 : bool Usage(const CommandLine* command_line,
80 : const base::StringPiece& message) const;
81 : // @}
82 :
83 : // Used to parse old-style deprecated command-lines.
84 : // TODO(chrisha): Remove this once build scripts and profiling tools have
85 : // been updated.
86 : void ParseDeprecatedMode(const CommandLine* command_line);
87 :
88 : // The mode of the instrumenter. This is valid after a successful call to
89 : // ParseCommandLine.
90 : Mode mode_;
91 :
92 : // @name Command-line parameters.
93 : // @{
94 : base::FilePath input_dll_path_;
95 : base::FilePath input_pdb_path_;
96 : base::FilePath output_dll_path_;
97 : base::FilePath output_pdb_path_;
98 : base::FilePath filter_path_;
99 : std::string agent_dll_;
100 : bool allow_overwrite_;
101 : bool new_decomposer_;
102 : bool no_augment_pdb_;
103 : bool no_parse_debug_info_;
104 : bool no_strip_strings_;
105 : bool debug_friendly_;
106 : bool thunk_imports_;
107 : bool instrument_unsafe_references_;
108 : bool module_entry_only_;
109 : bool use_liveness_analysis_;
110 : bool remove_redundant_checks_;
111 : bool inline_fast_path_;
112 : // @}
113 :
114 : // @name Internal machinery, replaceable for testing purposes.
115 : // @{
116 : virtual pe::PERelinker& GetRelinker();
117 : scoped_ptr<pe::PERelinker> relinker_;
118 : // @}
119 : };
120 :
121 : } // namespace instrument
122 :
123 : #endif // SYZYGY_INSTRUMENT_INSTRUMENT_APP_H_
|