Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/Core/Debugger/WebSocket/SteppingBroadcaster.cpp
3187 views
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
if (reason_.reason != BreakReason::None) {
37
j.writeString("reason", BreakReasonToString(reason_.reason));
38
j.writeUint("relatedAddress", reason_.relatedAddress);
39
}
40
j.end();
41
return j.str();
42
}
43
44
private:
45
const SteppingReason &reason_;
46
};
47
48
// CPU has begun stepping (cpu.stepping)
49
//
50
// Sent unexpectedly with these properties:
51
// - pc: number value of PC register (inaccurate unless stepping.)
52
// - ticks: number of CPU cycles into emulation.
53
// - reason: a value submitted to Core_EnableStepping ("jit.branchdebug", "savestate.load", "ui.lost_focus", etc.)
54
// - relatedAddress: an address (often zero, but it can be a value of PC saved at some point, a related memory address, etc.)
55
56
// CPU has resumed from stepping (cpu.resume)
57
//
58
// Sent unexpectedly with no other properties.
59
void SteppingBroadcaster::Broadcast(net::WebSocketServer *ws) {
60
if (PSP_GetBootState() == BootState::Complete) {
61
int steppingCounter = Core_GetSteppingCounter();
62
// We ignore CORE_POWERDOWN as a stepping state.
63
if (coreState == CORE_STEPPING_CPU && steppingCounter != lastCounter_) {
64
ws->Send(CPUSteppingEvent(Core_GetSteppingReason()));
65
} else if (prevState_ == CORE_STEPPING_CPU && coreState != CORE_STEPPING_CPU && Core_IsActive()) {
66
ws->Send(R"({"event":"cpu.resume"})");
67
}
68
lastCounter_ = steppingCounter;
69
prevState_ = coreState;
70
} else {
71
lastCounter_ = -1;
72
prevState_ = CORE_POWERDOWN;
73
}
74
}
75
76