CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

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