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/file_path.h"
23 : #include "base/string_piece.h"
24 : #include "base/time.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 kCallTraceClientDllBasicBlockEntry[];
39 : static const char kCallTraceClientDllCoverage[];
40 : static const char kCallTraceClientDllProfile[];
41 : static const char kCallTraceClientDllRpc[];
42 :
43 : // The mode of the instrumenter.
44 : enum Mode {
45 : kInstrumentInvalidMode,
46 : kInstrumentAsanMode,
47 : kInstrumentBasicBlockEntryMode,
48 : kInstrumentCallTraceMode,
49 : kInstrumentCoverageMode,
50 : kInstrumentProfileMode,
51 : };
52 :
53 : InstrumentApp()
54 : : common::AppImplBase("Instrumenter"),
55 : mode_(kInstrumentInvalidMode),
56 : allow_overwrite_(false),
57 : new_decomposer_(false),
58 : no_augment_pdb_(false),
59 : no_parse_debug_info_(false),
60 : no_strip_strings_(false),
61 : debug_friendly_(false),
62 : instrument_unsafe_references_(true),
63 E : module_entry_only_(false) {
64 E : }
65 :
66 : // @name Implementation of the AppImplBase interface.
67 : // @{
68 : bool ParseCommandLine(const CommandLine* command_line);
69 : int Run();
70 : // @}
71 :
72 : protected:
73 : // @name Utility members.
74 : // @{
75 : bool Usage(const CommandLine* command_line,
76 : const base::StringPiece& message) const;
77 : // @}
78 :
79 : // Used to parse old-style deprecated command-lines.
80 : // TODO(chrisha): Remove this once build scripts and profiling tools have
81 : // been updated.
82 : void ParseDeprecatedMode(const CommandLine* command_line);
83 :
84 : // The mode of the instrumenter. This is valid after a successful call to
85 : // ParseCommandLine.
86 : Mode mode_;
87 :
88 : // @name Command-line parameters.
89 : // @{
90 : FilePath input_dll_path_;
91 : FilePath input_pdb_path_;
92 : FilePath output_dll_path_;
93 : FilePath output_pdb_path_;
94 : FilePath filter_path_;
95 : std::string client_dll_;
96 : bool allow_overwrite_;
97 : bool new_decomposer_;
98 : bool no_augment_pdb_;
99 : bool no_parse_debug_info_;
100 : bool no_strip_strings_;
101 : bool debug_friendly_;
102 : bool thunk_imports_;
103 : bool instrument_unsafe_references_;
104 : bool module_entry_only_;
105 : // @}
106 :
107 : // @name Internal machinery, replaceable for testing purposes.
108 : // @{
109 : virtual pe::PERelinker& GetRelinker();
110 : scoped_ptr<pe::PERelinker> relinker_;
111 : // @}
112 : };
113 :
114 : } // namespace instrument
115 :
116 : #endif // SYZYGY_INSTRUMENT_INSTRUMENT_APP_H_
|