From 6ba46688b450a99a6cb0fedef75775c3a3c3b7a1 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 15 Apr 2018 11:51:19 -0700 Subject: [PATCH] Debugger: Cleanup, add initial API docs. --- Core/Debugger/WebSocket/CPUCoreSubscriber.cpp | 55 +++++++++++++++++-- Core/Debugger/WebSocket/GameBroadcaster.cpp | 8 +-- .../WebSocket/SteppingBroadcaster.cpp | 2 +- 3 files changed, 55 insertions(+), 10 deletions(-) diff --git a/Core/Debugger/WebSocket/CPUCoreSubscriber.cpp b/Core/Debugger/WebSocket/CPUCoreSubscriber.cpp index c3ef6e6ff562..f2ef93b75e79 100644 --- a/Core/Debugger/WebSocket/CPUCoreSubscriber.cpp +++ b/Core/Debugger/WebSocket/CPUCoreSubscriber.cpp @@ -30,6 +30,17 @@ static std::string RegValueAsFloat(uint32_t u) { return StringFromFormat("%f", bits.f); } +// Retrieve all regs and their values (cpu.getAllRegs) +// +// No parameters. +// +// Response (same event name): +// - categories: array of objects: +// - id: "category" property to use for other events. +// - name: a category name, such as "GPR". +// - registerNames: array of string names of the registers (size varies per category.) +// - uintValues: array of unsigned integer values for the registers. +// - floatValues: array of strings showing float representation. May be "nan", "inf", or "-inf". void WebSocketCPUGetAllRegs(DebuggerRequest &req) { JsonWriter &json = req.Respond(); @@ -41,7 +52,7 @@ void WebSocketCPUGetAllRegs(DebuggerRequest &req) { int total = currentDebugMIPS->GetNumRegsInCategory(c); - json.pushArray("names"); + json.pushArray("registerNames"); for (int r = 0; r < total; ++r) json.writeString(currentDebugMIPS->GetRegName(c, r)); if (c == 0) { @@ -51,7 +62,7 @@ void WebSocketCPUGetAllRegs(DebuggerRequest &req) { } json.pop(); - json.pushArray("intValues"); + json.pushArray("uintValues"); // Writing as floating point to avoid negatives. Actually double, so safe. for (int r = 0; r < total; ++r) json.writeFloat(currentDebugMIPS->GetRegValue(c, r)); @@ -150,6 +161,20 @@ static DebuggerRegType ValidateCatReg(DebuggerRequest &req, int *cat, int *reg) return DebuggerRegType::NORMAL; } +// Retrieve the value of a single register (cpu.getReg) +// +// Parameters (by name): +// - name: string name of register to lookup. +// +// Parameters (by category id and index, ignored if name specified): +// - category: id of category for the register. +// - register: index into array of registers. +// +// Response (same event name): +// - category: id of category for the register. +// - register: index into array of registers. +// - uintValue: value in register. +// - floatValue: string showing float representation. May be "nan", "inf", or "-inf". void WebSocketCPUGetReg(DebuggerRequest &req) { int cat, reg; uint32_t val; @@ -176,16 +201,36 @@ void WebSocketCPUGetReg(DebuggerRequest &req) { JsonWriter &json = req.Respond(); json.writeInt("category", cat); json.writeInt("register", reg); - json.writeFloat("intValue", val); + json.writeFloat("uintValue", val); json.writeString("floatValue", RegValueAsFloat(val)); } +// Retrieve the value of a single register (cpu.getReg) +// +// Parameters (by name): +// - name: string name of register to lookup. +// - value: number (uint values only) or string to set to. Values may include +// "0x1234", "1.5", "nan", "-inf", etc. For a float, use a string with decimal e.g. "1.0". +// +// Parameters (by category id and index, ignored if name specified): +// - category: id of category for the register. +// - register: index into array of registers. +// - value: number (uint values only) or string to set to. Values may include +// "0x1234", "1.5", "nan", "-inf", etc. For a float, use a string with decimal e.g. "1.0". +// +// Response (same event name): +// - category: id of category for the register. +// - register: index into array of registers. +// - uintValue: new value in register. +// - floatValue: string showing float representation. May be "nan", "inf", or "-inf". +// +// NOTE: Cannot be called unless the CPU is currently stepping. void WebSocketCPUSetReg(DebuggerRequest &req) { if (!currentDebugMIPS->isAlive()) { return req.Fail("CPU not started"); } if (!Core_IsStepping()) { - return req.Fail("CPU currently running (cpu.interrupt first)"); + return req.Fail("CPU currently running (cpu.stepping first)"); } uint32_t val; @@ -219,6 +264,6 @@ void WebSocketCPUSetReg(DebuggerRequest &req) { // Repeat it back just to avoid confusion on how it parsed. json.writeInt("category", cat); json.writeInt("register", reg); - json.writeFloat("intValue", val); + json.writeFloat("uintValue", val); json.writeString("floatValue", RegValueAsFloat(val)); } diff --git a/Core/Debugger/WebSocket/GameBroadcaster.cpp b/Core/Debugger/WebSocket/GameBroadcaster.cpp index e1a9d2ae4e83..37a9e2c919cb 100644 --- a/Core/Debugger/WebSocket/GameBroadcaster.cpp +++ b/Core/Debugger/WebSocket/GameBroadcaster.cpp @@ -25,13 +25,13 @@ void GameBroadcaster::Broadcast(net::WebSocketServer *ws) { GlobalUIState state = GetUIState(); if (prevState_ != state) { if (state == UISTATE_PAUSEMENU) { - ws->Send(R"({"event":"game_pause"})"); + ws->Send(R"({"event":"game.pause"})"); } else if (state == UISTATE_INGAME && prevState_ == UISTATE_PAUSEMENU) { - ws->Send(R"({"event":"game_resume"})"); + ws->Send(R"({"event":"game.resume"})"); } else if (state == UISTATE_INGAME) { - ws->Send(R"({"event":"game_start"})"); + ws->Send(R"({"event":"game.start"})"); } else if (state == UISTATE_MENU) { - ws->Send(R"({"event":"game_quit"})"); + ws->Send(R"({"event":"game.quit"})"); } prevState_ = state; } diff --git a/Core/Debugger/WebSocket/SteppingBroadcaster.cpp b/Core/Debugger/WebSocket/SteppingBroadcaster.cpp index ca44bc06b44d..7be39bd7984b 100644 --- a/Core/Debugger/WebSocket/SteppingBroadcaster.cpp +++ b/Core/Debugger/WebSocket/SteppingBroadcaster.cpp @@ -25,7 +25,7 @@ void SteppingBroadcaster::Broadcast(net::WebSocketServer *ws) { if (coreState != prevState_) { if (Core_IsStepping() && PSP_IsInited()) { // TODO: Should send more data proactively. - ws->Send(R"({"event":"cpu_stepping"})"); + ws->Send(R"({"event":"cpu.stepping"})"); } prevState_ = coreState; }