From b8dbe02010ffae82a3a33a9d362d146556924576 Mon Sep 17 00:00:00 2001 From: Nemoumbra Date: Mon, 3 Jul 2023 18:14:26 +0300 Subject: [PATCH] Added a new window class --- CMakeLists.txt | 2 + Windows/Debugger/BreakpointWindow.cpp | 50 ++++----- Windows/Debugger/ScanRemoveWindow.cpp | 142 ++++++++++++++++++++++++++ Windows/Debugger/ScanRemoveWindow.h | 30 ++++++ Windows/PPSSPP.vcxproj | 2 + Windows/PPSSPP.vcxproj.filters | 6 ++ Windows/resource.h | 6 ++ 7 files changed, 215 insertions(+), 23 deletions(-) create mode 100644 Windows/Debugger/ScanRemoveWindow.cpp create mode 100644 Windows/Debugger/ScanRemoveWindow.h diff --git a/CMakeLists.txt b/CMakeLists.txt index a2e49dd691..a485884da7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2373,6 +2373,8 @@ set(WindowsFiles Windows/Debugger/Debugger_VFPUDlg.h Windows/Debugger/WatchItemWindow.cpp Windows/Debugger/WatchItemWindow.h + Windows/Debugger/ScanRemoveWindow.cpp + Windows/Debugger/ScanRemoveWindow.h Windows/GEDebugger/CtrlDisplayListView.cpp Windows/GEDebugger/SimpleGLWindow.cpp Windows/GEDebugger/TabState.cpp diff --git a/Windows/Debugger/BreakpointWindow.cpp b/Windows/Debugger/BreakpointWindow.cpp index 1a1b1a1d21..d26c5f6c29 100644 --- a/Windows/Debugger/BreakpointWindow.cpp +++ b/Windows/Debugger/BreakpointWindow.cpp @@ -11,7 +11,8 @@ INT_PTR CALLBACK BreakpointWindow::StaticDlgFunc(HWND hWnd, UINT iMsg, WPARAM wP if (iMsg == WM_INITDIALOG) { SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)lParam); thiz = (BreakpointWindow *)lParam; - } else { + } + else { thiz = (BreakpointWindow *)GetWindowLongPtr(hWnd, GWLP_USERDATA); } @@ -40,15 +41,15 @@ INT_PTR BreakpointWindow::DlgFunc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lP EnableWindow(GetDlgItem(hwnd, IDC_BREAKPOINT_ONCHANGE), memory); EnableWindow(GetDlgItem(hwnd, IDC_BREAKPOINT_SIZE), memory); EnableWindow(GetDlgItem(hwnd, IDC_BREAKPOINT_LOG_FORMAT), log); - + if (address != -1) { snprintf(str, sizeof(str), "0x%08X", address); - SetWindowTextA(GetDlgItem(hwnd,IDC_BREAKPOINT_ADDRESS),str); + SetWindowTextA(GetDlgItem(hwnd, IDC_BREAKPOINT_ADDRESS), str); } snprintf(str, sizeof(str), "0x%08X", size); - SetWindowTextA(GetDlgItem(hwnd, IDC_BREAKPOINT_SIZE),str); - + SetWindowTextA(GetDlgItem(hwnd, IDC_BREAKPOINT_SIZE), str); + SetWindowTextW(GetDlgItem(hwnd, IDC_BREAKPOINT_CONDITION), ConvertUTF8ToWString(condition).c_str()); SetWindowTextW(GetDlgItem(hwnd, IDC_BREAKPOINT_LOG_FORMAT), ConvertUTF8ToWString(logFormat).c_str()); return TRUE; @@ -121,7 +122,7 @@ INT_PTR BreakpointWindow::DlgFunc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lP bool BreakpointWindow::fetchDialogData(HWND hwnd) { - char str[256],errorMessage[512]; + char str[256], errorMessage[512]; PostfixExpression exp; memory = GetCheckState(hwnd, IDC_BREAKPOINT_MEMORY); @@ -132,36 +133,36 @@ bool BreakpointWindow::fetchDialogData(HWND hwnd) onChange = GetCheckState(hwnd, IDC_BREAKPOINT_ONCHANGE); // parse address - GetWindowTextA(GetDlgItem(hwnd,IDC_BREAKPOINT_ADDRESS),str,256); - if (cpu->initExpression(str,exp) == false) + GetWindowTextA(GetDlgItem(hwnd, IDC_BREAKPOINT_ADDRESS), str, 256); + if (cpu->initExpression(str, exp) == false) { snprintf(errorMessage, sizeof(errorMessage), "Invalid expression \"%s\": %s", str, getExpressionError()); - MessageBoxA(hwnd,errorMessage,"Error",MB_OK); + MessageBoxA(hwnd, errorMessage, "Error", MB_OK); return false; } - if (cpu->parseExpression(exp,address) == false) + if (cpu->parseExpression(exp, address) == false) { snprintf(errorMessage, sizeof(errorMessage), "Invalid expression \"%s\": %s", str, getExpressionError()); - MessageBoxA(hwnd,errorMessage,"Error",MB_OK); + MessageBoxA(hwnd, errorMessage, "Error", MB_OK); return false; } if (memory) { // parse size - GetWindowTextA(GetDlgItem(hwnd,IDC_BREAKPOINT_SIZE),str,256); - if (cpu->initExpression(str,exp) == false) + GetWindowTextA(GetDlgItem(hwnd, IDC_BREAKPOINT_SIZE), str, 256); + if (cpu->initExpression(str, exp) == false) { snprintf(errorMessage, sizeof(errorMessage), "Invalid expression \"%s\": %s", str, getExpressionError()); - MessageBoxA(hwnd,errorMessage,"Error",MB_OK); + MessageBoxA(hwnd, errorMessage, "Error", MB_OK); return false; } - if (cpu->parseExpression(exp,size) == false) + if (cpu->parseExpression(exp, size) == false) { snprintf(errorMessage, sizeof(errorMessage), "Invalid expression \"%s\": %s", str, getExpressionError()); - MessageBoxA(hwnd,errorMessage,"Error",MB_OK); + MessageBoxA(hwnd, errorMessage, "Error", MB_OK); return false; } } @@ -176,7 +177,7 @@ bool BreakpointWindow::fetchDialogData(HWND hwnd) if (cpu->initExpression(condition.c_str(), compiledCondition) == false) { snprintf(errorMessage, sizeof(errorMessage), "Invalid expression \"%s\": %s", condition.c_str(), getExpressionError()); - MessageBoxA(hwnd,errorMessage,"Error",MB_OK); + MessageBoxA(hwnd, errorMessage, "Error", MB_OK); return false; } } @@ -229,16 +230,17 @@ void BreakpointWindow::addBreakpoint() { } CBreakPoints::ChangeMemCheckLogFormat(address, address + size, logFormat); - } else { + } + else { // add breakpoint - CBreakPoints::AddBreakPoint(address,false); + CBreakPoints::AddBreakPoint(address, false); if (!condition.empty()) { BreakPointCond cond; cond.debug = cpu; cond.expressionString = condition; cond.expression = compiledCondition; - CBreakPoints::ChangeBreakPointAddCond(address,cond); + CBreakPoints::ChangeBreakPointAddCond(address, cond); } CBreakPoints::ChangeBreakPoint(address, result); @@ -257,11 +259,12 @@ void BreakpointWindow::loadFromMemcheck(const MemCheck &memcheck) { enabled = (memcheck.result & BREAK_ACTION_PAUSE) != 0; address = memcheck.start; - size = memcheck.end-address; + size = memcheck.end - address; if (memcheck.hasCondition) { condition = memcheck.condition.expressionString; - } else { + } + else { condition.clear(); } @@ -278,7 +281,8 @@ void BreakpointWindow::loadFromBreakpoint(const BreakPoint& breakpoint) { if (breakpoint.hasCond) { condition = breakpoint.cond.expressionString; - } else { + } + else { condition.clear(); } diff --git a/Windows/Debugger/ScanRemoveWindow.cpp b/Windows/Debugger/ScanRemoveWindow.cpp new file mode 100644 index 0000000000..efe50a1969 --- /dev/null +++ b/Windows/Debugger/ScanRemoveWindow.cpp @@ -0,0 +1,142 @@ + +#include "ScanRemoveWindow.h" +#include "../resource.h" + + + +bool ScanRemoveWindow::GetCheckState(HWND hwnd, int dlgItem) { + return SendMessage(GetDlgItem(hwnd, dlgItem), BM_GETCHECK, 0, 0) != 0; +} + +bool ScanRemoveWindow::fetchDialogData(HWND hwnd) +{ + char str[256], errorMessage[512]; + PostfixExpression exp; + + scan = GetCheckState(hwnd, IDC_SCANREMOVE_SCAN); + + // Parse the address + GetWindowTextA(GetDlgItem(hwnd, IDC_SCANREMOVE_ADDRESS), str, 256); + + if (cpu->initExpression(str, exp) == false) + { + snprintf(errorMessage, sizeof(errorMessage), "Invalid expression \"%s\": %s", str, getExpressionError()); + MessageBoxA(hwnd, errorMessage, "Error", MB_OK); + return false; + } + if (cpu->parseExpression(exp, address) == false) + { + snprintf(errorMessage, sizeof(errorMessage), "Invalid expression \"%s\": %s", str, getExpressionError()); + MessageBoxA(hwnd, errorMessage, "Error", MB_OK); + return false; + } + + // Parse the size + GetWindowTextA(GetDlgItem(hwnd, IDC_SCANREMOVE_SIZE), str, 256); + + if (cpu->initExpression(str, exp) == false) + { + snprintf(errorMessage, sizeof(errorMessage), "Invalid expression \"%s\": %s", str, getExpressionError()); + MessageBoxA(hwnd, errorMessage, "Error", MB_OK); + return false; + } + if (cpu->parseExpression(exp, size) == false) + { + snprintf(errorMessage, sizeof(errorMessage), "Invalid expression \"%s\": %s", str, getExpressionError()); + MessageBoxA(hwnd, errorMessage, "Error", MB_OK); + return false; + } + + return true; +} + +INT_PTR CALLBACK ScanRemoveWindow::StaticDlgFunc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { + ScanRemoveWindow *thiz; + if (iMsg == WM_INITDIALOG) { + SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)lParam); + thiz = (ScanRemoveWindow *)lParam; + } + else { + thiz = (ScanRemoveWindow *)GetWindowLongPtr(hWnd, GWLP_USERDATA); + } + + if (!thiz) + return FALSE; + return thiz->DlgFunc(hWnd, iMsg, wParam, lParam); +} + +INT_PTR ScanRemoveWindow::DlgFunc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) +{ + char str[128]; + + switch (iMsg) + { + case WM_INITDIALOG: + + // Set the radiobutton values + SendMessage(GetDlgItem(hwnd, IDC_SCANREMOVE_SCAN), BM_SETCHECK, scan ? BST_CHECKED : BST_UNCHECKED, 0); + SendMessage(GetDlgItem(hwnd, IDC_SCANREMOVE_REMOVE), BM_SETCHECK, scan ? BST_UNCHECKED : BST_CHECKED, 0); + + // Set the text in the textboxes + if (address != -1) { + snprintf(str, sizeof(str), "0x%08X", address); + SetWindowTextA(GetDlgItem(hwnd, IDC_SCANREMOVE_ADDRESS), str); + } + snprintf(str, sizeof(str), "0x%08X", size); + SetWindowTextA(GetDlgItem(hwnd, IDC_SCANREMOVE_SIZE), str); + + return TRUE; + case WM_COMMAND: + switch (LOWORD(wParam)) + { + case IDC_SCANREMOVE_SCAN: + switch (HIWORD(wParam)) + { + case BN_CLICKED: + scan = true; + break; + } + break; + case IDC_SCANREMOVE_REMOVE: + switch (HIWORD(wParam)) + { + case BN_CLICKED: + scan = false; + break; + } + break; + case IDC_SCANREMOVE_OK: + switch (HIWORD(wParam)) + { + case BN_CLICKED: + if (fetchDialogData(hwnd)) { + EndDialog(hwnd, true); + } + break; + }; + break; + case IDC_SCANREMOVE_CANCEL: + switch (HIWORD(wParam)) + { + case BN_CLICKED: + EndDialog(hwnd, false); + break; + }; + break; + case IDOK: + if (fetchDialogData(hwnd)) { + EndDialog(hwnd, true); + } + break; + case IDCANCEL: + EndDialog(hwnd, false); + break; + } + } + + return FALSE; +} + +bool ScanRemoveWindow::exec() { + return DialogBoxParam(GetModuleHandle(0), MAKEINTRESOURCE(IDD_BREAKPOINT), parentHwnd, StaticDlgFunc, (LPARAM)this) != 0; +} diff --git a/Windows/Debugger/ScanRemoveWindow.h b/Windows/Debugger/ScanRemoveWindow.h new file mode 100644 index 0000000000..753fe95685 --- /dev/null +++ b/Windows/Debugger/ScanRemoveWindow.h @@ -0,0 +1,30 @@ +#pragma once +#include +#include "Common/CommonWindows.h" +#include "Common/CommonTypes.h" +#include "Core/Debugger/DebugInterface.h" + +class ScanRemoveWindow { + HWND parentHwnd; + DebugInterface* cpu; + + bool scan; + u32 address; + u32 size; + + bool GetCheckState(HWND hwnd, int dlgItem); + bool fetchDialogData(HWND hwnd); + + static INT_PTR CALLBACK StaticDlgFunc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam); + INT_PTR DlgFunc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam); + +public: + ScanRemoveWindow(HWND parent, DebugInterface* cpu) : cpu(cpu) { + parentHwnd = parent; + scan = true; + address = -1; + size = 1; + } + + bool exec(); +}; diff --git a/Windows/PPSSPP.vcxproj b/Windows/PPSSPP.vcxproj index f0a38f80da..a222977c2f 100644 --- a/Windows/PPSSPP.vcxproj +++ b/Windows/PPSSPP.vcxproj @@ -844,6 +844,7 @@ + @@ -1400,6 +1401,7 @@ + diff --git a/Windows/PPSSPP.vcxproj.filters b/Windows/PPSSPP.vcxproj.filters index 35fa64082c..8c7e46cb3a 100644 --- a/Windows/PPSSPP.vcxproj.filters +++ b/Windows/PPSSPP.vcxproj.filters @@ -280,6 +280,9 @@ Windows\Debugger + + Windows\Debugger + @@ -568,6 +571,9 @@ Windows\Debugger + + Windows\Debugger + Other Platforms\Mac diff --git a/Windows/resource.h b/Windows/resource.h index ae1ff111c3..82e363b816 100644 --- a/Windows/resource.h +++ b/Windows/resource.h @@ -122,6 +122,12 @@ #define IDC_SHOWOFFSETS 1200 #define IDC_GEDBG_PRIMCOUNTER 1201 #define IDC_BUTTON_SEARCH 1204 +#define IDC_SCANREMOVE_SCAN 1205 +#define IDC_SCANREMOVE_REMOVE 1206 +#define IDC_SCANREMOVE_ADDRESS 1207 +#define IDC_SCANREMOVE_SIZE 1208 +#define IDC_SCANREMOVE_OK 1209 +#define IDC_SCANREMOVE_CANCEL 1210 #define ID_FILE_EXIT 40000 #define ID_DEBUG_SAVEMAPFILE 40001