Path: blob/master/Core/Debugger/WebSocket/SteppingBroadcaster.cpp
3187 views
// Copyright (c) 2018- PPSSPP Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official git repository and contact information can be found at15// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.1617#include "Core/Core.h"18#include "Core/CoreTiming.h"19#include "Core/Debugger/WebSocket/SteppingBroadcaster.h"20#include "Core/Debugger/WebSocket/WebSocketUtils.h"21#include "Core/MIPS/MIPS.h"22#include "Core/System.h"2324struct CPUSteppingEvent {25CPUSteppingEvent(const SteppingReason &reason) : reason_(reason) {26}2728operator std::string() {29JsonWriter j;30j.begin();31j.writeString("event", "cpu.stepping");32j.writeUint("pc", currentMIPS->pc);33// A double ought to be good enough for a 156 day debug session.34j.writeFloat("ticks", CoreTiming::GetTicks());35if (reason_.reason != BreakReason::None) {36j.writeString("reason", BreakReasonToString(reason_.reason));37j.writeUint("relatedAddress", reason_.relatedAddress);38}39j.end();40return j.str();41}4243private:44const SteppingReason &reason_;45};4647// CPU has begun stepping (cpu.stepping)48//49// Sent unexpectedly with these properties:50// - pc: number value of PC register (inaccurate unless stepping.)51// - ticks: number of CPU cycles into emulation.52// - reason: a value submitted to Core_EnableStepping ("jit.branchdebug", "savestate.load", "ui.lost_focus", etc.)53// - relatedAddress: an address (often zero, but it can be a value of PC saved at some point, a related memory address, etc.)5455// CPU has resumed from stepping (cpu.resume)56//57// Sent unexpectedly with no other properties.58void SteppingBroadcaster::Broadcast(net::WebSocketServer *ws) {59if (PSP_GetBootState() == BootState::Complete) {60int steppingCounter = Core_GetSteppingCounter();61// We ignore CORE_POWERDOWN as a stepping state.62if (coreState == CORE_STEPPING_CPU && steppingCounter != lastCounter_) {63ws->Send(CPUSteppingEvent(Core_GetSteppingReason()));64} else if (prevState_ == CORE_STEPPING_CPU && coreState != CORE_STEPPING_CPU && Core_IsActive()) {65ws->Send(R"({"event":"cpu.resume"})");66}67lastCounter_ = steppingCounter;68prevState_ = coreState;69} else {70lastCounter_ = -1;71prevState_ = CORE_POWERDOWN;72}73}747576