From 8e7847f6d959e25b7cda3ebe9289c85594a44215 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 21 Aug 2022 14:09:52 -0700 Subject: [PATCH] UI: Show return address for exec crashes. --- Core/Core.cpp | 7 +++++-- Core/Core.h | 3 ++- Core/MIPS/IR/IRInterpreter.cpp | 2 +- Core/MIPS/MIPSInt.cpp | 2 +- UI/EmuScreen.cpp | 17 +++++++++++++---- 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/Core/Core.cpp b/Core/Core.cpp index e723107d3034..52a1df8f4c1a 100644 --- a/Core/Core.cpp +++ b/Core/Core.cpp @@ -487,16 +487,19 @@ void Core_ExecException(u32 address, u32 pc, ExecExceptionType type) { e.exec_type = type; e.address = address; e.pc = pc; - Core_EnableStepping(true, "cpu.exception", pc); + // This just records the closest value that could be useful as reference. + e.ra = currentMIPS->r[MIPS_REG_RA]; + Core_EnableStepping(true, "cpu.exception", address); } -void Core_Break() { +void Core_Break(u32 pc) { ERROR_LOG(CPU, "BREAK!"); ExceptionInfo &e = g_exceptionInfo; e = {}; e.type = ExceptionType::BREAK; e.info = ""; + e.pc = pc; if (!g_Config.bIgnoreBadMemAccess) { Core_EnableStepping(true, "cpu.breakInstruction", currentMIPS->pc); diff --git a/Core/Core.h b/Core/Core.h index 894accd6aeed..d706e7afec78 100644 --- a/Core/Core.h +++ b/Core/Core.h @@ -106,7 +106,7 @@ void Core_MemoryException(u32 address, u32 pc, MemoryExceptionType type); void Core_MemoryExceptionInfo(u32 address, u32 pc, MemoryExceptionType type, std::string additionalInfo); void Core_ExecException(u32 address, u32 pc, ExecExceptionType type); -void Core_Break(); +void Core_Break(u32 pc); // Call when loading save states, etc. void Core_ResetException(); @@ -125,6 +125,7 @@ struct ExceptionInfo { MemoryExceptionType memory_type; uint32_t pc; uint32_t address; + uint32_t ra = 0; // Reuses pc and address from memory type, where address is the failed destination. ExecExceptionType exec_type; diff --git a/Core/MIPS/IR/IRInterpreter.cpp b/Core/MIPS/IR/IRInterpreter.cpp index bc97b52b732a..27b0ba0ca328 100644 --- a/Core/MIPS/IR/IRInterpreter.cpp +++ b/Core/MIPS/IR/IRInterpreter.cpp @@ -998,7 +998,7 @@ u32 IRInterpret(MIPSState *mips, const IRInst *inst, int count) { } case IROp::Break: - Core_Break(); + Core_Break(mips->pc); return mips->pc + 4; case IROp::SetCtrlVFPU: diff --git a/Core/MIPS/MIPSInt.cpp b/Core/MIPS/MIPSInt.cpp index 99cad4df3e62..46585b69a9ca 100644 --- a/Core/MIPS/MIPSInt.cpp +++ b/Core/MIPS/MIPSInt.cpp @@ -157,7 +157,7 @@ namespace MIPSInt void Int_Break(MIPSOpcode op) { Reporting::ReportMessage("BREAK instruction hit"); - Core_Break(); + Core_Break(PC); PC += 4; } diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index aa0857646704..1b98b91bb8d6 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -1209,16 +1209,25 @@ PC: %08x } else if (info.type == ExceptionType::BAD_EXEC_ADDR) { snprintf(statbuf, sizeof(statbuf), R"( Destination: %s to %08x -PC: %08x)", +PC: %08x +RA: %08x)", ExecExceptionTypeAsString(info.exec_type), info.address, - info.pc); + info.pc, + info.ra); ctx->Draw()->DrawTextShadow(ubuntu24, statbuf, x, y, 0xFFFFFFFF); y += 180; - } else { + } else if (info.type == ExceptionType::BREAK) { snprintf(statbuf, sizeof(statbuf), R"( BREAK -)"); +PC: %08x +)", info.pc); + ctx->Draw()->DrawTextShadow(ubuntu24, statbuf, x, y, 0xFFFFFFFF); + y += 180; + } else { + snprintf(statbuf, sizeof(statbuf), R"( +Invalid / Unknown (%d) +)", (int)info.type); ctx->Draw()->DrawTextShadow(ubuntu24, statbuf, x, y, 0xFFFFFFFF); y += 180; }