From 4979a0a839390713671f3f9756dc6820501d4ad4 Mon Sep 17 00:00:00 2001 From: Christoph Egger Date: Tue, 2 Jun 2015 21:31:28 +0200 Subject: [PATCH] Make requestNewFunction pass a signal With the Disassembler being assigned to a different thread soon, this should allow the gui to stay alive while the disassembler is busy working. --- src/core/InformationManager.cxx | 1 + src/core/InformationManager.hxx | 2 +- src/disassembler/Disassembler.hxx | 14 ++++++++++++-- src/gui/Mainwindow.cxx | 13 ++++++------- src/gui/Mainwindow.hxx | 2 ++ src/gui/widgets/BasicBlockWidget.cxx | 2 +- 6 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/core/InformationManager.cxx b/src/core/InformationManager.cxx index c548a55..b947a58 100644 --- a/src/core/InformationManager.cxx +++ b/src/core/InformationManager.cxx @@ -41,6 +41,7 @@ InformationManager::~InformationManager() { void InformationManager::reset(const std::string& filename) { this->filename = filename; disassembler.reset(createLLVMDisassembler(filename, this)); + emit resetEvent(); if (disassembler.get() != NULL) disassembler.get()->start(); } diff --git a/src/core/InformationManager.hxx b/src/core/InformationManager.hxx index 2f70d73..c7d6321 100644 --- a/src/core/InformationManager.hxx +++ b/src/core/InformationManager.hxx @@ -35,7 +35,7 @@ public: void renameFunctionEvent(RenameFunctionEvent* event); void newFunctionEvent(NewFunctionEvent* event); void changeCommentEvent(ChangeCommentEvent* event); - void reset(); + void resetEvent(); public: InformationManager(); ~InformationManager(); diff --git a/src/disassembler/Disassembler.hxx b/src/disassembler/Disassembler.hxx index 7e1e3e1..ad35018 100644 --- a/src/disassembler/Disassembler.hxx +++ b/src/disassembler/Disassembler.hxx @@ -5,13 +5,17 @@ #include #include +#include "qt.hxx" #include "Instruction.hxx" class Function; class BasicBlock; class InformationManager; -class Disassembler { +class Disassembler : public QObject { +#ifndef SWIG + Q_OBJECT +#endif public: Disassembler() {} virtual ~Disassembler() {} @@ -20,7 +24,13 @@ public: virtual void getSymbols() = 0; virtual uint64_t entryAddress() = 0; - virtual Function * disassembleFunctionAt(uint64_t address, const std::string& name = "") = 0; +#ifndef SWIG +public slots: +#endif + virtual Function * disassembleFunctionAt(uint64_t address) { + return disassembleFunctionAt(address, ""); + } + virtual Function * disassembleFunctionAt(uint64_t address, const std::string& name) = 0; virtual std::vector getInstructions(const BasicBlock* block) = 0; }; diff --git a/src/gui/Mainwindow.cxx b/src/gui/Mainwindow.cxx index adadc06..850c036 100644 --- a/src/gui/Mainwindow.cxx +++ b/src/gui/Mainwindow.cxx @@ -90,6 +90,11 @@ Mainwindow::Mainwindow(InformationManager* mgr) QTreeWidgetItem * external = new QTreeWidgetItem(listWidget, QStringList("External Functions")); external->setChildIndicatorPolicy(QTreeWidgetItem::ShowIndicator); external->setBackground(0, QBrush(QColor(0xff, 0xdd, 0xdd))); + connect(mgr, &InformationManager::resetEvent, + [this,mgr]() { + connect(this, SIGNAL(requestNewFunctionByAddress(uint64_t)), + mgr->getDisassembler(), SLOT(disassembleFunctionAt(uint64_t))); + }); connect(mgr, &InformationManager::newFunctionEvent, [=] (NewFunctionEvent* event) { std::string name = event->function->getName(); @@ -220,7 +225,7 @@ void Mainwindow::requestNewFunction() { NewFunctionDialog dialog; int result = dialog.exec(); if (QDialog::Accepted == result) { - requestNewFunctionByAddress(dialog.result()); + emit requestNewFunctionByAddress(dialog.result()); } else { LOG4CXX_DEBUG(logger, "requestNewFunction aborted"); } @@ -238,12 +243,6 @@ void Mainwindow::requestNewGroup() { } } -void Mainwindow::requestNewFunctionByAddress(uint64_t address) { - LOG4CXX_DEBUG(logger, "requesting Function at " << std::hex << address); - manager->getDisassembler()->disassembleFunctionAt(address); - switchMainPlaneToAddress(address); -} - void Mainwindow::renameFunction(Function* function) { SimpleStringDialog dialog("New name"); int result = dialog.exec(); diff --git a/src/gui/Mainwindow.hxx b/src/gui/Mainwindow.hxx index 1b497df..3a3a94d 100644 --- a/src/gui/Mainwindow.hxx +++ b/src/gui/Mainwindow.hxx @@ -28,6 +28,8 @@ public: public slots: void switchMainPlaneToAddress(uint64_t); + +signals: void requestNewFunctionByAddress(uint64_t address); private: diff --git a/src/gui/widgets/BasicBlockWidget.cxx b/src/gui/widgets/BasicBlockWidget.cxx index e08cba5..21f432f 100644 --- a/src/gui/widgets/BasicBlockWidget.cxx +++ b/src/gui/widgets/BasicBlockWidget.cxx @@ -58,7 +58,7 @@ void CustomQGraphicsTextItem::contextMenuEvent(QGraphicsSceneContextMenuEvent* e QAction* act = menu.addAction(c.selectedText() + " is a Function"); QObject::connect(act, &QAction::triggered, [=]() { - parent->mainwindow->requestNewFunctionByAddress(address); + emit parent->mainwindow->requestNewFunctionByAddress(address); if (NULL == table) return; int row = table->cellAt(c).row(); uint64_t insAddress = parent->instructions[row].getAddress(); -- 2.39.5