Skip to content

Commit

Permalink
UI: Show return address for exec crashes.
Browse files Browse the repository at this point in the history
  • Loading branch information
unknownbrackets committed Aug 21, 2022
1 parent 80e481b commit 8e7847f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
7 changes: 5 additions & 2 deletions Core/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion Core/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Core/MIPS/IR/IRInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion Core/MIPS/MIPSInt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ namespace MIPSInt
void Int_Break(MIPSOpcode op)
{
Reporting::ReportMessage("BREAK instruction hit");
Core_Break();
Core_Break(PC);
PC += 4;
}

Expand Down
17 changes: 13 additions & 4 deletions UI/EmuScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 8e7847f

Please sign in to comment.