From e1bfd95f637cd9abc890d1e2aee0173805a83b0c Mon Sep 17 00:00:00 2001 From: Ziemas Date: Tue, 24 Oct 2023 23:03:26 +0200 Subject: [PATCH] MipsStackWalk: Detect leaf functions. --- pcsx2/DebugTools/MipsStackWalk.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/pcsx2/DebugTools/MipsStackWalk.cpp b/pcsx2/DebugTools/MipsStackWalk.cpp index 6480c14c5b976..b87efbd0924c6 100644 --- a/pcsx2/DebugTools/MipsStackWalk.cpp +++ b/pcsx2/DebugTools/MipsStackWalk.cpp @@ -135,12 +135,27 @@ namespace MipsStackWalk u32 rawOp = cpu->read32(pc); const R5900::OPCODE& op = R5900::GetInstruction(rawOp); - // Here's where they store the ra address. + // Look for RA write to ram if (IsSWInstr(op) && _RT == MIPS_REG_RA && _RS == MIPS_REG_SP) { ra_offset = _IMM16; } + // Look for previous function end + if (IsJRInstr(op) && _RS == MIPS_REG_RA) + { + // Found previous function end + // Since no stack setup was found assume this is a leaf + // with no stack usage + pc = pc + 8; + + frame.entry = pc; + frame.stackSize = 0; + + return true; + } + + // Look for the frame allocation stack pointer subtraction if (IsAddImmInstr(op) && _RT == MIPS_REG_SP && _RS == MIPS_REG_SP) { // A positive imm either means alloca() or we went too far.