Skip to content

Commit

Permalink
Debugger: Use a lock for memory reallocs.
Browse files Browse the repository at this point in the history
Simpler this way, no need to remember to lock memory.
  • Loading branch information
unknownbrackets committed May 7, 2018
1 parent 4d93a1a commit aaa4e93
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
4 changes: 4 additions & 0 deletions Core/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions Core/Debugger/WebSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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");
}
Expand All @@ -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");
Expand Down
3 changes: 0 additions & 3 deletions Core/Debugger/WebSocket/DisasmSubscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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");
}
Expand Down
14 changes: 10 additions & 4 deletions Core/MemMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand All @@ -320,8 +327,7 @@ void DoState(PointerWrap &p) {
p.DoMarker("PSPModel");
p.Do(g_MemorySize);
if (oldMemorySize != g_MemorySize) {
Shutdown();
Init();
Reinit();
}
}

Expand Down

0 comments on commit aaa4e93

Please sign in to comment.