mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Debugger: Reorganize state handling.
Looking like this will be needed for disasm caches, etc.
This commit is contained in:
parent
0a21063525
commit
a4044fd6a0
4 changed files with 40 additions and 8 deletions
|
@ -42,11 +42,15 @@
|
|||
|
||||
#include "Core/Debugger/WebSocket/CPUCoreSubscriber.h"
|
||||
|
||||
typedef void (*DebuggerEventHandler)(DebuggerRequest &req);
|
||||
static const std::unordered_map<std::string, DebuggerEventHandler> debuggerEvents({
|
||||
{"cpu.getAllRegs", &WebSocketCPUGetAllRegs},
|
||||
{"cpu.getReg", &WebSocketCPUGetReg},
|
||||
{"cpu.setReg", &WebSocketCPUSetReg},
|
||||
typedef void *(*SubscriberInit)(DebuggerEventHandlerMap &map);
|
||||
typedef void (*Subscribershutdown)(void *p);
|
||||
struct SubscriberInfo {
|
||||
SubscriberInit init;
|
||||
Subscribershutdown shutdown;
|
||||
};
|
||||
|
||||
static const std::vector<SubscriberInfo> subscribers({
|
||||
{ &WebSocketCPUCoreInit, nullptr },
|
||||
});
|
||||
|
||||
void HandleDebuggerRequest(const http::Request &request) {
|
||||
|
@ -58,6 +62,12 @@ void HandleDebuggerRequest(const http::Request &request) {
|
|||
GameBroadcaster game;
|
||||
SteppingBroadcaster stepping;
|
||||
|
||||
std::unordered_map<std::string, DebuggerEventHandler> eventHandlers;
|
||||
std::vector<void *> subscriberData;
|
||||
for (auto info : subscribers) {
|
||||
subscriberData.push_back(info.init(eventHandlers));
|
||||
}
|
||||
|
||||
ws->SetTextHandler([&](const std::string &t) {
|
||||
JsonReader reader(t.c_str(), t.size());
|
||||
if (!reader.ok()) {
|
||||
|
@ -73,8 +83,8 @@ void HandleDebuggerRequest(const http::Request &request) {
|
|||
}
|
||||
|
||||
DebuggerRequest req(event, ws, root);
|
||||
auto eventFunc = debuggerEvents.find(event);
|
||||
if (eventFunc != debuggerEvents.end()) {
|
||||
auto eventFunc = eventHandlers.find(event);
|
||||
if (eventFunc != eventHandlers.end()) {
|
||||
eventFunc->second(req);
|
||||
req.Finish();
|
||||
} else {
|
||||
|
@ -92,5 +102,13 @@ void HandleDebuggerRequest(const http::Request &request) {
|
|||
stepping.Broadcast(ws);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < subscribers.size(); ++i) {
|
||||
if (subscribers[i].shutdown) {
|
||||
subscribers[i].shutdown(subscriberData[i]);
|
||||
} else {
|
||||
assert(!subscriberData[i]);
|
||||
}
|
||||
}
|
||||
|
||||
delete ws;
|
||||
}
|
||||
|
|
|
@ -22,6 +22,15 @@
|
|||
#include "Core/MIPS/MIPS.h"
|
||||
#include "Core/MIPS/MIPSDebugInterface.h"
|
||||
|
||||
void *WebSocketCPUCoreInit(DebuggerEventHandlerMap &map) {
|
||||
// No need to bind or alloc state, these are all global.
|
||||
map["cpu.getAllRegs"] = &WebSocketCPUGetAllRegs;
|
||||
map["cpu.getReg"] = &WebSocketCPUGetReg;
|
||||
map["cpu.setReg"] = &WebSocketCPUSetReg;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static std::string RegValueAsFloat(uint32_t u) {
|
||||
union {
|
||||
uint32_t u;
|
||||
|
|
|
@ -17,7 +17,9 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
struct DebuggerRequest;
|
||||
#include "Core/Debugger/WebSocket/WebSocketUtils.h"
|
||||
|
||||
void *WebSocketCPUCoreInit(DebuggerEventHandlerMap &map);
|
||||
|
||||
void WebSocketCPUGetAllRegs(DebuggerRequest &req);
|
||||
void WebSocketCPUGetReg(DebuggerRequest &req);
|
||||
|
|
|
@ -84,3 +84,6 @@ private:
|
|||
bool responseBegun_ = false;
|
||||
bool responseSent_ = false;
|
||||
};
|
||||
|
||||
typedef std::function<void(DebuggerRequest &req)> DebuggerEventHandler;
|
||||
typedef std::unordered_map<std::string, DebuggerEventHandler> DebuggerEventHandlerMap;
|
||||
|
|
Loading…
Add table
Reference in a new issue