Fix crash due to null break reason

This commit is contained in:
Henrik Rydgård 2024-11-12 11:25:35 +01:00
parent 0bf53e38f4
commit df104e7e31
3 changed files with 28 additions and 8 deletions

View File

@ -415,13 +415,18 @@ bool Core_Run(GraphicsContext *ctx) {
// Free-threaded (hm, possibly except tracing).
void Core_Break(const char *reason, u32 relatedAddress) {
// Stop the tracer
mipsTracer.stop_tracing();
{
std::lock_guard<std::mutex> lock(g_stepMutex);
if (!g_stepCommand.empty()) {
// Already broke.
ERROR_LOG(Log::CPU, "Core_Break called with a break already in progress: %s", g_stepCommand.reason);
return;
}
mipsTracer.stop_tracing();
g_stepCommand.reason = reason;
g_stepCommand.relatedAddr = relatedAddress;
steppingCounter++;
_assert_msg_(reason != nullptr, "No reason specified for break");
Core_UpdateState(CORE_STEPPING);
}
System_Notify(SystemNotification::DEBUG_MODE_CHANGE);

View File

@ -33,8 +33,10 @@ 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);
if (reason_.reason) {
j.writeString("reason", reason_.reason);
j.writeUint("relatedAddress", reason_.relatedAddress);
}
j.end();
return j.str();
}

View File

@ -17,6 +17,7 @@
#include <thread>
#include "Core/Core.h"
#include "Common/Data/Encoding/Utf8.h"
#include "Common/Thread/ThreadUtil.h"
#include "Common/System/Request.h"
@ -324,7 +325,11 @@ bool Load_PSP_ISO(FileLoader *fileLoader, std::string *error_string) {
// TODO: We can't use the initial error_string pointer.
bool success = __KernelLoadExec(bootpath.c_str(), 0, &PSP_CoreParameter().errorString);
if (success && coreState == CORE_POWERUP) {
coreState = PSP_CoreParameter().startBreak ? CORE_STEPPING : CORE_RUNNING;
if (PSP_CoreParameter().startBreak) {
Core_Break("start-break");
} else {
coreState = CORE_RUNNING;
}
} else {
coreState = CORE_BOOT_ERROR;
// TODO: This is a crummy way to communicate the error...
@ -483,7 +488,11 @@ bool Load_PSP_ELF_PBP(FileLoader *fileLoader, std::string *error_string) {
bool success = __KernelLoadExec(finalName.c_str(), 0, &PSP_CoreParameter().errorString);
if (success && coreState == CORE_POWERUP) {
coreState = PSP_CoreParameter().startBreak ? CORE_STEPPING : CORE_RUNNING;
if (PSP_CoreParameter().startBreak) {
Core_Break("start-break");
} else {
coreState = CORE_RUNNING;
}
} else {
coreState = CORE_BOOT_ERROR;
// TODO: This is a crummy way to communicate the error...
@ -509,7 +518,11 @@ bool Load_PSP_GE_Dump(FileLoader *fileLoader, std::string *error_string) {
bool success = __KernelLoadGEDump("disc0:/data.ppdmp", &PSP_CoreParameter().errorString);
if (success && coreState == CORE_POWERUP) {
coreState = PSP_CoreParameter().startBreak ? CORE_STEPPING : CORE_RUNNING;
if (PSP_CoreParameter().startBreak) {
Core_Break("start-break");
} else {
coreState = CORE_RUNNING;
}
} else {
coreState = CORE_BOOT_ERROR;
// TODO: This is a crummy way to communicate the error...