From c0fc2e65e05a472654be131c0e830b13cef0d51d Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 9 Apr 2023 00:47:36 -0700 Subject: [PATCH] Debugger: Highlight changed watches. --- Windows/Debugger/Debugger_Lists.cpp | 34 ++++++++++++++++++++++++++--- Windows/Debugger/Debugger_Lists.h | 7 ++++++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/Windows/Debugger/Debugger_Lists.cpp b/Windows/Debugger/Debugger_Lists.cpp index 92ff4ec457..505db7176e 100644 --- a/Windows/Debugger/Debugger_Lists.cpp +++ b/Windows/Debugger/Debugger_Lists.cpp @@ -823,7 +823,23 @@ CtrlWatchList::CtrlWatchList(HWND hwnd, DebugInterface *cpu) } void CtrlWatchList::RefreshValues() { - Update(); + int steppingCounter = Core_GetSteppingCounter(); + int changes = false; + for (auto &watch : watches_) { + if (watch.steppingCounter != steppingCounter) { + watch.lastValue = watch.currentValue; + watch.steppingCounter = steppingCounter; + changes = true; + } + + uint32_t prevValue = watch.currentValue; + watch.evaluateFailed = !cpu_->parseExpression(watch.expression, watch.currentValue); + if (prevValue != watch.currentValue) + changes = true; + } + + if (changes) + Update(); } bool CtrlWatchList::WindowMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT &returnValue) { @@ -902,6 +918,14 @@ void CtrlWatchList::OnRightClick(int itemIndex, int column, const POINT &pt) { } } +bool CtrlWatchList::OnRowPrePaint(int row, LPNMLVCUSTOMDRAW msg) { + if (row >= 0 && HasWatchChanged(row)) { + msg->clrText = RGB(255, 0, 0); + return true; + } + return false; +} + void CtrlWatchList::AddWatch() { WatchItemWindow win(nullptr, GetHandle(), cpu_); if (win.Exec()) { @@ -910,7 +934,7 @@ void CtrlWatchList::AddWatch() { info.name = win.GetName(); info.originalExpression = win.GetExpression(); watches_.push_back(info); - Update(); + RefreshValues(); } else { char errorMessage[512]; snprintf(errorMessage, sizeof(errorMessage), "Invalid expression \"%s\": %s", win.GetExpression().c_str(), getExpressionError()); @@ -926,7 +950,7 @@ void CtrlWatchList::EditWatch(int pos) { if (cpu_->initExpression(win.GetExpression().c_str(), watches_[pos].expression)) { watches_[pos].name = win.GetName(); watches_[pos].originalExpression = win.GetExpression(); - Update(); + RefreshValues(); } else { char errorMessage[512]; snprintf(errorMessage, sizeof(errorMessage), "Invalid expression \"%s\": %s", win.GetExpression().c_str(), getExpressionError()); @@ -939,3 +963,7 @@ void CtrlWatchList::DeleteWatch(int pos) { watches_.erase(watches_.begin() + pos); Update(); } + +bool CtrlWatchList::HasWatchChanged(int pos) { + return watches_[pos].lastValue != watches_[pos].currentValue; +} diff --git a/Windows/Debugger/Debugger_Lists.h b/Windows/Debugger/Debugger_Lists.h index 9858b29955..04c92b4d09 100644 --- a/Windows/Debugger/Debugger_Lists.h +++ b/Windows/Debugger/Debugger_Lists.h @@ -95,16 +95,23 @@ protected: void GetColumnText(wchar_t *dest, int row, int col) override; int GetRowCount() override { return (int)watches_.size(); } void OnRightClick(int itemIndex, int column, const POINT &point) override; + bool ListenRowPrePaint() override { return true; } + bool OnRowPrePaint(int row, LPNMLVCUSTOMDRAW msg) override; private: void AddWatch(); void EditWatch(int pos); void DeleteWatch(int pos); + bool HasWatchChanged(int pos); struct WatchInfo { std::string name; std::string originalExpression; PostfixExpression expression; + uint32_t currentValue = 0; + uint32_t lastValue = 0; + int steppingCounter = -1; + bool evaluateFailed = false; }; std::vector watches_; DebugInterface *cpu_;