From 4e43b1ec8cc0a10310d1407b453c67051da8b89b Mon Sep 17 00:00:00 2001 From: dreamsyntax Date: Wed, 27 Nov 2024 01:30:02 -0700 Subject: [PATCH] Debugger/MemoryScanner: Add 'Freeze Selected' (#3334) --- src/core/memory_scanner.cpp | 8 ++++++++ src/core/memory_scanner.h | 2 ++ src/duckstation-qt/memoryscannerwindow.cpp | 20 ++++++++++++++++++++ src/duckstation-qt/memoryscannerwindow.h | 1 + src/duckstation-qt/memoryscannerwindow.ui | 12 +++++++++++- 5 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/core/memory_scanner.cpp b/src/core/memory_scanner.cpp index 4a75150fd..30b1a7f70 100644 --- a/src/core/memory_scanner.cpp +++ b/src/core/memory_scanner.cpp @@ -340,6 +340,14 @@ bool MemoryWatchList::AddEntry(std::string description, u32 address, MemoryAcces return true; } +bool MemoryWatchList::GetEntryFreeze(u32 index) const +{ + if (index >= m_entries.size()) + return false; + + return m_entries[index].freeze; +} + void MemoryWatchList::RemoveEntry(u32 index) { if (index >= m_entries.size()) diff --git a/src/core/memory_scanner.h b/src/core/memory_scanner.h index 659dc6d62..fefb46052 100644 --- a/src/core/memory_scanner.h +++ b/src/core/memory_scanner.h @@ -112,6 +112,8 @@ public: u32 GetEntryCount() const { return static_cast(m_entries.size()); } bool AddEntry(std::string description, u32 address, MemoryAccessSize size, bool is_signed, bool freeze); + bool GetEntryFreeze(u32 index) const; + void RemoveEntry(u32 index); bool RemoveEntryByDescription(const char* description); bool RemoveEntryByAddress(u32 address); diff --git a/src/duckstation-qt/memoryscannerwindow.cpp b/src/duckstation-qt/memoryscannerwindow.cpp index ff56d6c46..30d0501a3 100644 --- a/src/duckstation-qt/memoryscannerwindow.cpp +++ b/src/duckstation-qt/memoryscannerwindow.cpp @@ -171,6 +171,7 @@ void MemoryScannerWindow::connectUi() }); connect(m_ui.scanAddWatch, &QPushButton::clicked, this, &MemoryScannerWindow::addToWatchClicked); connect(m_ui.scanAddManualAddress, &QPushButton::clicked, this, &MemoryScannerWindow::addManualWatchAddressClicked); + connect(m_ui.scanFreezeWatch, &QPushButton::clicked, this, &MemoryScannerWindow::freezeWatchClicked); connect(m_ui.scanRemoveWatch, &QPushButton::clicked, this, &MemoryScannerWindow::removeWatchClicked); connect(m_ui.scanTable, &QTableWidget::currentItemChanged, this, &MemoryScannerWindow::scanCurrentItemChanged); connect(m_ui.watchTable, &QTableWidget::currentItemChanged, this, &MemoryScannerWindow::watchCurrentItemChanged); @@ -208,6 +209,7 @@ void MemoryScannerWindow::enableUi(bool enabled) m_ui.scanAddWatch->setEnabled(enabled && !m_ui.scanTable->selectedItems().empty()); m_ui.watchTable->setEnabled(enabled); m_ui.scanAddManualAddress->setEnabled(enabled); + m_ui.scanFreezeWatch->setEnabled(enabled && !m_ui.watchTable->selectedItems().empty()); m_ui.scanRemoveWatch->setEnabled(enabled && !m_ui.watchTable->selectedItems().empty()); } @@ -330,6 +332,22 @@ void MemoryScannerWindow::addManualWatchAddressClicked() updateWatch(); } +void MemoryScannerWindow::freezeWatchClicked() +{ + const int indexFirst = getSelectedWatchIndexFirst(); + const int indexLast = getSelectedWatchIndexLast(); + if (indexFirst < 0) + return; + + const bool freeze = m_watch.GetEntryFreeze(indexFirst); + + for (int index = indexLast; index >= indexFirst; index--) + { + m_watch.SetEntryFreeze(static_cast(index), !freeze); + updateWatch(); + } +} + void MemoryScannerWindow::removeWatchClicked() { const int indexFirst = getSelectedWatchIndexFirst(); @@ -351,6 +369,7 @@ void MemoryScannerWindow::scanCurrentItemChanged(QTableWidgetItem* current, QTab void MemoryScannerWindow::watchCurrentItemChanged(QTableWidgetItem* current, QTableWidgetItem* previous) { + m_ui.scanFreezeWatch->setEnabled((current != nullptr)); m_ui.scanRemoveWatch->setEnabled((current != nullptr)); } @@ -569,6 +588,7 @@ void MemoryScannerWindow::updateWatch() } m_ui.scanSaveWatch->setEnabled(!entries.empty()); + m_ui.scanFreezeWatch->setEnabled(false); m_ui.scanRemoveWatch->setEnabled(false); } diff --git a/src/duckstation-qt/memoryscannerwindow.h b/src/duckstation-qt/memoryscannerwindow.h index 0b47d7e02..cb7af539d 100644 --- a/src/duckstation-qt/memoryscannerwindow.h +++ b/src/duckstation-qt/memoryscannerwindow.h @@ -37,6 +37,7 @@ private Q_SLOTS: void addToWatchClicked(); void addManualWatchAddressClicked(); + void freezeWatchClicked(); void removeWatchClicked(); void scanCurrentItemChanged(QTableWidgetItem* current, QTableWidgetItem* previous); void watchCurrentItemChanged(QTableWidgetItem* current, QTableWidgetItem* previous); diff --git a/src/duckstation-qt/memoryscannerwindow.ui b/src/duckstation-qt/memoryscannerwindow.ui index 8b3baea37..73299a152 100644 --- a/src/duckstation-qt/memoryscannerwindow.ui +++ b/src/duckstation-qt/memoryscannerwindow.ui @@ -436,13 +436,23 @@ + + + + false + + + Freeze Selected Entries + + + false - Remove Selected Entries from Watch List + Remove Selected Entries