0df07b2a7283d3b270712d7be1477f996ea3cea9
[frida/frida.git] / src / core / BasicBlock.hxx
1 #ifndef INCLUDE__BasicBlock_hxx
2 #define INCLUDE__BasicBlock_hxx
3
4 #include <cassert>
5 #include <string>
6 #include <sstream>
7
8 class Disassembler;
9 class InformationManager;
10 class QXmlStreamWriter;
11 class QXmlStreamReader;
12
13 class BasicBlock {
14 public:
15 uint64_t getStartAddress() const {
16 return start_address;
17 }
18
19 uint64_t getEndAddress() const {
20 return end_address;
21 }
22
23 uint64_t getNextBlock(size_t index) const {
24 assert(index < 2);
25 return next_blocks[index];
26 }
27
28 void setNextBlock(size_t index, uint64_t address) {
29 assert(index < 2);
30 next_blocks[index] = address;
31 }
32
33 void setStartAddress(uint64_t address) {
34 start_address = address;
35 }
36
37 void setEndAddress(uint64_t address) {
38 end_address = address;
39 }
40
41 std::string getName() const {
42 std::stringstream s;
43 s << "BLOCK_" << std::hex << start_address << '_' << end_address;
44 return s.str();
45 }
46
47 InformationManager* getManager() const {
48 return manager;
49 }
50
51 void serialize(QXmlStreamWriter& stream);
52 static BasicBlock* deserialize(QXmlStreamReader& stream, InformationManager* manager);
53
54 private:
55 BasicBlock(uint64_t start_address, InformationManager* manager)
56 : start_address(start_address)
57 , end_address(0)
58 , manager(manager) {
59 next_blocks[0] = 0;
60 next_blocks[1] = 0;
61 }
62
63 uint64_t start_address;
64 uint64_t end_address;
65 Disassembler* disassembler;
66 InformationManager* manager;
67 uint64_t next_blocks[2];
68
69 friend class InformationManager;
70 };
71
72 #endif