From e523ac836543bede2126ad198ecf6f0b973c5e5d Mon Sep 17 00:00:00 2001 From: Lucas Hosseini Date: Sun, 14 May 2023 06:59:13 +0200 Subject: [PATCH] Get rid of stale jump arrows in disassembly widget. (#3175) This commit clears arrows from edited instructions, in order to avoid stale arrows to remain drawn. closes #3114 --- src/widgets/DisassemblyWidget.cpp | 17 ++++++++++++++++- src/widgets/DisassemblyWidget.h | 2 ++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/widgets/DisassemblyWidget.cpp b/src/widgets/DisassemblyWidget.cpp index 4c18b57f5c..d892ffd1e0 100644 --- a/src/widgets/DisassemblyWidget.cpp +++ b/src/widgets/DisassemblyWidget.cpp @@ -132,7 +132,7 @@ DisassemblyWidget::DisassemblyWidget(MainWindow *main) connect(Core(), &CutterCore::functionRenamed, this, [this]() { refreshDisasm(); }); connect(Core(), SIGNAL(varsChanged()), this, SLOT(refreshDisasm())); connect(Core(), SIGNAL(asmOptionsChanged()), this, SLOT(refreshDisasm())); - connect(Core(), &CutterCore::instructionChanged, this, &DisassemblyWidget::refreshIfInRange); + connect(Core(), &CutterCore::instructionChanged, this, &DisassemblyWidget::instructionChanged); connect(Core(), &CutterCore::breakpointsChanged, this, &DisassemblyWidget::refreshIfInRange); connect(Core(), SIGNAL(refreshCodeViews()), this, SLOT(refreshDisasm())); @@ -226,6 +226,12 @@ void DisassemblyWidget::refreshIfInRange(RVA offset) } } +void DisassemblyWidget::instructionChanged(RVA offset) +{ + leftPanel->clearArrowFrom(offset); + refreshDisasm(); +} + void DisassemblyWidget::refreshDisasm(RVA offset) { if (!disasmRefresh->attemptRefresh(offset == RVA_INVALID ? nullptr : new RVA(offset))) { @@ -988,3 +994,12 @@ void DisassemblyLeftPanel::paintEvent(QPaintEvent *event) lastBeginOffset = lines.first().offset; } + +void DisassemblyLeftPanel::clearArrowFrom(RVA offset) +{ + auto it = std::find_if(arrows.begin(), arrows.end(), + [&](const Arrow &it) { return it.jmpFromOffset() == offset; }); + if (it != arrows.end()) { + arrows.erase(it); + } +} diff --git a/src/widgets/DisassemblyWidget.h b/src/widgets/DisassemblyWidget.h index 1ab1621687..ce3e8a62e8 100644 --- a/src/widgets/DisassemblyWidget.h +++ b/src/widgets/DisassemblyWidget.h @@ -53,6 +53,7 @@ public slots: protected slots: void on_seekChanged(RVA offset); void refreshIfInRange(RVA offset); + void instructionChanged(RVA offset); void refreshDisasm(RVA offset = RVA_INVALID); bool updateMaxLines(); @@ -153,6 +154,7 @@ class DisassemblyLeftPanel : public QFrame DisassemblyLeftPanel(DisassemblyWidget *disas); void paintEvent(QPaintEvent *event) override; void wheelEvent(QWheelEvent *event) override; + void clearArrowFrom(RVA offset); private: DisassemblyWidget *disas;