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_INSTRUMENTER_WITH_AGENT_H_
21 : #define SYZYGY_INSTRUMENT_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 :
31 : class InstrumenterWithAgent : public InstrumenterInterface {
32 : public:
33 : InstrumenterWithAgent()
34 : : allow_overwrite_(false),
35 : new_decomposer_(false),
36 : no_augment_pdb_(false),
37 : no_parse_debug_info_(false),
38 E : no_strip_strings_(false) {
39 E : }
40 :
41 E : ~InstrumenterWithAgent() { }
42 :
43 : // @name InstrumenterInterface implementation.
44 : // @{
45 : virtual bool ParseCommandLine(const CommandLine* command_line);
46 : virtual bool Instrument();
47 : // @}
48 :
49 : // @name Accessors.
50 : // @
51 E : const std::string& agent_dll() {
52 E : return agent_dll_;
53 E : }
54 : // @}
55 :
56 : protected:
57 : // Template method that does the actual instrumentation for a given agent.
58 : // This function is meant to be called by the Instrument function.
59 : // @note The implementation should log on failure.
60 : virtual bool InstrumentImpl() = 0;
61 :
62 : // @name Internal machinery, replaceable for testing purposes.
63 : // @{
64 : virtual pe::PERelinker* GetRelinker();
65 : scoped_ptr<pe::PERelinker> relinker_;
66 : // @}
67 :
68 : // The agent DLL used by this instrumentation.
69 : std::string agent_dll_;
70 :
71 : // @name Command-line parameters.
72 : // @{
73 : base::FilePath input_dll_path_;
74 : base::FilePath input_pdb_path_;
75 : base::FilePath output_dll_path_;
76 : base::FilePath output_pdb_path_;
77 : bool allow_overwrite_;
78 : bool new_decomposer_;
79 : bool no_augment_pdb_;
80 : bool no_parse_debug_info_;
81 : bool no_strip_strings_;
82 : // @}
83 : };
84 :
85 : } // namespace instrument
86 :
87 : #endif // SYZYGY_INSTRUMENT_INSTRUMENTER_WITH_AGENT_H_
|