Implemented "Compare with Current" action in snapshot manager

This commit is contained in:
Nav
2023-05-01 15:48:01 +01:00
parent e3cbfdc5fc
commit 9c8e130446
6 changed files with 110 additions and 6 deletions

View File

@@ -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<FocusedMemoryRegion> focusedRegionsB,
std::vector<ExcludedMemoryRegion> 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);
}
}

View File

@@ -35,6 +35,16 @@ namespace Bloom::Widgets
QWidget* parent = nullptr
);
SnapshotDiff(
MemorySnapshot& snapshotA,
Targets::TargetMemoryBuffer dataB,
std::vector<FocusedMemoryRegion> focusedRegionsB,
std::vector<ExcludedMemoryRegion> 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<Targets::TargetMemoryBuffer> hexViewerDataA;
std::vector<FocusedMemoryRegion> focusedRegionsA;
std::vector<ExcludedMemoryRegion> excludedRegionsA;
std::optional<Targets::TargetStackPointer> stackPointerA;
Targets::TargetStackPointer stackPointerA;
DifferentialHexViewerWidget* hexViewerWidgetA = nullptr;
HexViewerWidgetSettings hexViewerWidgetSettingsA = HexViewerWidgetSettings();
std::optional<Targets::TargetMemoryBuffer> hexViewerDataB;
std::vector<FocusedMemoryRegion> focusedRegionsB;
std::vector<ExcludedMemoryRegion> excludedRegionsB;
std::optional<Targets::TargetStackPointer> stackPointerB;
Targets::TargetStackPointer stackPointerB;
DifferentialHexViewerWidget* hexViewerWidgetB = nullptr;
HexViewerWidgetSettings hexViewerWidgetSettingsB = HexViewerWidgetSettings();

View File

@@ -27,6 +27,7 @@ namespace Bloom::Widgets
const bool& staleData,
const std::vector<FocusedMemoryRegion>& focusedMemoryRegions,
const std::vector<ExcludedMemoryRegion>& excludedMemoryRegions,
const std::optional<Targets::TargetStackPointer>& 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
);

View File

@@ -41,6 +41,7 @@ namespace Bloom::Widgets
const bool& staleData,
const std::vector<FocusedMemoryRegion>& focusedMemoryRegions,
const std::vector<ExcludedMemoryRegion>& excludedMemoryRegions,
const std::optional<Targets::TargetStackPointer>& stackPointer,
PaneState& state,
PanelWidget* parent = nullptr
);
@@ -60,6 +61,7 @@ namespace Bloom::Widgets
const std::vector<FocusedMemoryRegion>& focusedMemoryRegions;
const std::vector<ExcludedMemoryRegion>& excludedMemoryRegions;
const std::optional<Targets::TargetStackPointer>& 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<ListItem*>& 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);

View File

@@ -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);
}
);

View File

@@ -59,6 +59,7 @@ namespace Bloom::Widgets
const Targets::TargetMemoryDescriptor& targetMemoryDescriptor;
std::optional<Targets::TargetMemoryBuffer> data;
std::optional<Targets::TargetStackPointer> stackPointer;
std::optional<QSharedPointer<ReadTargetMemory>> activeRefreshTask;
QWidget* container = nullptr;