Permalink
Browse files

Debugger: Use a lock for memory reallocs.

Simpler this way, no need to remember to lock memory.
  • Loading branch information...
unknownbrackets committed May 6, 2018
1 parent 8598fc9 commit 3193772e78d7c58ab7fecb07c5a860337314bb0a
Showing with 17 additions and 7 deletions.
  1. +4 −0 Core/Core.h
  2. +3 −0 Core/Debugger/WebSocket.cpp
  3. +0 −3 Core/Debugger/WebSocket/DisasmSubscriber.cpp
  4. +10 −4 Core/MemMap.cpp
View
@@ -45,6 +45,10 @@ enum class CoreLifecycle {
STOPPING,
// Guaranteed call after STOPPING.
STOPPED,
// Sometimes called for save states. Guaranteed sequence, and never during STARTING or STOPPING.
MEMORY_REINITING,
MEMORY_REINITED,
};
typedef void (* CoreLifecycleFunc)(CoreLifecycle stage);
@@ -20,6 +20,7 @@
#include "thread/threadutil.h"
#include "Core/Debugger/WebSocket.h"
#include "Core/Debugger/WebSocket/WebSocketUtils.h"
#include "Core/MemMap.h"
// This WebSocket (connected through the same port as disc sharing) allows API/debugger access to PPSSPP.
// Currently, the only subprotocol "debugger.ppsspp.org" uses a simple JSON based interface.
@@ -88,6 +89,7 @@ static void WebSocketNotifyLifecycle(CoreLifecycle stage) {
switch (stage) {
case CoreLifecycle::STARTING:
case CoreLifecycle::STOPPING:
case CoreLifecycle::MEMORY_REINITING:
if (debuggersConnected > 0) {
DEBUG_LOG(SYSTEM, "Waiting for debugger to complete on shutdown");
}
@@ -96,6 +98,7 @@ static void WebSocketNotifyLifecycle(CoreLifecycle stage) {
case CoreLifecycle::START_COMPLETE:
case CoreLifecycle::STOPPED:
case CoreLifecycle::MEMORY_REINITED:
lifecycleLock.unlock();
if (debuggersConnected > 0) {
DEBUG_LOG(SYSTEM, "Debugger ready for shutdown");
@@ -256,7 +256,6 @@ 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");
}
@@ -339,7 +338,6 @@ 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");
}
@@ -417,7 +415,6 @@ 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");
}
View
@@ -291,6 +291,14 @@ void Init() {
base, m_pPhysicalRAM, m_pUncachedRAM);
}
void Reinit() {
_assert_msg_(SYSTEM, PSP_IsInited(), "Cannot reinit during startup/shutdown");
Core_NotifyLifecycle(CoreLifecycle::MEMORY_REINITING);
Shutdown();
Init();
Core_NotifyLifecycle(CoreLifecycle::MEMORY_REINITED);
}
void DoState(PointerWrap &p) {
auto s = p.Section("Memory", 1, 3);
if (!s)
@@ -308,8 +316,7 @@ void DoState(PointerWrap &p) {
if (!g_RemasterMode) {
g_MemorySize = g_PSPModel == PSP_MODEL_FAT ? RAM_NORMAL_SIZE : RAM_DOUBLE_SIZE;
if (oldMemorySize < g_MemorySize) {
Shutdown();
Init();
Reinit();
}
}
} else {
@@ -320,8 +327,7 @@ void DoState(PointerWrap &p) {
p.DoMarker("PSPModel");
p.Do(g_MemorySize);
if (oldMemorySize != g_MemorySize) {
Shutdown();
Init();
Reinit();
}
}

0 comments on commit 3193772

Please sign in to comment.