From e72efe71f279cc103afcf100dc7855c15d8cf734 Mon Sep 17 00:00:00 2001 From: Nav Date: Mon, 1 May 2023 17:08:06 +0100 Subject: [PATCH] Refresh snapshot diff windows when comparing against current memory and the memory has been updated --- .../SnapshotDiff/SnapshotDiff.cpp | 19 +++++++++++++ .../SnapshotDiff/SnapshotDiff.hpp | 7 +++++ .../SnapshotManager/SnapshotManager.cpp | 27 +++++++++++++++---- .../SnapshotManager/SnapshotManager.hpp | 3 +++ .../TargetMemoryInspectionPane.cpp | 7 +++-- 5 files changed, 56 insertions(+), 7 deletions(-) diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/SnapshotDiff.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/SnapshotDiff.cpp index 570cc95e..9e4e87ba 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/SnapshotDiff.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/SnapshotDiff.cpp @@ -82,6 +82,25 @@ namespace Bloom::Widgets this->dataBSecondaryLabel->setVisible(false); } + void SnapshotDiff::refreshB( + Targets::TargetMemoryBuffer data, + std::vector focusedRegions, + std::vector excludedRegions, + Targets::TargetStackPointer stackPointer + ) { + this->hexViewerDataB = data; + this->focusedRegionsB = focusedRegions; + this->excludedRegionsB = excludedRegions; + this->stackPointerB = stackPointer; + + if (this->memoryDescriptor.type == Targets::TargetMemoryType::RAM) { + this->hexViewerWidgetB->setStackPointer(this->stackPointerB); + } + + this->hexViewerWidgetB->refreshRegions(); + this->hexViewerWidgetB->updateValues(); + } + void SnapshotDiff::showEvent(QShowEvent* event) { QWidget::showEvent(event); } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/SnapshotDiff.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/SnapshotDiff.hpp index 7e772e89..1f1e19e3 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/SnapshotDiff.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/SnapshotDiff.hpp @@ -45,6 +45,13 @@ namespace Bloom::Widgets QWidget* parent = nullptr ); + void refreshB( + Targets::TargetMemoryBuffer data, + std::vector focusedRegions, + std::vector excludedRegions, + Targets::TargetStackPointer stackPointer + ); + protected: void showEvent(QShowEvent* event) override; void resizeEvent(QResizeEvent* event) override; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotManager.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotManager.cpp index 1e9f45fe..3d3c5b07 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotManager.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotManager.cpp @@ -239,6 +239,24 @@ namespace Bloom::Widgets this->show(); } + void SnapshotManager::onCurrentDataChanged() { + this->createSnapshotWindow->refreshForm(); + + if (!this->data.has_value()) { + return; + } + + // Refresh the data in all snapshot diff windows where current data is being used + for (auto& snapshotCurrentDiff : this->snapshotCurrentDiffsBySnapshotAId) { + snapshotCurrentDiff->refreshB( + *(this->data), + this->focusedMemoryRegions, + this->excludedMemoryRegions, + this->stackPointer.value_or(0) + ); + } + } + void SnapshotManager::resizeEvent(QResizeEvent* event) { const auto size = this->size(); this->container->setFixedSize(size.width(), size.height()); @@ -360,18 +378,17 @@ namespace Bloom::Widgets return; } - const auto diffKey = snapshotIdA; - auto snapshotDiffIt = this->snapshotDiffs.find(diffKey); + auto snapshotDiffIt = this->snapshotCurrentDiffsBySnapshotAId.find(snapshotIdA); - if (snapshotDiffIt == this->snapshotDiffs.end()) { + if (snapshotDiffIt == this->snapshotCurrentDiffsBySnapshotAId.end()) { const auto& snapshotItA = this->snapshotsById.find(snapshotIdA); if (snapshotItA == this->snapshotsById.end()) { return; } - snapshotDiffIt = this->snapshotDiffs.insert( - diffKey, + snapshotDiffIt = this->snapshotCurrentDiffsBySnapshotAId.insert( + snapshotIdA, new SnapshotDiff( snapshotItA.value(), *(this->data), diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotManager.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotManager.hpp index b0f68210..e4636428 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotManager.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotManager.hpp @@ -46,6 +46,8 @@ namespace Bloom::Widgets PanelWidget* parent = nullptr ); + void onCurrentDataChanged(); + signals: void insightWorkerTaskCreated(const QSharedPointer& task); void snapshotRestored(const QString& snapshotId); @@ -69,6 +71,7 @@ namespace Bloom::Widgets QMap snapshotItemsById; QMap snapshotViewersById; QMap snapshotDiffs; + QMap snapshotCurrentDiffsBySnapshotAId; QWidget* container = nullptr; QWidget* toolBar = nullptr; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.cpp index fb0b8552..179cc134 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.cpp @@ -361,6 +361,8 @@ namespace Bloom::Widgets &InsightWorkerTask::finished, this, [this] { + this->snapshotManager->onCurrentDataChanged(); + this->refreshButton->stopSpin(); if (this->targetState == Targets::TargetState::STOPPED) { @@ -380,6 +382,9 @@ namespace Bloom::Widgets this->taskProgressIndicator->addTask(readStackPointerTask); InsightWorker::queueTask(readStackPointerTask); + + } else { + this->snapshotManager->onCurrentDataChanged(); } } ); @@ -580,8 +585,6 @@ namespace Bloom::Widgets this->data = data; this->hexViewerWidget->updateValues(); this->setStaleData(false); - - this->snapshotManager->createSnapshotWindow->refreshForm(); } void TargetMemoryInspectionPane::openMemoryRegionManagerWindow() {