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