From d388fe58f73411456572e4ca28526c926baac095 Mon Sep 17 00:00:00 2001 From: Dimitri ALBORA Date: Sat, 26 Jan 2019 22:08:39 +0100 Subject: [PATCH] gdbstub: only let Execute breakpoints write/restore BKPT opcodes into target memory --- src/core/gdbstub/gdbstub.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/core/gdbstub/gdbstub.cpp b/src/core/gdbstub/gdbstub.cpp index 035448efa..d7649227f 100644 --- a/src/core/gdbstub/gdbstub.cpp +++ b/src/core/gdbstub/gdbstub.cpp @@ -409,10 +409,13 @@ static void RemoveBreakpoint(BreakpointType type, VAddr addr) { LOG_DEBUG(Debug_GDBStub, "gdb: removed a breakpoint: {:08x} bytes at {:08x} of type {}", bp->second.len, bp->second.addr, static_cast(type)); - Core::System::GetInstance().Memory().WriteBlock( - *Core::System::GetInstance().Kernel().GetCurrentProcess(), bp->second.addr, - bp->second.inst.data(), bp->second.inst.size()); - Core::CPU().ClearInstructionCache(); + + if (type == BreakpointType::Execute) { + Core::System::GetInstance().Memory().WriteBlock( + *Core::System::GetInstance().Kernel().GetCurrentProcess(), bp->second.addr, + bp->second.inst.data(), bp->second.inst.size()); + Core::CPU().ClearInstructionCache(); + } p.erase(addr); } @@ -921,11 +924,14 @@ static bool CommitBreakpoint(BreakpointType type, VAddr addr, u32 len) { Core::System::GetInstance().Memory().ReadBlock( *Core::System::GetInstance().Kernel().GetCurrentProcess(), addr, breakpoint.inst.data(), breakpoint.inst.size()); + static constexpr std::array btrap{0x70, 0x00, 0x20, 0xe1}; - Core::System::GetInstance().Memory().WriteBlock( - *Core::System::GetInstance().Kernel().GetCurrentProcess(), addr, btrap.data(), - btrap.size()); - Core::CPU().ClearInstructionCache(); + if (type == BreakpointType::Execute) { + Core::System::GetInstance().Memory().WriteBlock( + *Core::System::GetInstance().Kernel().GetCurrentProcess(), addr, btrap.data(), + btrap.size()); + Core::CPU().ClearInstructionCache(); + } p.insert({addr, breakpoint}); LOG_DEBUG(Debug_GDBStub, "gdb: added {} breakpoint: {:08x} bytes at {:08x}\n",