Reoganize Function/BasicBlock creation
[frida/frida.git] / src / gui / Mainwindow.cxx
index b2f5b4da2b1e273e1e3a0ed7065bb1e9b2ba3996..47ab2a3eda39b0447d26c3259e351546302e474e 100644 (file)
@@ -14,8 +14,8 @@
 
 namespace {
        BasicBlockWidget *
-       local__add_basic_block(BasicBlock * block, Disassembler * dis,
-                              Mainwindow * mainwindow,
+       local__add_basic_block(BasicBlock * block, 
+                              Mainwindow * mainwindow, InformationManager * manager,
                               std::map<uint64_t, BasicBlockWidget*>& known_blocks,
                               CFGScene * scene, uint64_t starty, uint64_t startx);
 }
@@ -173,8 +173,7 @@ void Mainwindow::addFunction(Function* fun) {
        // CFG
        CFGScene * scene = new CFGScene;
 
-       Disassembler * dis = manager->getDisassembler();
-       BasicBlock * block = dis->getBasicBlock(fun->getStartAddress());
+       BasicBlock * block = manager->getBasicBlock(fun->getStartAddress());
 
        uint64_t start_address(std::numeric_limits<uint64_t>::max());
        for (auto b : fun->blocks()) {
@@ -182,8 +181,8 @@ void Mainwindow::addFunction(Function* fun) {
                        start_address = b.first;
        }
 
-       local__add_basic_block(block, manager->getDisassembler(), this,
-                              blocks, scene, start_address, 100);
+       local__add_basic_block(block, this,
+                              manager, blocks, scene, start_address, 100);
 
        QGraphicsView * view = new QGraphicsView(scene);
        w->addTab(view, "CFG");
@@ -205,8 +204,8 @@ void Mainwindow::addFunction(Function* fun) {
 
 namespace {
        BasicBlockWidget *
-       local__add_basic_block(BasicBlock * block, Disassembler * dis,
-                              Mainwindow * mainwindow,
+       local__add_basic_block(BasicBlock * block,
+                              Mainwindow * mainwindow, InformationManager * manager,
                               std::map<uint64_t, BasicBlockWidget*>& known_blocks,
                               CFGScene * scene, uint64_t starty, uint64_t startx) {
 
@@ -226,16 +225,17 @@ namespace {
                widget->setFlag(QGraphicsItem::ItemIsMovable, true);
                widget->moveBy(100*startx, block->getStartAddress() - starty);
 
-               dis->printEachInstruction(block->getStartAddress(),
-                                         block->getEndAddress(),
-                                         [&](uint8_t* bytes,
-                                             size_t byte_count,
-                                             const std::string& line,
-                                             const std::string& ref) {
-                                                 widget->addItem(bytes, byte_count,
-                                                                 line.c_str() + 1, // remove \t
-                                                                 ref.c_str());
-                                         });
+               manager->getDisassembler()
+                       ->printEachInstruction(block->getStartAddress(),
+                                              block->getEndAddress(),
+                                              [&](uint8_t* bytes,
+                                                  size_t byte_count,
+                                                  const std::string& line,
+                                                  const std::string& ref) {
+                                                      widget->addItem(bytes, byte_count,
+                                                                      line.c_str() + 1, // remove \t
+                                                                      ref.c_str());
+                                              });
 
                BasicBlockWidget *tmp, *nextl(NULL), *nextr(NULL);
                BasicBlock * tmpblock;
@@ -243,18 +243,16 @@ namespace {
                        int xshift = 0;
                        if (block->getNextBlock(1) != 0)
                                xshift = 1;
-                       tmpblock = dis->getBasicBlock(block->getNextBlock(0));
-                       tmp = local__add_basic_block(tmpblock, dis,
-                                                    mainwindow,
+                       tmpblock = manager->getBasicBlock(block->getNextBlock(0));
+                       tmp = local__add_basic_block(tmpblock, mainwindow, manager,
                                                     known_blocks,
                                                     scene, starty, startx+xshift);
                        nextl = tmp;
                        tmp->addPrevious(widget);
                }
                if (block->getNextBlock(1) != 0) {
-                       tmpblock = dis->getBasicBlock(block->getNextBlock(1));
-                       tmp = local__add_basic_block(tmpblock, dis,
-                                                    mainwindow,
+                       tmpblock = manager->getBasicBlock(block->getNextBlock(1));
+                       tmp = local__add_basic_block(tmpblock, mainwindow, manager,
                                                     known_blocks,
                                                     scene, starty, startx-1);
                        nextr = tmp;