After tested under windows.
[dyninst.git] / patchAPI / h / PatchObject.h
1 /* Plugin Interface */
2
3 #ifndef PATCHAPI_H_DYNINST_OBJECT_H_
4 #define PATCHAPI_H_DYNINST_OBJECT_H_
5
6 #include "common.h"
7 #include "CFGMaker.h"
8
9 namespace Dyninst {
10 namespace PatchAPI {
11
12 class PatchFunction;
13
14 /* PatchObject represents a binary object, which could be either a library or
15    executable. It is also an instrumentation  unit. */
16 class PatchObject {
17   friend class AddrSpace;
18
19   public:
20     PATCHAPI_EXPORT static PatchObject* create(ParseAPI::CodeObject* co, Address base,
21                                                CFGMakerPtr cm = CFGMakerPtr(new CFGMaker));
22     PATCHAPI_EXPORT static PatchObject* clone(PatchObject* par_obj, Address base);
23     PATCHAPI_EXPORT virtual ~PatchObject();
24
25     typedef std::vector<PatchFunction *> funclist;
26     typedef std::map<const ParseAPI::Function*, PatchFunction*> FuncMap;
27     typedef std::map<const ParseAPI::Block*, PatchBlock*> BlockMap;
28     typedef std::map<const ParseAPI::Edge*, PatchEdge*> EdgeMap;
29
30     // Getters and setter
31     Address codeBase() { return codeBase_; }
32     ParseAPI::CodeObject* co() const { return co_; }
33     ParseAPI::CodeSource* cs() const { return cs_; }
34     AddrSpacePtr addrSpace() const { return addr_space_; }
35     void setAddrSpace(AddrSpacePtr as) { addr_space_ = as; }
36
37     // Function
38     PATCHAPI_EXPORT PatchFunction *getFunc(ParseAPI::Function *);
39     PATCHAPI_EXPORT void addFunc(PatchFunction*);
40     PATCHAPI_EXPORT void removeFunc(PatchFunction*);
41
42     // Block
43     PATCHAPI_EXPORT PatchBlock *getBlock(ParseAPI::Block*);
44     PATCHAPI_EXPORT void addBlock(PatchBlock*);
45     PATCHAPI_EXPORT void removeBlock(PatchBlock*);
46
47     // Edge
48     PATCHAPI_EXPORT PatchEdge *getEdge(ParseAPI::Edge*, PatchBlock*, PatchBlock*);
49     PATCHAPI_EXPORT void addEdge(PatchEdge*);
50     PATCHAPI_EXPORT void removeEdge(PatchEdge*);
51
52   protected:
53     ParseAPI::CodeObject* co_;
54     ParseAPI::CodeSource* cs_;
55     Address codeBase_;
56     AddrSpacePtr addr_space_;
57     FuncMap funcs_;
58     BlockMap blocks_;
59     EdgeMap edges_;
60     CFGMakerPtr cfg_maker_;
61
62     PATCHAPI_EXPORT PatchObject(ParseAPI::CodeObject* o, Address a, CFGMakerPtr cm);
63     PATCHAPI_EXPORT PatchObject(const PatchObject* par_obj, Address a);
64     PATCHAPI_EXPORT void copyCFG(PatchObject* par_obj);
65 };
66
67 }
68 }
69
70 #endif  // PATCHAPI_H_DYNINST_MODULE_H_