Skip to content

Commit

Permalink
Debugger: Cleanup, add initial API docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
unknownbrackets committed Apr 15, 2018
1 parent 6a3c12a commit 6ba4668
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 10 deletions.
55 changes: 50 additions & 5 deletions Core/Debugger/WebSocket/CPUCoreSubscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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) {
Expand All @@ -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));
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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));
}
8 changes: 4 additions & 4 deletions Core/Debugger/WebSocket/GameBroadcaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion Core/Debugger/WebSocket/SteppingBroadcaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 6ba4668

Please sign in to comment.