]> git.siccegge.de Git - frida/frida.git/blob - src/core/InformationManager.hxx
Run the disassembler in it's own thread
[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 <functional>
6 #include <string>
7 #include <map>
8 #include <vector>
9 #include <memory>
10
11 #include "qt.hxx"
12 #include "disassembler/Disassembler.hxx"
13
14 #include "core/events/NewFunctionEvent.hxx"
15
16 class Interpreter;
17
18 class Function;
19 class BasicBlock;
20 class Comment;
21
22 class RenameFunctionEvent;
23 class NewFunctionEvent;
24 class ChangeCommentEvent;
25
26 class QString;
27 class QTemporaryFile;
28 class QPluginLoader;
29
30 class InformationManager : public QObject {
31 #ifndef SWIG
32 Q_OBJECT
33 signals:
34 #else
35 public:
36 #endif
37 void renameFunctionEvent(RenameFunctionEvent* event);
38 void newFunctionEvent(NewFunctionEvent event);
39 void changeCommentEvent(ChangeCommentEvent* event);
40 void resetEvent();
41 public:
42 InformationManager();
43 ~InformationManager();
44
45 void reset(const std::string& filename);
46 void load(const std::string& filename);
47 void save(const std::string& filename);
48
49 Disassembler* getDisassembler()
50 { return disassembler.get(); }
51
52 // Accessors
53 Function* getFunction(uint64_t address);
54 bool hasFunctions() const {return functions.size() != 0;}
55 std::map<uint64_t, Function*>::const_iterator beginFunctions();
56 std::map<uint64_t, Function*>::const_iterator endFunctions();
57
58 BasicBlock* getBasicBlock(uint64_t address);
59 bool hasBasicBlocks() const {return blocks.size() != 0;}
60 std::map<uint64_t, BasicBlock*>::const_iterator beginBasicBlocks();
61 std::map<uint64_t, BasicBlock*>::const_iterator endBasicBlocks();
62
63 std::pair<
64 std::multimap<uint64_t, Comment*>::const_iterator,
65 std::multimap<uint64_t, Comment*>::const_iterator>
66 getComments(uint64_t address);
67 bool hasComments() const {return ! comments.empty();}
68 std::multimap<uint64_t,Comment*>::const_iterator beginComments();
69 std::multimap<uint64_t,Comment*>::const_iterator endComments();
70
71 Interpreter* getInterpreter(const std::string& name);
72 bool hasInterpreters() const {return interpreters.size() != 0;}
73 std::map<std::string, Interpreter*>::const_iterator beginInterpreters();
74 std::map<std::string, Interpreter*>::const_iterator endInterpreters();
75
76 /* Protocoll:
77 *
78 * Users may allocate new Data containers with the new*()
79 * functions. Once they have populated the information they hand
80 * over the object to the information manager using the finish*()
81 * functions.
82 *
83 * if new*() returns NULL there already exists a function at the
84 * specified address. Users may then get the old object if they
85 * wish or (more likely) skip creating it. Uniqueness of the
86 * object is only guaranteed as compared to the finish()ed
87 * objects.
88 *
89 * Users are responsible for destroying functions iff they do not
90 * finish them using the delete*() functions. Once the objects are
91 * finished, the information manager is responsible for cleaning
92 * up the memory. If delete*() is called on a finished object, bad
93 * thingsmay happen.
94 */
95 Function* newFunction(uint64_t address);
96 Function* newDynamicFunction(uint64_t address);
97 BasicBlock* newBasicBlock(uint64_t address);
98 Comment* newGlobalComment(uint64_t address);
99 Comment* newLocalComment(uint64_t address, Function* f);
100 void finishFunction(Function* f);
101 void finishBasicBlock(BasicBlock* b);
102 void finishComment(Comment* c);
103 void deleteFunction(Function* f);
104 void deleteBasicBlock(BasicBlock* b);
105 void deleteComment(Comment* c);
106
107 private:
108 std::unique_ptr<Disassembler> disassembler;
109
110 std::map<std::string, Interpreter*> interpreters;
111 std::map<uint64_t, Function*> functions;
112 std::map<uint64_t, BasicBlock*> blocks;
113 std::multimap<uint64_t, Comment*> comments;
114
115 std::string filename;
116 std::unique_ptr<QTemporaryFile> tmpfile;
117 std::vector<QPluginLoader*> plugins;
118
119 QThread disassemblerThread;
120 log4cxx::LoggerPtr logger;
121 };
122
123 #endif /* INCLUDE__InformationManager_hxx */