Highlight jumptargets
authorChristoph Egger <siccegge@stud.informatik.uni-erlangen.de>
Tue, 19 May 2015 17:02:13 +0000 (19:02 +0200)
committerChristoph Egger <christoph@anonymous.siccegge.de>
Tue, 19 May 2015 17:07:41 +0000 (19:07 +0200)
 + 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
src/gui/widgets/BasicBlockWidget.hxx
src/gui/widgets/CFGScene.cxx
src/gui/widgets/CFGScene.hxx

index ee3b7afc0048ead4a014630349187602ea61b2a4..de97c51d521c92b6cfc36d1871102a0b31cd221e 100644 (file)
@@ -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);
index 215086d760b2cc7a03fb692fd75b71dc34b7790e..30eeb69d81ec30fa9c535645a76f020010c5f5bb 100644 (file)
@@ -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<QGraphicsTextItem> _widget;
        QTextTable* _table;
        BasicBlock* block;
index 7e31acbd8dc1af8f05b82c700c10d155b9f191cb..c40e2498494a85a403156feb0c1d83864da93d5e 100644 (file)
@@ -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());
+}
index b343381f6e97fc99165af834badf04ff429af9af..094233c0e11ccb4b17c95fb2d76193cfcc8a6eb3 100644 (file)
@@ -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<BasicBlockWidget*> widgets;
 
        void drawLine(QPainter* painter, BasicBlockWidget * from, BasicBlockWidget * to, int8_t side = 0);
 
        void spaceWidgets();
+
+       BasicBlockWidget* highlightedBlock;
 };
 
 #endif