1 : // Copyright 2013 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 : // Specialization of the instrumenter interface for the instrumenters who use an
16 : // agent. This performs all the common bits of this kind of instrumenters:
17 : // - Parse the shared command-line parameters.
18 : // - Initialization the relinker.
19 : // - Default implementation of Instrument.
20 : #ifndef SYZYGY_INSTRUMENT_INSTRUMENTERS_INSTRUMENTER_WITH_AGENT_H_
21 : #define SYZYGY_INSTRUMENT_INSTRUMENTERS_INSTRUMENTER_WITH_AGENT_H_
22 :
23 : #include <string>
24 :
25 : #include "base/command_line.h"
26 : #include "syzygy/instrument/instrumenter.h"
27 : #include "syzygy/pe/pe_relinker.h"
28 :
29 : namespace instrument {
30 : namespace instrumenters {
31 :
32 : class InstrumenterWithAgent : public InstrumenterInterface {
33 : public:
34 : InstrumenterWithAgent()
35 : : allow_overwrite_(false),
36 : debug_friendly_(false),
37 : new_decomposer_(false),
38 : no_augment_pdb_(false),
39 : no_parse_debug_info_(false),
40 E : no_strip_strings_(false) {
41 E : }
42 :
43 E : ~InstrumenterWithAgent() { }
44 :
45 : // @name InstrumenterInterface implementation.
46 : // @{
47 : virtual bool ParseCommandLine(const CommandLine* command_line);
48 : virtual bool Instrument();
49 : // @}
50 :
51 : // @name Accessors.
52 : // @
53 E : const std::string& agent_dll() {
54 E : return agent_dll_;
55 E : }
56 : // @}
57 :
58 : protected:
59 : // Template method that does the actual instrumentation for a given agent.
60 : // This function is meant to be called by the Instrument function.
61 : // @note The implementation should log on failure.
62 : virtual bool InstrumentImpl() = 0;
63 :
64 : // Pure virtual method that should return the name of the instrumentation
65 : // mode.
66 : virtual const char* InstrumentationMode() = 0;
67 :
68 : // Virtual method called by ParseCommandLine to parse the additional
69 : // command-line arguments specific to an instrumenter.
70 : // @param command_line the command-line to be parsed.
71 : // @returns true by default. Should return false on error.
72 : virtual bool ParseAdditionalCommandLineArguments(
73 E : const CommandLine* command_line) {
74 E : return true;
75 E : }
76 :
77 : // @name Internal machinery, replaceable for testing purposes.
78 : // @{
79 : virtual pe::PERelinker* GetRelinker();
80 : scoped_ptr<pe::PERelinker> relinker_;
81 : // @}
82 :
83 : // The agent DLL used by this instrumentation.
84 : std::string agent_dll_;
85 :
86 : // @name Command-line parameters.
87 : // @{
88 : base::FilePath input_dll_path_;
89 : base::FilePath input_pdb_path_;
90 : base::FilePath output_dll_path_;
91 : base::FilePath output_pdb_path_;
92 : bool allow_overwrite_;
93 : bool debug_friendly_;
94 : bool new_decomposer_;
95 : bool no_augment_pdb_;
96 : bool no_parse_debug_info_;
97 : bool no_strip_strings_;
98 : // @}
99 : };
100 :
101 : } // namespace instrumenters
102 : } // namespace instrument
103 :
104 : #endif // SYZYGY_INSTRUMENT_INSTRUMENTERS_INSTRUMENTER_WITH_AGENT_H_
|