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