diff options
| author | 2023-08-15 15:36:14 +0200 | |
|---|---|---|
| committer | 2023-08-15 15:36:14 +0200 | |
| commit | a8c4f01f6ca040672e85faaf42a8ef12d373dd65 (patch) | |
| tree | 2db0c5b56534cca4b569b5832db84fc1cebba662 | |
| parent | Merge pull request #11256 from FearlessTobi/revert-10075 (diff) | |
| parent | gdbstub: fixup replaced instruction bytes in memory reads (diff) | |
| download | yuzu-a8c4f01f6ca040672e85faaf42a8ef12d373dd65.tar.gz yuzu-a8c4f01f6ca040672e85faaf42a8ef12d373dd65.tar.xz yuzu-a8c4f01f6ca040672e85faaf42a8ef12d373dd65.zip | |
Merge pull request #11287 from liamwhite/replaced-bytes
gdbstub: fixup replaced instruction bytes in memory reads
| -rw-r--r-- | src/core/debugger/gdbstub.cpp | 17 |
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); |