From f5791071f9a861b4efd8b821cbb9f04a0647c3f4 Mon Sep 17 00:00:00 2001 From: Eladash Date: Thu, 16 Apr 2020 21:16:40 +0300 Subject: [PATCH 1/5] debugger: Rephrase "Current function" to "In function" Takes less space which makes actual function name display a bit nicer. Also the meaning is clearer. --- rpcs3/Emu/Cell/PPUThread.cpp | 2 +- rpcs3/Emu/Cell/SPUThread.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rpcs3/Emu/Cell/PPUThread.cpp b/rpcs3/Emu/Cell/PPUThread.cpp index d3968ba20ad8..269bc7cd5ebd 100644 --- a/rpcs3/Emu/Cell/PPUThread.cpp +++ b/rpcs3/Emu/Cell/PPUThread.cpp @@ -504,7 +504,7 @@ std::string ppu_thread::dump_misc() const if (_func) { - ret += "Current function: "; + ret += "In function: "; ret += _func; ret += '\n'; diff --git a/rpcs3/Emu/Cell/SPUThread.cpp b/rpcs3/Emu/Cell/SPUThread.cpp index c15fcf29cbc3..7912ae598028 100644 --- a/rpcs3/Emu/Cell/SPUThread.cpp +++ b/rpcs3/Emu/Cell/SPUThread.cpp @@ -1056,7 +1056,7 @@ std::string spu_thread::dump_misc() const { if (const auto func = current_func) { - ret += "\nCurrent function: "; + ret += "\nIn function: "; ret += func; } else From 26ca30cee26bbbb1db7ae0c437eb2fd19f6e0d8f Mon Sep 17 00:00:00 2001 From: Eladash Date: Thu, 16 Apr 2020 21:35:11 +0300 Subject: [PATCH 2/5] PPU debugger: read 32-bit pointer instead of 64-bit PPU ABI supports only 32-bit pointers in userland, also fix it to use super ptr. --- rpcs3/Emu/Cell/PPUThread.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/rpcs3/Emu/Cell/PPUThread.cpp b/rpcs3/Emu/Cell/PPUThread.cpp index 269bc7cd5ebd..a971bede8fec 100644 --- a/rpcs3/Emu/Cell/PPUThread.cpp +++ b/rpcs3/Emu/Cell/PPUThread.cpp @@ -381,11 +381,10 @@ std::string ppu_thread::dump_regs() const const u32 max_str_len = 32; const u32 hex_count = 8; - if (reg <= UINT32_MAX && vm::check_addr(static_cast(reg), max_str_len, vm::page_readable)) + if (reg <= UINT32_MAX && vm::check_addr(static_cast(reg), max_str_len)) { - const u64 reg_ptr = vm::read64(reg); - - if (reg_ptr <= UINT32_MAX && vm::check_addr(static_cast(reg_ptr), max_str_len, vm::page_readable)) + if (const u32 reg_ptr = *vm::get_super_ptr(static_cast(reg)); + vm::check_addr(reg_ptr, max_str_len)) { reg = reg_ptr; } From 9d1be31dfe4d2ab6dbde1dd6f2c3237eba293be0 Mon Sep 17 00:00:00 2001 From: Eladash Date: Fri, 17 Apr 2020 09:15:30 +0300 Subject: [PATCH 3/5] PPU debugger: report functions on registers display --- rpcs3/Emu/Cell/PPUThread.cpp | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/rpcs3/Emu/Cell/PPUThread.cpp b/rpcs3/Emu/Cell/PPUThread.cpp index a971bede8fec..4a2108466c02 100644 --- a/rpcs3/Emu/Cell/PPUThread.cpp +++ b/rpcs3/Emu/Cell/PPUThread.cpp @@ -383,17 +383,45 @@ std::string ppu_thread::dump_regs() const if (reg <= UINT32_MAX && vm::check_addr(static_cast(reg), max_str_len)) { + bool is_function = false; + u32 toc = 0; + if (const u32 reg_ptr = *vm::get_super_ptr(static_cast(reg)); vm::check_addr(reg_ptr, max_str_len)) { + if ((reg | reg_ptr) % 4 == 0 && vm::check_addr(reg_ptr, 4, vm::page_executable)) + { + toc = *vm::get_super_ptr(static_cast(reg + 4)); + + if (toc % 4 == 0 && vm::check_addr(toc)) + { + is_function = true; + } + } + reg = reg_ptr; } + else if (reg % 4 == 0 && vm::check_addr(reg, 4, vm::page_executable)) + { + is_function = true; + } const auto gpr_buf = vm::get_super_ptr(reg); std::string buf_tmp(gpr_buf, gpr_buf + max_str_len); - if (std::isprint(static_cast(buf_tmp[0])) && std::isprint(static_cast(buf_tmp[1])) && std::isprint(static_cast(buf_tmp[2]))) + if (is_function) + { + if (toc) + { + fmt::append(ret, " -> func(at=0x%x, toc=0x%x)", reg, toc); + } + else + { + fmt::append(ret, " -> function-code"); + } + } + else if (std::isprint(static_cast(buf_tmp[0])) && std::isprint(static_cast(buf_tmp[1])) && std::isprint(static_cast(buf_tmp[2]))) { fmt::append(ret, " -> \"%s\"", buf_tmp.c_str()); } From c0403f10a532ebc997a628151f82c8d13920d809 Mon Sep 17 00:00:00 2001 From: Eladash Date: Fri, 17 Apr 2020 15:19:42 +0300 Subject: [PATCH 4/5] Minor fixup for unimplemented syscall args dump --- rpcs3/Emu/Cell/lv2/lv2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpcs3/Emu/Cell/lv2/lv2.cpp b/rpcs3/Emu/Cell/lv2/lv2.cpp index a83bd977db43..8301f4fa9251 100644 --- a/rpcs3/Emu/Cell/lv2/lv2.cpp +++ b/rpcs3/Emu/Cell/lv2/lv2.cpp @@ -56,7 +56,7 @@ void fmt_class_string::format(std::string& out, u64 arg) static bool null_func(ppu_thread& ppu) { - ppu_log.todo("Unimplemented syscall %s -> CELL_OK (r3=0x%llx, r4=0x%x, r5=0x%llx, r6=0x%llx, r7=0x%llx, r8=0x%llx, r9=0x%llx, r10=0x%llx)", ppu_syscall_code(ppu.gpr[11]), + ppu_log.todo("Unimplemented syscall %s -> CELL_OK (r3=0x%llx, r4=0x%llx, r5=0x%llx, r6=0x%llx, r7=0x%llx, r8=0x%llx, r9=0x%llx, r10=0x%llx)", ppu_syscall_code(ppu.gpr[11]), ppu.gpr[3], ppu.gpr[4], ppu.gpr[5], ppu.gpr[6], ppu.gpr[7], ppu.gpr[8], ppu.gpr[9], ppu.gpr[10]); ppu.gpr[3] = 0; From 0ee41b9e82504bda61ab9520b55b9e036f123d84 Mon Sep 17 00:00:00 2001 From: Eladash Date: Fri, 17 Apr 2020 16:45:13 +0300 Subject: [PATCH 5/5] PPUAnalyzer: Check if TOC from OPD is a valid address --- rpcs3/Emu/Cell/PPUAnalyser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpcs3/Emu/Cell/PPUAnalyser.cpp b/rpcs3/Emu/Cell/PPUAnalyser.cpp index 259d3aa72376..d3a674c57f93 100644 --- a/rpcs3/Emu/Cell/PPUAnalyser.cpp +++ b/rpcs3/Emu/Cell/PPUAnalyser.cpp @@ -664,7 +664,7 @@ void ppu_module::analyse(u32 lib_toc, u32 entry) const u32 _toc_end = _toc + 0x8000; // TODO: improve TOC constraints - if (_toc % 4 || _toc == 0 || _toc >= 0x40000000 || (_toc >= start && _toc < end)) + if (_toc % 4 || !vm::check_addr(_toc) || _toc >= 0x40000000 || (_toc >= start && _toc < end)) { sec_end.set(0); break;