From 1dbb5422a2ceba4c5738ce4e60ba5c3b055fa68a Mon Sep 17 00:00:00 2001 From: Eladash Date: Thu, 19 Mar 2020 12:29:50 +0200 Subject: [PATCH] Avoid a segfault when reading ppu stack contents in debuggers TODO: lock vm mutex. --- rpcs3/Emu/Cell/PPUThread.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/rpcs3/Emu/Cell/PPUThread.cpp b/rpcs3/Emu/Cell/PPUThread.cpp index e378991d2a..aaa701b18e 100644 --- a/rpcs3/Emu/Cell/PPUThread.cpp +++ b/rpcs3/Emu/Cell/PPUThread.cpp @@ -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(gpr[1]); + + if (!vm::check_addr(stack_ptr, 1, vm::page_writable)) + { + // Normally impossible unless the code does not follow ABI rules + return ret; + } + u32 stack_min = stack_ptr & ~0xfff; u32 stack_max = stack_min + 4096; @@ -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(sp))) + for (u64 sp = *vm::get_super_ptr(stack_ptr); sp >= stack_min && std::max(sp, sp + 0x200) < stack_max; sp = *vm::get_super_ptr(static_cast(sp))) { // TODO: print also function addresses - fmt::append(ret, "> from 0x%08llx (0x0)\n", vm::read64(static_cast(sp + 16))); + fmt::append(ret, "> from 0x%08llx (0x0)\n", *vm::get_super_ptr(static_cast(sp + 16))); } return ret;