mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-12-02 02:33:43 +01:00
Add GPR write breakpoints (break when a register is written, anywhere)
New debugging primitive: break whenever any instruction writes to a
given general-purpose register (0-31), regardless of which address
executes the write. Requested for continuing the reboot.bin trace,
where the actual blocker is "what sets $s3 to this bad value", not
"what happens at a specific address" - existing address/memory
breakpoints can't express that directly.
- GPRBreakpoint (Core/Debugger/Breakpoints.h) mirrors the existing
BreakPoint/MemCheck shape (result/condition/logFormat/hit count),
keyed by register index instead of address/range.
- BreakpointManager keeps a u32 bitmask (bit i = register i has an
active breakpoint) alongside the GPRBreakpoint vector, so the
interpreter loop can test "would this write trip anything" with a
single shift+and against a value already cached in a local.
- RunUntilDowncountZeroWithChecks (Core/MIPS/MIPSTables.cpp) computes
the about-to-be-written register from the current instruction's
OUT_RT/OUT_RD/OUT_RA flags (GetGPRWriteTarget()) and checks it
against the mask, same convention as the existing memcheck handling
right above it (checked before the instruction executes, bails via
CORE_STEPPING_CPU without running it if tripped).
- New BreakReason::GPRBreakpoint ("cpu.gprBreakpoint") for Core_Break.
- WebSocket API: cpu.gprBreakpoint.add/update/remove/list, accepting
either a 0-31 'register' index or a case-insensitive 'name' (e.g.
"s3"), documented in docs/WebSocketDebugger.md.
Interpreter-only for now, deliberately.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GZq8ZtJmFY7bkX5FVkr3P9
This commit is contained in:
1 parent
3f6743d40d
commit
75174af77b
8 files changed
+500
-2
No files matched your search
@@ -1142,9 +1142,24 @@ static void RunUntilDowncountZeroFast(MIPSState *mips) {
|
||||
}
|
||||
|
||||
#define _RS(op) ((op>>21) & 0x1F)
|
||||
// Returns the 0-31 GPR index an instruction is about to write, or -1 if it doesn't write a GPR.
|
||||
// OUT_RA is always $ra (31) - jal/bltzal/bgezal/etc. have no encoded destination register field,
|
||||
// unlike jalr (which uses OUT_RD, since its destination is chosen via the rd field).
|
||||
static inline int GetGPRWriteTarget(const MIPSInstruction *instr, MIPSOpcode op) {
|
||||
if (instr->flags & OUT_RT)
|
||||
return (op >> 16) & 0x1F;
|
||||
if (instr->flags & OUT_RD)
|
||||
return (op >> 11) & 0x1F;
|
||||
if (instr->flags & OUT_RA)
|
||||
return 31;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void RunUntilDowncountZeroWithChecks(MIPSState *mips, u64 globalTicks) {
|
||||
bool hasBPs = g_breakpoints.HasBreakPoints();
|
||||
bool hasMCs = g_breakpoints.HasMemChecks();
|
||||
// Bit i set means register i has an active GPR breakpoint - see GetGPRBreakpointMask().
|
||||
u32 gprBPMask = g_breakpoints.GetGPRBreakpointMask();
|
||||
while (mips->downcount >= 0 && coreState == CORE_RUNNING_CPU) {
|
||||
// Don't stop in a delay slot! Well, unless we hit a memcheck in one, of course.
|
||||
do {
|
||||
@@ -1181,6 +1196,15 @@ static void RunUntilDowncountZeroWithChecks(MIPSState *mips, u64 globalTicks) {
|
||||
if (coreState == CORE_STEPPING_CPU)
|
||||
break;
|
||||
}
|
||||
if (gprBPMask != 0 && (instr->flags & (OUT_RT | OUT_RD | OUT_RA)) != 0 && g_breakpoints.CheckSkipFirst() != mips->pc) {
|
||||
int gprTarget = GetGPRWriteTarget(instr, op);
|
||||
if (gprTarget >= 0 && (gprBPMask & (1u << gprTarget)) != 0) {
|
||||
g_breakpoints.ExecGPRBreakpoint(gprTarget, mips->pc);
|
||||
// If it tripped, bail without running - same convention as memchecks above.
|
||||
if (coreState == CORE_STEPPING_CPU)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool wasInDelaySlot = mips->inDelaySlot;
|
||||
Interpret(mips, instr, op);
|
||||
@@ -1204,7 +1228,7 @@ int MIPSInterpret_RunUntil(MIPSState *mips, u64 globalTicks) {
|
||||
CoreTiming::Advance(mips);
|
||||
|
||||
uint64_t ticksLeft = globalTicks - CoreTiming::GetTicks(mips);
|
||||
if (g_breakpoints.HasBreakPoints() || g_breakpoints.HasMemChecks() || ticksLeft <= mips->downcount) {
|
||||
if (g_breakpoints.HasBreakPoints() || g_breakpoints.HasMemChecks() || g_breakpoints.HasGPRBreakpoints() || ticksLeft <= mips->downcount) {
|
||||
RunUntilDowncountZeroWithChecks(mips, globalTicks);
|
||||
} else {
|
||||
RunUntilDowncountZeroFast(mips);
|
||||
|
||||
Reference in new issue
Block a user