diff --git a/CMakeLists.txt b/CMakeLists.txt index a1cc6b95f5..5d1b359c53 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1414,6 +1414,8 @@ add_library(${CoreLibName} ${CoreLinkType} Core/Debugger/WebSocket/GameBroadcaster.h Core/Debugger/WebSocket/GameSubscriber.cpp Core/Debugger/WebSocket/GameSubscriber.h + Core/Debugger/WebSocket/HLESubscriber.cpp + Core/Debugger/WebSocket/HLESubscriber.h Core/Debugger/WebSocket/LogBroadcaster.cpp Core/Debugger/WebSocket/LogBroadcaster.h Core/Debugger/WebSocket/SteppingBroadcaster.cpp diff --git a/Core/Core.vcxproj b/Core/Core.vcxproj index 1b95d40373..d38b535a23 100644 --- a/Core/Core.vcxproj +++ b/Core/Core.vcxproj @@ -189,6 +189,7 @@ + @@ -546,6 +547,7 @@ + diff --git a/Core/Core.vcxproj.filters b/Core/Core.vcxproj.filters index f4803dd56c..221dd1c738 100644 --- a/Core/Core.vcxproj.filters +++ b/Core/Core.vcxproj.filters @@ -725,6 +725,9 @@ Debugger\WebSocket + + Debugger\WebSocket + @@ -1340,6 +1343,9 @@ HLE\Kernel + + Debugger\WebSocket + diff --git a/Core/Debugger/WebSocket.cpp b/Core/Debugger/WebSocket.cpp index f477746c78..7bce20cc5e 100644 --- a/Core/Debugger/WebSocket.cpp +++ b/Core/Debugger/WebSocket.cpp @@ -52,6 +52,7 @@ #include "Core/Debugger/WebSocket/CPUCoreSubscriber.h" #include "Core/Debugger/WebSocket/DisasmSubscriber.h" #include "Core/Debugger/WebSocket/GameSubscriber.h" +#include "Core/Debugger/WebSocket/HLESubscriber.h" #include "Core/Debugger/WebSocket/SteppingSubscriber.h" typedef void *(*SubscriberInit)(DebuggerEventHandlerMap &map); @@ -66,6 +67,7 @@ static const std::vector subscribers({ { &WebSocketCPUCoreInit, nullptr }, { &WebSocketDisasmInit, &WebSocketDisasmShutdown }, { &WebSocketGameInit, nullptr }, + { &WebSocketHLEInit, nullptr }, { &WebSocketSteppingInit, &WebSocketSteppingShutdown }, }); diff --git a/Core/Debugger/WebSocket/HLESubscriber.cpp b/Core/Debugger/WebSocket/HLESubscriber.cpp new file mode 100644 index 0000000000..efb82c3b36 --- /dev/null +++ b/Core/Debugger/WebSocket/HLESubscriber.cpp @@ -0,0 +1,103 @@ +// Copyright (c) 2018- PPSSPP Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0 or later versions. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official git repository and contact information can be found at +// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. + +#include "Core/Debugger/SymbolMap.h" +#include "Core/Debugger/WebSocket/HLESubscriber.h" +#include "Core/Debugger/WebSocket/WebSocketUtils.h" +#include "Core/HLE/sceKernelThread.h" + +void *WebSocketHLEInit(DebuggerEventHandlerMap &map) { + map["hle.thread.list"] = &WebSocketHLEThreadList; + map["hle.func.list"] = &WebSocketHLEFuncList; + map["hle.module.list"] = &WebSocketHLEModuleList; + + return nullptr; +} + +void WebSocketHLEThreadList(DebuggerRequest &req) { + // Will just return none of the CPU isn't ready yet. + auto threads = GetThreadsInfo(); + + JsonWriter &json = req.Respond(); + json.pushArray("threads"); + for (auto th : threads) { + json.pushDict(); + json.writeUint("id", th.id); + json.writeString("name", th.name); + json.writeInt("status", th.status); + json.pushArray("statuses"); + if (th.status & THREADSTATUS_RUNNING) + json.writeString("running"); + if (th.status & THREADSTATUS_READY) + json.writeString("ready"); + if (th.status & THREADSTATUS_WAIT) + json.writeString("wait"); + if (th.status & THREADSTATUS_SUSPEND) + json.writeString("suspend"); + if (th.status & THREADSTATUS_DORMANT) + json.writeString("dormant"); + if (th.status & THREADSTATUS_DEAD) + json.writeString("dead"); + json.pop(); + json.writeUint("pc", th.curPC); + json.writeUint("entry", th.entrypoint); + json.writeUint("initialStackSize", th.initialStack); + json.writeUint("currentStackSize", th.stackSize); + json.writeInt("priority", th.priority); + json.writeInt("priority", (int)th.waitType); + json.writeBool("isCurrent", th.isCurrent); + json.pop(); + } + json.pop(); +} + +void WebSocketHLEFuncList(DebuggerRequest &req) { + if (!g_symbolMap) + return req.Fail("CPU not active"); + + auto functions = g_symbolMap->GetAllSymbols(ST_FUNCTION); + + JsonWriter &json = req.Respond(); + json.pushArray("functions"); + for (auto f : functions) { + json.pushDict(); + json.writeString("name", f.name); + json.writeUint("address", f.address); + json.writeUint("size", f.size); + json.pop(); + } + json.pop(); +} + +void WebSocketHLEModuleList(DebuggerRequest &req) { + if (!g_symbolMap) + return req.Fail("CPU not active"); + + auto modules = g_symbolMap->getAllModules(); + + JsonWriter &json = req.Respond(); + json.pushArray("functions"); + for (auto m : modules) { + json.pushDict(); + json.writeString("name", m.name); + json.writeUint("address", m.address); + json.writeUint("size", m.size); + json.writeBool("isActive", m.active); + json.pop(); + } + json.pop(); +} diff --git a/Core/Debugger/WebSocket/HLESubscriber.h b/Core/Debugger/WebSocket/HLESubscriber.h new file mode 100644 index 0000000000..61af4dc80d --- /dev/null +++ b/Core/Debugger/WebSocket/HLESubscriber.h @@ -0,0 +1,26 @@ +// Copyright (c) 2018- PPSSPP Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0 or later versions. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official git repository and contact information can be found at +// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. + +#pragma once + +#include "Core/Debugger/WebSocket/WebSocketUtils.h" + +void *WebSocketHLEInit(DebuggerEventHandlerMap &map); + +void WebSocketHLEThreadList(DebuggerRequest &req); +void WebSocketHLEFuncList(DebuggerRequest &req); +void WebSocketHLEModuleList(DebuggerRequest &req); diff --git a/Core/HLE/sceKernelThread.cpp b/Core/HLE/sceKernelThread.cpp index 11d246576e..576c3f1182 100644 --- a/Core/HLE/sceKernelThread.cpp +++ b/Core/HLE/sceKernelThread.cpp @@ -15,10 +15,11 @@ // Official git repository and contact information can be found at // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. -#include -#include -#include #include +#include +#include +#include +#include #include "base/logging.h" @@ -647,6 +648,8 @@ static std::vector pendingDeleteThreads; // Lists all thread ids that aren't deleted/etc. std::vector threadqueue; +// Only for debugger, so not needed to read, just write. +std::mutex threadqueueLock; // Lists only ready thread ids. ThreadQueueList threadReadyQueue; @@ -1154,8 +1157,9 @@ void __KernelIdle() __KernelReSchedule("idle"); } -void __KernelThreadingShutdown() -{ +void __KernelThreadingShutdown() { + std::lock_guard guard(threadqueueLock); + kernelMemory.Free(threadReturnHackAddr); threadqueue.clear(); threadReadyQueue.clear(); @@ -1590,8 +1594,9 @@ void __KernelCancelThreadEndTimeout(SceUID threadID) CoreTiming::UnscheduleEvent(eventThreadEndTimeout, threadID); } -static void __KernelRemoveFromThreadQueue(SceUID threadID) -{ +static void __KernelRemoveFromThreadQueue(SceUID threadID) { + std::lock_guard guard(threadqueueLock); + int prio = __KernelGetThreadPrio(threadID); if (prio != 0) threadReadyQueue.remove(prio, threadID); @@ -1850,8 +1855,9 @@ void __KernelResetThread(Thread *t, int lowestPriority) ERROR_LOG_REPORT(SCEKERNEL, "Resetting thread with threads waiting on end?"); } -Thread *__KernelCreateThread(SceUID &id, SceUID moduleId, const char *name, u32 entryPoint, u32 priority, int stacksize, u32 attr) -{ +Thread *__KernelCreateThread(SceUID &id, SceUID moduleId, const char *name, u32 entryPoint, u32 priority, int stacksize, u32 attr) { + std::lock_guard guard(threadqueueLock); + Thread *t = new Thread; id = kernelObjects.Create(t); @@ -3508,8 +3514,8 @@ void __KernelRegisterWaitTypeFuncs(WaitType type, WaitBeginCallbackFunc beginFun waitTypeFuncs[type].endFunc = endFunc; } -std::vector GetThreadsInfo() -{ +std::vector GetThreadsInfo() { + std::lock_guard guard(threadqueueLock); std::vector threadList; u32 error; diff --git a/android/jni/Android.mk b/android/jni/Android.mk index b08ade3a28..4501775884 100644 --- a/android/jni/Android.mk +++ b/android/jni/Android.mk @@ -307,6 +307,7 @@ EXEC_AND_LIB_FILES := \ $(SRC)/Core/Debugger/WebSocket/DisasmSubscriber.cpp \ $(SRC)/Core/Debugger/WebSocket/GameBroadcaster.cpp \ $(SRC)/Core/Debugger/WebSocket/GameSubscriber.cpp \ + $(SRC)/Core/Debugger/WebSocket/HLESubscriber.cpp \ $(SRC)/Core/Debugger/WebSocket/LogBroadcaster.cpp \ $(SRC)/Core/Debugger/WebSocket/SteppingBroadcaster.cpp \ $(SRC)/Core/Debugger/WebSocket/SteppingSubscriber.cpp \