summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/debugger/gdbstub.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/core/debugger/gdbstub.cpp b/src/core/debugger/gdbstub.cpp
index 0f839d5b4..e55831f27 100644
--- a/src/core/debugger/gdbstub.cpp
+++ b/src/core/debugger/gdbstub.cpp
@@ -263,6 +263,23 @@ void GDBStub::ExecuteCommand(std::string_view packet, std::vector<DebuggerAction
263 263
264 std::vector<u8> mem(size); 264 std::vector<u8> mem(size);
265 if (system.ApplicationMemory().ReadBlock(addr, mem.data(), size)) { 265 if (system.ApplicationMemory().ReadBlock(addr, mem.data(), size)) {
266 // Restore any bytes belonging to replaced instructions.
267 auto it = replaced_instructions.lower_bound(addr);
268 for (; it != replaced_instructions.end() && it->first < addr + size; it++) {
269 // Get the bytes of the instruction we previously replaced.
270 const u32 original_bytes = it->second;
271
272 // Calculate where to start writing to the output buffer.
273 const size_t output_offset = it->first - addr;
274
275 // Calculate how many bytes to write.
276 // The loop condition ensures output_offset < size.
277 const size_t n = std::min<size_t>(size - output_offset, sizeof(u32));
278
279 // Write the bytes to the output buffer.
280 std::memcpy(mem.data() + output_offset, &original_bytes, n);
281 }
282
266 SendReply(Common::HexToString(mem)); 283 SendReply(Common::HexToString(mem));
267 } else { 284 } else {
268 SendReply(GDB_STUB_REPLY_ERR); 285 SendReply(GDB_STUB_REPLY_ERR);