From f66b0ff56ca2bc867bef82a74fc0e608e5dfc079 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Wed, 10 Feb 2021 20:36:02 -0800 Subject: [PATCH] Debugger: Option to skip mem hacks in memory dump. --- Windows/Debugger/DumpMemoryWindow.cpp | 46 ++++++++++++++++++++------- Windows/ppsspp.rc | 7 ++-- Windows/resource.h | 1 + 3 files changed, 40 insertions(+), 14 deletions(-) diff --git a/Windows/Debugger/DumpMemoryWindow.cpp b/Windows/Debugger/DumpMemoryWindow.cpp index 3676307420..67b95ce8fe 100644 --- a/Windows/Debugger/DumpMemoryWindow.cpp +++ b/Windows/Debugger/DumpMemoryWindow.cpp @@ -2,7 +2,9 @@ #include #include "Common/Data/Encoding/Utf8.h" #include "Core/Core.h" +#include "Core/HLE/ReplaceTables.h" #include "Core/MemMap.h" +#include "Core/MIPS/JitCommon/JitBlockCache.h" #include "Windows/Debugger/DumpMemoryWindow.h" #include "Windows/resource.h" #include "Windows/W32Util/ShellUtil.h" @@ -75,27 +77,49 @@ INT_PTR CALLBACK DumpMemoryWindow::dlgFunc(HWND hwnd, UINT iMsg, WPARAM wParam, } break; case IDOK: - if (bp->fetchDialogData(hwnd)) - { + if (bp->fetchDialogData(hwnd)) { + bool priorDumpWasStepping = Core_IsStepping(); + if (!priorDumpWasStepping && PSP_IsInited()) { + // If emulator isn't paused force paused state, but wait before locking. + Core_EnableStepping(true); + Core_WaitInactive(); + } + auto memLock = Memory::Lock(); if (!PSP_IsInited()) break; FILE *output = _wfopen(bp->fileName_.c_str(), L"wb"); - if (output == NULL) { + if (output == nullptr) { char errorMessage[2048]; snprintf(errorMessage, sizeof(errorMessage), "Could not open file \"%S\".", bp->fileName_.c_str()); - MessageBoxA(hwnd,errorMessage,"Error",MB_OK); + MessageBoxA(hwnd, errorMessage, "Error", MB_OK); break; } - - bool priorDumpWasStepping = Core_IsStepping(); - if (!priorDumpWasStepping) Core_EnableStepping(true); // If emulator isn't paused force paused state - fwrite(Memory::GetPointer(bp->start), 1, bp->size, output); + + bool includeReplacements = SendMessage(GetDlgItem(hwnd, IDC_DUMP_INCLUDEHACKS), BM_GETCHECK, 0, 0) != 0; + if (includeReplacements) { + fwrite(Memory::GetPointer(bp->start), 1, bp->size, output); + } else { + auto savedReplacements = SaveAndClearReplacements(); + if (MIPSComp::jit) { + auto savedBlocks = MIPSComp::jit->SaveAndClearEmuHackOps(); + fwrite(Memory::GetPointer(bp->start), 1, bp->size, output); + MIPSComp::jit->RestoreSavedEmuHackOps(savedBlocks); + } else { + fwrite(Memory::GetPointer(bp->start), 1, bp->size, output); + } + RestoreSavedReplacements(savedReplacements); + } + fclose(output); - if (!priorDumpWasStepping) Core_EnableStepping(false); // If emulator wasn't paused before memory dump resume emulation automatically. - MessageBoxA(hwnd,"Done.","Information",MB_OK); - EndDialog(hwnd,true); + if (!priorDumpWasStepping) { + // If emulator wasn't paused before memory dump resume emulation automatically. + Core_EnableStepping(false); + } + + MessageBoxA(hwnd, "Done.", "Information", MB_OK); + EndDialog(hwnd, true); } break; case IDCANCEL: diff --git a/Windows/ppsspp.rc b/Windows/ppsspp.rc index 966cd1e3b8..4a29a62ea0 100644 --- a/Windows/ppsspp.rc +++ b/Windows/ppsspp.rc @@ -376,7 +376,7 @@ BEGIN PUSHBUTTON "Cancel",IDC_BREAKPOINT_CANCEL,186,98,42,14 END -IDD_DUMPMEMORY DIALOGEX 0, 0, 230, 85 +IDD_DUMPMEMORY DIALOGEX 0, 0, 230, 100 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "Dump memory" FONT 8, "MS Shell Dlg", 400, 0, 0x1 @@ -393,8 +393,9 @@ BEGIN CONTROL "VRAM",IDC_DUMP_VRAM,"Button",BS_AUTORADIOBUTTON,152,22,35,10 CONTROL "Scratchpad",IDC_DUMP_SCRATCHPAD,"Button",BS_AUTORADIOBUTTON,152,34,52,10 CONTROL "Custom range",IDC_DUMP_CUSTOMRANGE,"Button",BS_AUTORADIOBUTTON,152,46,61,10 - DEFPUSHBUTTON "OK",IDOK,117,64,50,14 - PUSHBUTTON "Cancel",IDCANCEL,173,64,50,14 + CONTROL "Include jit checks and replacements",IDC_DUMP_INCLUDEHACKS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,41,58,120,14 + DEFPUSHBUTTON "OK",IDOK,117,79,50,14 + PUSHBUTTON "Cancel",IDCANCEL,173,79,50,14 END diff --git a/Windows/resource.h b/Windows/resource.h index 914629f889..a13d9b3846 100644 --- a/Windows/resource.h +++ b/Windows/resource.h @@ -263,6 +263,7 @@ #define ID_DISASM_ASSEMBLE 40091 #define ID_DISASM_ADDNEWBREAKPOINT 40092 #define ID_DISASM_EDITBREAKPOINT 40093 +#define IDC_DUMP_INCLUDEHACKS 40094 #define ID_EMULATION_CHEATS 40096 #define ID_HELP_CHINESE_FORUM 40097 #define ID_OPTIONS_MORE_SETTINGS 40098