]> git.siccegge.de Git - frida/frida.git/blob - src/core/InformationManager.hxx
Reoganize Function/BasicBlock creation
[frida/frida.git] / src / core / InformationManager.hxx
1 #ifndef INCLUDE__InformationManager_hxx
2 #define INCLUDE__InformationManager_hxx
3
4 #include <boost/signals2.hpp>
5 #include <functional>
6 #include <string>
7 #include <map>
8
9 class Disassembler;
10 class Function;
11 class BasicBlock;
12 class Comment;
13
14 class QString;
15
16 class RenameFunctionEvent;
17
18 class InformationManager {
19 public:
20 ~InformationManager();
21
22 void reset(const std::string& filename);
23 void save(const QString& filename);
24
25 void signal_new_function(Function* f);
26 void signal_new_dyn_symbol(const std::string& f)
27 { new_dyn_symbol_signal(f); }
28
29 boost::signals2::connection
30 connect_new_function_signal(std::function<void(Function*)> f)
31 { return new_function_signal.connect(f); }
32
33 boost::signals2::connection
34 connect_new_dyn_symbol_signal(std::function<void(const std::string& name)> f)
35 { return new_dyn_symbol_signal.connect(f); }
36
37 boost::signals2::connection
38 connect_reset_signal(std::function<void ()> f)
39 { return reset_signal.connect(f); }
40
41 boost::signals2::connection
42 connect_rename_function_signal(std::function<void (RenameFunctionEvent*)> f)
43 { return rename_function_signal.connect(f); }
44
45 Disassembler* getDisassembler()
46 { return disassembler.get(); }
47
48 void dispatch(RenameFunctionEvent* event)
49 { rename_function_signal(event); }
50
51 Function* getFunction(uint64_t address);
52 BasicBlock* getBasicBlock(uint64_t address);
53
54 /* Protocoll:
55 *
56 * Users may allocate new Data containers with the new*()
57 * functions. Once they have populated the information they hand
58 * over the object to the information manager using the finish*()
59 * functions.
60 *
61 * if new*() returns NULL there already exists a function at the
62 * specified address. Users may then get the old object if they
63 * wish or (more likely) skip creating it. Uniqueness of the
64 * object is only guaranteed as compared to the finish()ed
65 * objects.
66 *
67 * Users are responsible for destroying functions iff they do not
68 * finish them using the delete*() functions. Once the objects are
69 * finished, the information manager is responsible for cleaning
70 * up the memory. If delete*() is called on a finished object, bad
71 * thingsmay happen.
72 */
73 Function* newFunction(uint64_t address);
74 BasicBlock* newBasicBlock(uint64_t address);
75 Comment* newGlobalComment(uint64_t address);
76 Comment* newLocalComment(uint64_t address, Function* f);
77 void finishFunction(Function* f);
78 void finishBasicBlock(BasicBlock* b);
79 void finnishComment(Comment* c);
80 void deleteFunction(Function* f);
81 void deleteBasicBlock(BasicBlock* b);
82 void deleteComment(Comment* c);
83 private:
84 boost::signals2::signal<void ()> reset_signal;
85 boost::signals2::signal<void (Function*)> new_function_signal;
86 boost::signals2::signal<void (const std::string& name)> new_dyn_symbol_signal;
87 boost::signals2::signal<void (RenameFunctionEvent*)> rename_function_signal;
88 std::unique_ptr<Disassembler> disassembler;
89 std::map<uint64_t, Function*> functions;
90 std::map<uint64_t, BasicBlock*> blocks;
91 };
92
93 #endif /* INCLUDE__InformationManager_hxx */