From 3ce7fd78941c6b3d9a4b7d570bd4c9e4e5d05eb3 Mon Sep 17 00:00:00 2001 From: Eladash Date: Fri, 21 Aug 2020 12:10:00 +0300 Subject: [PATCH] Debugger: Fix instructions editor --- rpcs3/Emu/Cell/PPUThread.cpp | 31 +++++++++++++++++++++++-------- rpcs3/rpcs3qt/debugger_frame.cpp | 3 +-- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/rpcs3/Emu/Cell/PPUThread.cpp b/rpcs3/Emu/Cell/PPUThread.cpp index de7ead2fbf..59b18a548b 100644 --- a/rpcs3/Emu/Cell/PPUThread.cpp +++ b/rpcs3/Emu/Cell/PPUThread.cpp @@ -333,25 +333,40 @@ extern void ppu_remove_breakpoint(u32 addr) extern bool ppu_patch(u32 addr, u32 value) { - if (g_cfg.core.ppu_decoder == ppu_decoder_type::llvm && Emu.GetStatus() != system_state::ready) + if (addr % 4) + { + ppu_log.fatal("Patch failed at 0x%x: unanligned memory address.", addr); + return false; + } + + vm::reader_lock rlock; + + if (!vm::check_addr(addr, sizeof(value))) + { + ppu_log.fatal("Patch failed at 0x%x: invalid memory address.", addr); + return false; + } + + const bool is_exec = vm::check_addr(addr, sizeof(value), vm::page_executable); + + if (is_exec && g_cfg.core.ppu_decoder == ppu_decoder_type::llvm && !Emu.IsReady()) { // TODO: support recompilers ppu_log.fatal("Patch failed at 0x%x: LLVM recompiler is used.", addr); return false; } - if (!vm::try_access(addr, &value, sizeof(value), true)) - { - ppu_log.fatal("Patch failed at 0x%x: invalid memory address.", addr); - return false; - } + *vm::get_super_ptr(addr) = value; const u32 _break = ::narrow(reinterpret_cast(&ppu_break)); const u32 fallback = ::narrow(reinterpret_cast(&ppu_fallback)); - if (ppu_ref(addr) != _break && ppu_ref(addr) != fallback) + if (is_exec) { - ppu_ref(addr) = ppu_cache(addr); + if (ppu_ref(addr) != _break && ppu_ref(addr) != fallback) + { + ppu_ref(addr) = ppu_cache(addr); + } } return true; diff --git a/rpcs3/rpcs3qt/debugger_frame.cpp b/rpcs3/rpcs3qt/debugger_frame.cpp index 88996b7f06..07f30d8108 100644 --- a/rpcs3/rpcs3qt/debugger_frame.cpp +++ b/rpcs3/rpcs3qt/debugger_frame.cpp @@ -232,8 +232,7 @@ void debugger_frame::keyPressEvent(QKeyEvent* event) return; } - const u32 start_pc = m_debugger_list->m_pc - m_debugger_list->m_item_count * 4; - const u32 pc = start_pc + i * 4; + const u32 pc = m_debugger_list->m_pc + i * 4; if (QApplication::keyboardModifiers() & Qt::ControlModifier) {