Skip to content

Commit

Permalink
MipsStackWalk: Detect leaf functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziemas authored and refractionpcsx2 committed Oct 26, 2023
1 parent 715bc94 commit e1bfd95
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion pcsx2/DebugTools/MipsStackWalk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit e1bfd95

Please sign in to comment.