Skip to content

Commit

Permalink
Avoid a segfault when reading ppu stack contents in debuggers
Browse files Browse the repository at this point in the history
TODO: lock vm mutex.
  • Loading branch information
elad335 committed Mar 19, 2020
1 parent e5eafb1 commit 857723c
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions rpcs3/Emu/Cell/PPUThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,17 @@ std::string ppu_thread::dump() const
fmt::append(ret, "FPSCR = [FL=%u | FG=%u | FE=%u | FU=%u]\n", fpscr.fl, fpscr.fg, fpscr.fe, fpscr.fu);
fmt::append(ret, "\nCall stack:\n=========\n0x%08x (0x0) called\n", cia);

//std::shared_lock rlock(vm::g_mutex); // Needs optimizations

// Determine stack range
u32 stack_ptr = static_cast<u32>(gpr[1]);

if (!vm::check_addr(stack_ptr))
{
// Normally impossible unless the code does not follow ABI rules
return ret;
}

u32 stack_min = stack_ptr & ~0xfff;
u32 stack_max = stack_min + 4096;

Expand All @@ -487,10 +496,10 @@ std::string ppu_thread::dump() const
stack_max += 4096;
}

for (u64 sp = vm::read64(stack_ptr); sp >= stack_min && std::max(sp, sp + 0x200) < stack_max; sp = vm::read64(static_cast<u32>(sp)))
for (u64 sp = *vm::get_super_ptr<u64>(stack_ptr); sp >= stack_min && std::max(sp, sp + 0x200) < stack_max; sp = *vm::get_super_ptr<u64>(static_cast<u32>(sp)))
{
// TODO: print also function addresses
fmt::append(ret, "> from 0x%08llx (0x0)\n", vm::read64(static_cast<u32>(sp + 16)));
fmt::append(ret, "> from 0x%08llx (0x0)\n", *vm::get_super_ptr<u64>(static_cast<u32>(sp + 16)));
}

return ret;
Expand Down

0 comments on commit 857723c

Please sign in to comment.