Function wrapping implementation and Symtab extensions for undefined symbols
[dyninst.git] / patchAPI / src / Instrumenter.C
1 /* Plugin */
2
3 #include "Instrumenter.h"
4 #include "PatchCFG.h"
5
6 using Dyninst::PatchAPI::InstrumenterPtr;
7 using Dyninst::PatchAPI::Instrumenter;
8 using Dyninst::PatchAPI::InstanceSet;
9 using Dyninst::PatchAPI::AddrSpacePtr;
10 using Dyninst::PatchAPI::PatchFunction;
11 using Dyninst::PatchAPI::PatchBlock;
12
13 /* Default implementation of Instrumenter */
14
15 InstrumenterPtr
16 Instrumenter::create(AddrSpacePtr as) {
17   InstrumenterPtr ret = InstrumenterPtr(new Instrumenter(as));
18   if (!ret) return InstrumenterPtr();
19   return ret;
20 }
21 /*
22 bool
23 Instrumenter::process() {
24   return true;
25 }
26 */
27 bool
28 Instrumenter::replaceFunction(PatchFunction* oldfunc, PatchFunction *newfunc) {
29   functionReplacements_[oldfunc] = newfunc;
30   return true;
31 }
32
33 bool
34 Instrumenter::revertReplacedFunction(PatchFunction* oldfunc) {
35   functionReplacements_.erase(oldfunc);
36   return true;
37 }
38
39 bool
40 Instrumenter::wrapFunction(PatchFunction* oldfunc, PatchFunction *newfunc, std::string name) {
41    functionWraps_[oldfunc] = std::make_pair(newfunc, name);
42    return true;
43 }
44
45 bool
46 Instrumenter::revertWrappedFunction(PatchFunction* oldfunc) {
47   functionWraps_.erase(oldfunc);
48   return true;
49 }
50
51 bool
52 Instrumenter::modifyCall(PatchBlock *callBlock, PatchFunction *newCallee, PatchFunction *context) {
53   callModifications_[callBlock][context] = newCallee;
54   return true;
55 }
56
57 bool
58 Instrumenter::revertModifiedCall(PatchBlock *callBlock, PatchFunction *context) {
59   if (callModifications_.find(callBlock) != callModifications_.end()) {
60     callModifications_[callBlock].erase(context);
61   }
62   return true;
63 }
64
65 bool
66 Instrumenter::removeCall(PatchBlock *callBlock, PatchFunction *context) {
67   modifyCall(callBlock, NULL, context);
68   return true;
69 }