diff --git a/src/Cutter.cpp b/src/Cutter.cpp index 009a9e47..11672f24 100644 --- a/src/Cutter.cpp +++ b/src/Cutter.cpp @@ -1229,6 +1229,16 @@ QString CutterCore::getSimpleGraph(QString function) return dot; } +void CutterCore::setGraphEmpty(bool empty) +{ + emptyGraph = empty; +} + +bool CutterCore::isGraphEmpty() +{ + return emptyGraph; +} + void CutterCore::getOpcodes() { QString opcodes = cmd("?O"); diff --git a/src/Cutter.h b/src/Cutter.h index 8910882c..7c52e956 100644 --- a/src/Cutter.h +++ b/src/Cutter.h @@ -538,6 +538,8 @@ public: QJsonDocument getFileVersionInfo(); QStringList getStats(); QString getSimpleGraph(QString function); + void setGraphEmpty(bool empty); + bool isGraphEmpty(); void getOpcodes(); QList opcodes; @@ -661,6 +663,8 @@ private: RVA offsetPriorDebugging = RVA_INVALID; QErrorMessage msgBox; + bool emptyGraph = false; + QList plugins; }; diff --git a/src/widgets/CutterSeekableWidget.cpp b/src/widgets/CutterSeekableWidget.cpp index bd0e74c4..4e310800 100644 --- a/src/widgets/CutterSeekableWidget.cpp +++ b/src/widgets/CutterSeekableWidget.cpp @@ -19,8 +19,7 @@ void CutterSeekableWidget::seek(RVA addr) { if (isInSyncWithCore) { Core()->seek(addr); - } - else { + } else { prevIdenpendentOffset = independentOffset; independentOffset = addr; emit seekChanged(addr); @@ -32,8 +31,7 @@ RVA CutterSeekableWidget::getOffset() RVA addr; if (isInSyncWithCore) { addr = Core()->getOffset(); - } - else { + } else { addr = independentOffset; } return addr; @@ -64,4 +62,4 @@ void CutterSeekableWidget::setIndependentOffset(RVA addr) independentOffset = addr; } -CutterSeekableWidget::~CutterSeekableWidget() {} \ No newline at end of file +CutterSeekableWidget::~CutterSeekableWidget() {} diff --git a/src/widgets/DisassemblerGraphView.cpp b/src/widgets/DisassemblerGraphView.cpp index c25bdc0c..323de0e2 100644 --- a/src/widgets/DisassemblerGraphView.cpp +++ b/src/widgets/DisassemblerGraphView.cpp @@ -168,10 +168,7 @@ void DisassemblerGraphView::loadCurrentGraph() bool emptyGraph = functions.isEmpty(); if (emptyGraph) { - // If there's no function to print, just move to disassembly and add a message - if (Core()->getMemoryWidgetPriority() == CutterCore::MemoryWidgetType::Graph) { - Core()->setMemoryWidgetPriority(CutterCore::MemoryWidgetType::Disassembly); - } + // If there's no function to print, just add a message if (!emptyText) { QVBoxLayout *layout = new QVBoxLayout(this); emptyText = new QLabel(this); @@ -184,6 +181,8 @@ void DisassemblerGraphView::loadCurrentGraph() } else if (emptyText) { emptyText->setVisible(false); } + // Refresh global "empty graph" variable so other widget know there is nothing to show here + Core()->setGraphEmpty(emptyGraph); Analysis anal; anal.ready = true; @@ -707,7 +706,7 @@ void DisassemblerGraphView::seekInstruction(bool previous_instr) continue; } - // Found the instructon. Check if a next one exists + // Found the instruction. Check if a next one exists if (!previous_instr && (i < db->instrs.size() - 1)) { seekable->seek(db->instrs[i + 1].addr); } else if (previous_instr && (i > 0)) { diff --git a/src/widgets/DisassemblerGraphView.h b/src/widgets/DisassemblerGraphView.h index 249b4aa2..9590db1a 100644 --- a/src/widgets/DisassemblerGraphView.h +++ b/src/widgets/DisassemblerGraphView.h @@ -108,7 +108,7 @@ class DisassemblerGraphView : public GraphView public: DisassemblerGraphView(QWidget *parent); - ~DisassemblerGraphView(); + ~DisassemblerGraphView() override; std::unordered_map disassembly_blocks; virtual void drawBlock(QPainter &p, GraphView::GraphBlock &block) override; virtual void blockClicked(GraphView::GraphBlock &block, QMouseEvent *event, QPoint pos) override; @@ -122,7 +122,7 @@ public: void loadCurrentGraph(); QString windowTitle; -// bool navigate(ut64 addr); + bool isGraphEmpty(); public slots: void refreshView(); @@ -160,6 +160,7 @@ private: int charHeight; int charOffset; int baseline; + bool emptyGraph; DisassemblyContextMenu *mMenu; diff --git a/src/widgets/DisassemblyWidget.cpp b/src/widgets/DisassemblyWidget.cpp index dfe7b774..7d6a9907 100644 --- a/src/widgets/DisassemblyWidget.cpp +++ b/src/widgets/DisassemblyWidget.cpp @@ -125,7 +125,8 @@ DisassemblyWidget::DisassemblyWidget(MainWindow *main, QAction *action) connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(colorsUpdatedSlot())); connect(this, &QDockWidget::visibilityChanged, this, [](bool visibility) { - if (visibility) { + bool emptyGraph = (Core()->getMemoryWidgetPriority() == CutterCore::MemoryWidgetType::Graph && Core()->isGraphEmpty()); + if (visibility && !emptyGraph) { Core()->setMemoryWidgetPriority(CutterCore::MemoryWidgetType::Disassembly); } }); @@ -623,7 +624,8 @@ void DisassemblyWidget::on_seekChanged(RVA offset) void DisassemblyWidget::raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType type) { - if (type == CutterCore::MemoryWidgetType::Disassembly) { + bool emptyGraph = (type == CutterCore::MemoryWidgetType::Graph && Core()->isGraphEmpty()); + if (type == CutterCore::MemoryWidgetType::Disassembly || emptyGraph) { raise(); setFocus(); } diff --git a/src/widgets/GraphWidget.cpp b/src/widgets/GraphWidget.cpp index 5f713df2..a07858aa 100644 --- a/src/widgets/GraphWidget.cpp +++ b/src/widgets/GraphWidget.cpp @@ -18,7 +18,8 @@ GraphWidget::GraphWidget(MainWindow *main, QAction *action) : connect(Core(), &CutterCore::raisePrioritizedMemoryWidget, this, [ = ](CutterCore::MemoryWidgetType type) { - if (type == CutterCore::MemoryWidgetType::Graph) { + bool emptyGraph = (type == CutterCore::MemoryWidgetType::Graph && Core()->isGraphEmpty()); + if (type == CutterCore::MemoryWidgetType::Graph && !emptyGraph) { this->raise(); this->graphView->setFocus(); }