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 aa2a3c6c..570cc95e 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/SnapshotDiff.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/SnapshotDiff.cpp @@ -50,6 +50,38 @@ namespace Bloom::Widgets this->dataBSecondaryLabel->setText(snapshotB.createdDate.toString("dd/MM/yyyy hh:mm")); } + SnapshotDiff::SnapshotDiff( + MemorySnapshot& snapshotA, + Targets::TargetMemoryBuffer dataB, + std::vector focusedRegionsB, + std::vector excludedRegionsB, + Targets::TargetStackPointer stackPointerB, + const Targets::TargetMemoryDescriptor& memoryDescriptor, + QWidget* parent + ) + : QWidget(parent) + , memoryDescriptor(memoryDescriptor) + , hexViewerDataA(snapshotA.data) + , focusedRegionsA(snapshotA.focusedRegions) + , excludedRegionsA(snapshotA.excludedRegions) + , stackPointerA(snapshotA.stackPointer) + , hexViewerDataB(dataB) + , focusedRegionsB(focusedRegionsB) + , excludedRegionsB(excludedRegionsB) + , stackPointerB(stackPointerB) + { + this->init(); + + this->setWindowTitle( + "Comparing snapshot \"" + snapshotA.name + "\" with current memory" + ); + + this->dataAPrimaryLabel->setText(snapshotA.name); + this->dataBPrimaryLabel->setText("Current"); + this->dataASecondaryLabel->setText(snapshotA.createdDate.toString("dd/MM/yyyy hh:mm")); + this->dataBSecondaryLabel->setVisible(false); + } + void SnapshotDiff::showEvent(QShowEvent* event) { QWidget::showEvent(event); } @@ -206,16 +238,16 @@ namespace Bloom::Widgets this->hexViewerWidgetB->setOther(this->hexViewerWidgetA); // this->hexViewerWidgetA->addExternalContextMenuAction(this->restoreBytesAction); - if (this->stackPointerA.has_value()) { - this->hexViewerWidgetA->setStackPointer(*(this->stackPointerA)); + if (this->memoryDescriptor.type == Targets::TargetMemoryType::RAM) { + this->hexViewerWidgetA->setStackPointer(this->stackPointerA); } } void SnapshotDiff::onHexViewerBReady() { this->hexViewerWidgetA->setOther(this->hexViewerWidgetB); - if (this->stackPointerB.has_value()) { - this->hexViewerWidgetB->setStackPointer(*(this->stackPointerB)); + if (this->memoryDescriptor.type == Targets::TargetMemoryType::RAM) { + this->hexViewerWidgetB->setStackPointer(this->stackPointerB); } } 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 8c7a1fa2..7e772e89 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/SnapshotDiff.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/SnapshotDiff.hpp @@ -35,6 +35,16 @@ namespace Bloom::Widgets QWidget* parent = nullptr ); + SnapshotDiff( + MemorySnapshot& snapshotA, + Targets::TargetMemoryBuffer dataB, + std::vector focusedRegionsB, + std::vector excludedRegionsB, + Targets::TargetStackPointer stackPointerB, + const Targets::TargetMemoryDescriptor& memoryDescriptor, + QWidget* parent = nullptr + ); + protected: void showEvent(QShowEvent* event) override; void resizeEvent(QResizeEvent* event) override; @@ -65,14 +75,14 @@ namespace Bloom::Widgets std::optional hexViewerDataA; std::vector focusedRegionsA; std::vector excludedRegionsA; - std::optional stackPointerA; + Targets::TargetStackPointer stackPointerA; DifferentialHexViewerWidget* hexViewerWidgetA = nullptr; HexViewerWidgetSettings hexViewerWidgetSettingsA = HexViewerWidgetSettings(); std::optional hexViewerDataB; std::vector focusedRegionsB; std::vector excludedRegionsB; - std::optional stackPointerB; + Targets::TargetStackPointer stackPointerB; DifferentialHexViewerWidget* hexViewerWidgetB = nullptr; HexViewerWidgetSettings hexViewerWidgetSettingsB = HexViewerWidgetSettings(); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotManager.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotManager.cpp index d4428bf4..1e9f45fe 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotManager.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotManager.cpp @@ -27,6 +27,7 @@ namespace Bloom::Widgets const bool& staleData, const std::vector& focusedMemoryRegions, const std::vector& excludedMemoryRegions, + const std::optional& stackPointer, PaneState& state, PanelWidget* parent ) @@ -36,6 +37,7 @@ namespace Bloom::Widgets , staleData(staleData) , focusedMemoryRegions(focusedMemoryRegions) , excludedMemoryRegions(excludedMemoryRegions) + , stackPointer(stackPointer) { this->setObjectName("snapshot-manager"); this->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); @@ -158,6 +160,19 @@ namespace Bloom::Widgets } ); + QObject::connect( + this->openSnapshotCurrentDiffAction, + &QAction::triggered, + this, + [this] { + if (this->selectedSnapshotItems.size() != 1) { + return; + } + + this->openSnapshotCurrentDiff(this->selectedSnapshotItems.front()->memorySnapshot.id); + } + ); + QObject::connect( this->deleteSnapshotAction, &QAction::triggered, @@ -340,6 +355,40 @@ namespace Bloom::Widgets snapshotDiff->activateWindow(); } + void SnapshotManager::openSnapshotCurrentDiff(const QString& snapshotIdA) { + if (!this->data.has_value()) { + return; + } + + const auto diffKey = snapshotIdA; + auto snapshotDiffIt = this->snapshotDiffs.find(diffKey); + + if (snapshotDiffIt == this->snapshotDiffs.end()) { + const auto& snapshotItA = this->snapshotsById.find(snapshotIdA); + + if (snapshotItA == this->snapshotsById.end()) { + return; + } + + snapshotDiffIt = this->snapshotDiffs.insert( + diffKey, + new SnapshotDiff( + snapshotItA.value(), + *(this->data), + this->focusedMemoryRegions, + this->excludedMemoryRegions, + this->stackPointer.value_or(0), + this->memoryDescriptor, + this + ) + ); + } + + auto* snapshotDiff = snapshotDiffIt.value(); + snapshotDiff->show(); + snapshotDiff->activateWindow(); + } + void SnapshotManager::deleteSnapshot(const QString& snapshotId, bool confirmationPromptEnabled) { const auto& snapshotIt = this->snapshotsById.find(snapshotId); @@ -529,10 +578,16 @@ namespace Bloom::Widgets menu->addAction(this->openSnapshotViewerAction); menu->addAction(this->deleteSnapshotAction); menu->addSeparator(); + menu->addAction(this->openSnapshotCurrentDiffAction); + menu->addSeparator(); menu->addAction(this->restoreSnapshotAction); this->openSnapshotViewerAction->setEnabled(this->selectedSnapshotItems.size() == 1); this->deleteSnapshotAction->setEnabled(this->selectedSnapshotItems.size() == 1); + this->openSnapshotCurrentDiffAction->setEnabled( + this->selectedSnapshotItems.size() == 1 + && this->data.has_value() + ); this->restoreSnapshotAction->setEnabled( this->selectedSnapshotItems.size() == 1 && this->targetState == Targets::TargetState::STOPPED ); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotManager.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotManager.hpp index 19442ca9..b0f68210 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotManager.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotManager.hpp @@ -41,6 +41,7 @@ namespace Bloom::Widgets const bool& staleData, const std::vector& focusedMemoryRegions, const std::vector& excludedMemoryRegions, + const std::optional& stackPointer, PaneState& state, PanelWidget* parent = nullptr ); @@ -60,6 +61,7 @@ namespace Bloom::Widgets const std::vector& focusedMemoryRegions; const std::vector& excludedMemoryRegions; + const std::optional& stackPointer; Targets::TargetState targetState = Targets::TargetState::UNKNOWN; @@ -81,6 +83,7 @@ namespace Bloom::Widgets QAction* openSnapshotViewerAction = new QAction("Open", this); QAction* openSnapshotDiffAction = new QAction("Compare Selection", this); + QAction* openSnapshotCurrentDiffAction = new QAction("Compare with Current", this); QAction* deleteSnapshotAction = new QAction("Delete", this); QAction* restoreSnapshotAction = new QAction("Restore", this); @@ -95,6 +98,7 @@ namespace Bloom::Widgets void onSnapshotItemSelectionChanged(const std::list& selectedItems); void openSnapshotViewer(const QString& snapshotId); void openSnapshotDiff(const QString& snapshotIdA, const QString& snapshotIdB); + void openSnapshotCurrentDiff(const QString& snapshotIdA); void deleteSnapshot(const QString& snapshotId, bool confirmationPromptEnabled); void restoreSnapshot(const QString& snapshotId, bool confirmationPromptEnabled); void onSnapshotItemDoubleClick(MemorySnapshotItem* item); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.cpp index 49d3792d..fb0b8552 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.cpp @@ -126,6 +126,7 @@ namespace Bloom::Widgets this->staleData, this->settings.focusedMemoryRegions, this->settings.excludedMemoryRegions, + this->stackPointer, this->settings.snapshotManagerState, this->rightPanel ); @@ -350,6 +351,7 @@ namespace Bloom::Widgets &ReadStackPointer::stackPointerRead, this, [this] (Targets::TargetStackPointer stackPointer) { + this->stackPointer = stackPointer; this->hexViewerWidget->setStackPointer(stackPointer); } ); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.hpp index 0f342cd5..646f6719 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.hpp @@ -59,6 +59,7 @@ namespace Bloom::Widgets const Targets::TargetMemoryDescriptor& targetMemoryDescriptor; std::optional data; + std::optional stackPointer; std::optional> activeRefreshTask; QWidget* container = nullptr;