Debugger: Add reason to cpu.stepping event.

This commit is contained in:
Unknown W. Brackets 2021-10-23 17:22:09 -07:00
parent 2bd13c5d9d
commit fc2efe5dff
3 changed files with 21 additions and 1 deletions

View file

@ -392,6 +392,13 @@ int Core_GetSteppingCounter() {
return steppingCounter;
}
SteppingReason Core_GetSteppingReason() {
SteppingReason r;
r.reason = steppingReason;
r.relatedAddress = steppingAddress;
return r;
}
const char *ExceptionTypeAsString(ExceptionType type) {
switch (type) {
case ExceptionType::MEMORY: return "Invalid Memory Access";

View file

@ -41,6 +41,11 @@ void Core_UpdateSingleStep();
void Core_ProcessStepping();
// Changes every time we enter stepping.
int Core_GetSteppingCounter();
struct SteppingReason {
const char *reason = nullptr;
u32 relatedAddress = 0;
};
SteppingReason Core_GetSteppingReason();
enum class CoreLifecycle {
STARTING,

View file

@ -23,6 +23,9 @@
#include "Core/System.h"
struct CPUSteppingEvent {
CPUSteppingEvent(const SteppingReason &reason) : reason_(reason) {
}
operator std::string() {
JsonWriter j;
j.begin();
@ -30,9 +33,14 @@ struct CPUSteppingEvent {
j.writeUint("pc", currentMIPS->pc);
// A double ought to be good enough for a 156 day debug session.
j.writeFloat("ticks", CoreTiming::GetTicks());
j.writeString("reason", reason_.reason);
j.writeUint("relatedAddress", reason_.relatedAddress);
j.end();
return j.str();
}
private:
const SteppingReason &reason_;
};
// CPU has begun stepping (cpu.stepping)
@ -49,7 +57,7 @@ void SteppingBroadcaster::Broadcast(net::WebSocketServer *ws) {
int steppingCounter = Core_GetSteppingCounter();
// We ignore CORE_POWERDOWN as a stepping state.
if (coreState == CORE_STEPPING && steppingCounter != lastCounter_) {
ws->Send(CPUSteppingEvent());
ws->Send(CPUSteppingEvent(Core_GetSteppingReason()));
} else if (prevState_ == CORE_STEPPING && coreState != CORE_STEPPING && Core_IsActive()) {
ws->Send(R"({"event":"cpu.resume"})");
}