]> git.siccegge.de Git - frida/frida.git/blobdiff - src/gui/Mainwindow.cxx
Make link to local functions clickable
[frida/frida.git] / src / gui / Mainwindow.cxx
index 764eb0376d1ca4acb12f56fb0faa7b37c27c98d1..0f2486ddc13e2ed82227107d0f791368f82bb8b6 100644 (file)
@@ -4,15 +4,13 @@
 
 #include "widgets/CFGScene.hxx"
 #include "dialogs/NewFunctionDialog.hxx"
-#include <iostream>
-#include <sstream>
-#include <map>
 
-#include <QtGui>
+#include <sstream>
 
 namespace {
        BasicBlockWidget *
        local__add_basic_block(BasicBlock * block, Disassembler * dis,
+                              Mainwindow * mainwindow,
                               std::map<uint64_t, BasicBlockWidget*>& known_blocks,
                               CFGScene * scene, uint64_t starty, uint64_t startx);
 }
@@ -54,7 +52,7 @@ Mainwindow::Mainwindow(InformationManager* mgr)
        setCentralWidget(stackedWidget);
 
        connect(listWidget, SIGNAL(currentRowChanged(int)),
-               stackedWidget, SLOT(setCurrentIndex(int)));
+               this, SLOT(switchMainPlane(int)));
 
        setWindowTitle(tr("FRIDA"));
 
@@ -83,6 +81,22 @@ void Mainwindow::open() {
        manager->reset(fileName.toStdString());
 }
 
+void Mainwindow::switchMainPlaneToAddress(uint64_t address) {
+       if (objects_list_by_address.find(address) != objects_list_by_address.end()) {
+               LOG4CXX_DEBUG(logger, "Switching to function " << std::hex << address);
+               QListWidgetItem * item = objects_list_by_address[address];
+               listWidget->setCurrentItem(item);
+               stackedWidget->setCurrentWidget(objects_list[item]);
+       } else {
+               LOG4CXX_DEBUG(logger, "No function at " << std::hex << address
+                             << " -- it's probably an imported Symbol");
+       }
+}
+
+void Mainwindow::switchMainPlane(int index) {
+       stackedWidget->setCurrentWidget(objects_list[listWidget->currentItem()]);
+}
+
 void Mainwindow::showListContextMenu(const QPoint& point) {
        QListWidgetItem * item = listWidget->itemAt(point);
        if (item) {
@@ -127,8 +141,8 @@ void Mainwindow::addFunction(Function* fun) {
                        start_address = b.first;
        }
 
-       local__add_basic_block(block, manager->getDisassembler(), blocks, scene,
-                              start_address, 100);
+       local__add_basic_block(block, manager->getDisassembler(), this,
+                              blocks, scene, start_address, 100);
 
        QGraphicsView * view = new QGraphicsView(scene);
        w->addTab(view, "CFG");
@@ -140,13 +154,18 @@ void Mainwindow::addFunction(Function* fun) {
 
        w->addTab(t, "Listing");
 
-       listWidget->addItem(fun->getName().c_str());
+       QListWidgetItem * item = new QListWidgetItem(fun->getName().c_str(), listWidget);
        stackedWidget->addWidget(w);
+       objects_list.insert(std::make_pair(item, w));
+       LOG4CXX_DEBUG(logger, "Adding function widget at " << std::hex
+                     << fun->getStartAddress());
+       objects_list_by_address.insert(std::make_pair(fun->getStartAddress(), item));
 }
 
 namespace {
        BasicBlockWidget *
        local__add_basic_block(BasicBlock * block, Disassembler * dis,
+                              Mainwindow * mainwindow,
                               std::map<uint64_t, BasicBlockWidget*>& known_blocks,
                               CFGScene * scene, uint64_t starty, uint64_t startx) {
 
@@ -157,7 +176,8 @@ namespace {
                std::stringstream s;
                s << "BLOCK_" << std::hex << block->getStartAddress()
                  << "_" << block->getEndAddress();
-               BasicBlockWidget * widget = new BasicBlockWidget(s.str().c_str(), block);
+               BasicBlockWidget * widget = new BasicBlockWidget(s.str().c_str(),
+                                                                block, mainwindow);
 
                known_blocks.insert(std::make_pair(block->getStartAddress(), widget));
 
@@ -184,6 +204,7 @@ namespace {
                                xshift = 1;
                        tmpblock = dis->getBasicBlock(block->getNextBlock(0));
                        tmp = local__add_basic_block(tmpblock, dis,
+                                                    mainwindow,
                                                     known_blocks,
                                                     scene, starty, startx+xshift);
                        nextl = tmp;
@@ -192,6 +213,7 @@ namespace {
                if (block->getNextBlock(1) != 0) {
                        tmpblock = dis->getBasicBlock(block->getNextBlock(1));
                        tmp = local__add_basic_block(tmpblock, dis,
+                                                    mainwindow,
                                                     known_blocks,
                                                     scene, starty, startx-1);
                        nextr = tmp;