From 7e983f239ca96faf5c8ba92cd4de54eba5235f75 Mon Sep 17 00:00:00 2001 From: Christoph Egger Date: Tue, 19 May 2015 19:02:13 +0200 Subject: [PATCH] Highlight jumptargets + Properly handle jmps at the right place in the gui + Try to center on the relevant BasicBlock + Change color of the BasicBlock Centering needs us to increase the actual Scene size as well so we can also center on widgets at the rim of the scene. Bug should only be closed once this is implemented Ref T31 --- src/gui/widgets/BasicBlockWidget.cxx | 20 ++++++++++++++++++-- src/gui/widgets/BasicBlockWidget.hxx | 10 ++++++++++ src/gui/widgets/CFGScene.cxx | 12 ++++++++++++ src/gui/widgets/CFGScene.hxx | 5 ++++- 4 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/gui/widgets/BasicBlockWidget.cxx b/src/gui/widgets/BasicBlockWidget.cxx index ee3b7af..de97c51 100644 --- a/src/gui/widgets/BasicBlockWidget.cxx +++ b/src/gui/widgets/BasicBlockWidget.cxx @@ -1,4 +1,5 @@ #include "BasicBlockWidget.hxx" +#include "CFGScene.hxx" #include "gui/Mainwindow.hxx" #include "gui/dialogs/SimpleStringDialog.hxx" #include "core/BasicBlock.hxx" @@ -103,7 +104,7 @@ void CustomQGraphicsTextItem::adjustSize() { BasicBlockWidget::BasicBlockWidget(const QString& name, BasicBlock * block, Mainwindow * mainwindow) : width(200), height(45), name(name) - , _table(NULL) + , currentColor(defaultColor), _table(NULL) , block(block), mainwindow(mainwindow) , logger(log4cxx::Logger::getLogger("gui.BasicBlockWidget." + name.toStdString())) { next[0] = NULL; next[1] = NULL; @@ -122,6 +123,21 @@ BasicBlockWidget::BasicBlockWidget(const QString& name, BasicBlock * block, if (str.startsWith("function:")) { QString address = str.remove("function:"); mainwindow->switchMainPlaneToAddress(address.toInt(NULL, 16)); + } else if (str.startsWith("block:")) { + QString address = str.remove("block:"); + + /* next[0] is always the jumptarget. On a + * conditional jump, next[1] also + * contains the following instruction + * + * TODO: Verify we're switching to the + * right block -- the target + * address matches the next blocks + * start address + */ + LOG4CXX_TRACE(logger, "Highlighting block at Address " << address.toStdString() + << " BasicBlockWidget " << std::hex << next[0]); + ((CFGScene*)this->scene())->highlightBlock(next[0]); } }); instructions = block->getInstructions(); @@ -251,7 +267,7 @@ void BasicBlockWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem*, height = 25 + _widget->boundingRect().height(); if (width < 250) width = 250; - painter->fillRect(0, 0, width, height, QColor(0xcc, 0xcc, 0xff, 0xff)); + painter->fillRect(0, 0, width, height, currentColor); painter->setPen(QColor(0x00, 0x00, 0xff, 0xff)); painter->drawRect(0, 0, width, height); painter->drawText(5, 15, name); diff --git a/src/gui/widgets/BasicBlockWidget.hxx b/src/gui/widgets/BasicBlockWidget.hxx index 215086d..30eeb69 100644 --- a/src/gui/widgets/BasicBlockWidget.hxx +++ b/src/gui/widgets/BasicBlockWidget.hxx @@ -46,6 +46,15 @@ public: QString getName() const { return name; } + + QColor setColor(const QColor& newColor) { + QColor lastcolor = currentColor; + currentColor = newColor; + return lastcolor; + } + + const QColor defaultColor = QColor(0xcc, 0xcc, 0xff, 0xff); + const QColor highlightColor = QColor(0xff, 0x99, 0xff, 0xff); private: void updateFunctionName(RenameFunctionEvent* event); void populateWidget(); @@ -54,6 +63,7 @@ private: uint32_t width, height; QString name; + QColor currentColor; std::unique_ptr _widget; QTextTable* _table; BasicBlock* block; diff --git a/src/gui/widgets/CFGScene.cxx b/src/gui/widgets/CFGScene.cxx index 7e31acb..c40e249 100644 --- a/src/gui/widgets/CFGScene.cxx +++ b/src/gui/widgets/CFGScene.cxx @@ -107,3 +107,15 @@ void CFGScene::spaceWidgets() { } } } + +void CFGScene::highlightBlock(BasicBlockWidget* block) { + QGraphicsView* view = *(views().begin()); + if (highlightedBlock) { + highlightedBlock->setColor(highlightedBlock->defaultColor); + update(highlightedBlock->boundingRect()); + } + highlightedBlock = block; + view->centerOn(block); + block->setColor(block->highlightColor); + update(block->boundingRect()); +} diff --git a/src/gui/widgets/CFGScene.hxx b/src/gui/widgets/CFGScene.hxx index b343381..094233c 100644 --- a/src/gui/widgets/CFGScene.hxx +++ b/src/gui/widgets/CFGScene.hxx @@ -9,7 +9,7 @@ class CFGScene : public QGraphicsScene { public: CFGScene(QWidget * parent = 0) - : QGraphicsScene(parent) {} + : QGraphicsScene(parent), highlightedBlock(NULL) {} // Take special care when adding a BasicBlock to the scene as we // need to draw arrows for it later on @@ -19,12 +19,15 @@ public: } virtual void drawBackground(QPainter* painter, const QRectF & rect); + void highlightBlock(BasicBlockWidget* block); private: std::vector widgets; void drawLine(QPainter* painter, BasicBlockWidget * from, BasicBlockWidget * to, int8_t side = 0); void spaceWidgets(); + + BasicBlockWidget* highlightedBlock; }; #endif -- 2.39.2