CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/Core/Debugger/WebSocket/SteppingBroadcaster.cpp
Views: 1401
// 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());35j.writeString("reason", reason_.reason);36j.writeUint("relatedAddress", reason_.relatedAddress);37j.end();38return j.str();39}4041private:42const SteppingReason &reason_;43};4445// CPU has begun stepping (cpu.stepping)46//47// Sent unexpectedly with these properties:48// - pc: number value of PC register (inaccurate unless stepping.)49// - ticks: number of CPU cycles into emulation.50// - reason: a value submitted to Core_EnableStepping ("jit.branchdebug", "savestate.load", "ui.lost_focus", etc.)51// - relatedAddress: an address (often zero, but it can be a value of PC saved at some point, a related memory address, etc.)5253// CPU has resumed from stepping (cpu.resume)54//55// Sent unexpectedly with no other properties.56void SteppingBroadcaster::Broadcast(net::WebSocketServer *ws) {57if (PSP_IsInited()) {58int steppingCounter = Core_GetSteppingCounter();59// We ignore CORE_POWERDOWN as a stepping state.60if (coreState == CORE_STEPPING && steppingCounter != lastCounter_) {61ws->Send(CPUSteppingEvent(Core_GetSteppingReason()));62} else if (prevState_ == CORE_STEPPING && coreState != CORE_STEPPING && Core_IsActive()) {63ws->Send(R"({"event":"cpu.resume"})");64}65lastCounter_ = steppingCounter;66prevState_ = coreState;67} else {68lastCounter_ = -1;69prevState_ = CORE_POWERDOWN;70}71}727374