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