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