From 4d93a1a26001b7cb2340ed0d16d29796e3d851f1 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 6 May 2018 10:35:56 -0700 Subject: [PATCH] Debugger: Add some missing memory locks. We can restart memory when loading save states, so we need this even while we've got startup/shutdown locked. --- Core/Debugger/DisassemblyManager.cpp | 2 ++ Core/Debugger/WebSocket/DisasmSubscriber.cpp | 3 +++ Windows/Debugger/CtrlDisAsmView.cpp | 4 +++- Windows/Debugger/CtrlMemView.cpp | 5 +++++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Core/Debugger/DisassemblyManager.cpp b/Core/Debugger/DisassemblyManager.cpp index c5ab4b2e91d4..54ffae28d4a9 100644 --- a/Core/Debugger/DisassemblyManager.cpp +++ b/Core/Debugger/DisassemblyManager.cpp @@ -238,6 +238,8 @@ std::vector DisassemblyManager::getBranchLines(u32 start, u32 size) void DisassemblyManager::getLine(u32 address, bool insertSymbols, DisassemblyLineInfo& dest) { + // This is here really to avoid lock ordering issues. + auto memLock = Memory::Lock(); std::lock_guard guard(entriesLock_); auto it = findDisassemblyEntry(entries,address,false); if (it == entries.end()) diff --git a/Core/Debugger/WebSocket/DisasmSubscriber.cpp b/Core/Debugger/WebSocket/DisasmSubscriber.cpp index 95dddcebb820..84d0692ae2e4 100644 --- a/Core/Debugger/WebSocket/DisasmSubscriber.cpp +++ b/Core/Debugger/WebSocket/DisasmSubscriber.cpp @@ -256,6 +256,7 @@ void WebSocketDisasmState::Base(DebuggerRequest &req) { // - params: formatted parameters for the instruction. // - (other info about the disassembled line.) void WebSocketDisasmState::Disasm(DebuggerRequest &req) { + auto memLock = Memory::Lock(); if (!currentDebugMIPS->isAlive() || !Memory::IsActive()) { return req.Fail("CPU not started"); } @@ -338,6 +339,7 @@ void WebSocketDisasmState::Disasm(DebuggerRequest &req) { // Response (same event name): // - address: number address of match or null if none was found. void WebSocketDisasmState::SearchDisasm(DebuggerRequest &req) { + auto memLock = Memory::Lock(); if (!currentDebugMIPS->isAlive() || !Memory::IsActive()) { return req.Fail("CPU not started"); } @@ -415,6 +417,7 @@ void WebSocketDisasmState::SearchDisasm(DebuggerRequest &req) { // Response (same event name): // - encoding: resulting encoding at this address. Always returns one value, even for macros. void WebSocketDisasmState::Assemble(DebuggerRequest &req) { + auto memLock = Memory::Lock(); if (!currentDebugMIPS->isAlive() || !Memory::IsActive()) { return req.Fail("CPU not started"); } diff --git a/Windows/Debugger/CtrlDisAsmView.cpp b/Windows/Debugger/CtrlDisAsmView.cpp index 7b8ea0440684..93d4ed61789e 100644 --- a/Windows/Debugger/CtrlDisAsmView.cpp +++ b/Windows/Debugger/CtrlDisAsmView.cpp @@ -201,7 +201,6 @@ COLORREF scaleColor(COLORREF color, float factor) bool CtrlDisAsmView::getDisasmAddressText(u32 address, char* dest, bool abbreviateLabels, bool showData) { - auto memLock = Memory::Lock(); if (!PSP_IsInited()) return false; @@ -469,6 +468,7 @@ void CtrlDisAsmView::drawArguments(HDC hdc, const DisassemblyLineInfo &line, int void CtrlDisAsmView::onPaint(WPARAM wParam, LPARAM lParam) { + auto memLock = Memory::Lock(); if (!debugger->isAlive()) return; PAINTSTRUCT ps; @@ -1180,6 +1180,7 @@ void CtrlDisAsmView::calculatePixelPositions() void CtrlDisAsmView::search(bool continueSearch) { + auto memLock = Memory::Lock(); u32 searchAddress; if (continueSearch == false || searchQuery[0] == 0) @@ -1260,6 +1261,7 @@ void CtrlDisAsmView::search(bool continueSearch) std::string CtrlDisAsmView::disassembleRange(u32 start, u32 size) { + auto memLock = Memory::Lock(); std::string result; // gather all branch targets without labels diff --git a/Windows/Debugger/CtrlMemView.cpp b/Windows/Debugger/CtrlMemView.cpp index 4cede1270ea4..f1cc93e37289 100644 --- a/Windows/Debugger/CtrlMemView.cpp +++ b/Windows/Debugger/CtrlMemView.cpp @@ -174,6 +174,8 @@ CtrlMemView *CtrlMemView::getFrom(HWND hwnd) void CtrlMemView::onPaint(WPARAM wParam, LPARAM lParam) { + auto memLock = Memory::Lock(); + // draw to a bitmap for double buffering PAINTSTRUCT ps; HDC actualHdc = BeginPaint(wnd, &ps); @@ -445,6 +447,7 @@ void CtrlMemView::onMouseUp(WPARAM wParam, LPARAM lParam, int button) case ID_MEMVIEW_COPYVALUE_8: { + auto memLock = Memory::Lock(); char temp[24]; // it's admittedly not really useful like this @@ -462,6 +465,7 @@ void CtrlMemView::onMouseUp(WPARAM wParam, LPARAM lParam, int button) case ID_MEMVIEW_COPYVALUE_16: { + auto memLock = Memory::Lock(); char temp[24]; sprintf(temp,"%04X",Memory::IsValidAddress(curAddress) ? Memory::Read_U16(curAddress) : 0xFFFF); @@ -471,6 +475,7 @@ void CtrlMemView::onMouseUp(WPARAM wParam, LPARAM lParam, int button) case ID_MEMVIEW_COPYVALUE_32: { + auto memLock = Memory::Lock(); char temp[24]; sprintf(temp,"%08X",Memory::IsValidAddress(curAddress) ? Memory::Read_U32(curAddress) : 0xFFFFFFFF);