summaryrefslogtreecommitdiff
path: root/src/core/gdbstub/gdbstub.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/gdbstub/gdbstub.cpp')
-rw-r--r--src/core/gdbstub/gdbstub.cpp20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/core/gdbstub/gdbstub.cpp b/src/core/gdbstub/gdbstub.cpp
index be2b2e25f..d6be16ef6 100644
--- a/src/core/gdbstub/gdbstub.cpp
+++ b/src/core/gdbstub/gdbstub.cpp
@@ -644,7 +644,7 @@ static void ReadMemory() {
644 644
645 auto start_offset = command_buffer + 1; 645 auto start_offset = command_buffer + 1;
646 auto addr_pos = std::find(start_offset, command_buffer + command_length, ','); 646 auto addr_pos = std::find(start_offset, command_buffer + command_length, ',');
647 PAddr addr = HexToInt(start_offset, static_cast<u32>(addr_pos - start_offset)); 647 VAddr addr = HexToInt(start_offset, static_cast<u32>(addr_pos - start_offset));
648 648
649 start_offset = addr_pos + 1; 649 start_offset = addr_pos + 1;
650 u32 len = 650 u32 len =
@@ -656,12 +656,14 @@ static void ReadMemory() {
656 SendReply("E01"); 656 SendReply("E01");
657 } 657 }
658 658
659 const u8* data = Memory::GetPointer(addr); 659 if (!Memory::IsValidVirtualAddress(addr)) {
660 if (!data) {
661 return SendReply("E00"); 660 return SendReply("E00");
662 } 661 }
663 662
664 MemToGdbHex(reply, data, len); 663 std::vector<u8> data(len);
664 Memory::ReadBlock(addr, data.data(), len);
665
666 MemToGdbHex(reply, data.data(), len);
665 reply[len * 2] = '\0'; 667 reply[len * 2] = '\0';
666 SendReply(reinterpret_cast<char*>(reply)); 668 SendReply(reinterpret_cast<char*>(reply));
667} 669}
@@ -670,18 +672,20 @@ static void ReadMemory() {
670static void WriteMemory() { 672static void WriteMemory() {
671 auto start_offset = command_buffer + 1; 673 auto start_offset = command_buffer + 1;
672 auto addr_pos = std::find(start_offset, command_buffer + command_length, ','); 674 auto addr_pos = std::find(start_offset, command_buffer + command_length, ',');
673 PAddr addr = HexToInt(start_offset, static_cast<u32>(addr_pos - start_offset)); 675 VAddr addr = HexToInt(start_offset, static_cast<u32>(addr_pos - start_offset));
674 676
675 start_offset = addr_pos + 1; 677 start_offset = addr_pos + 1;
676 auto len_pos = std::find(start_offset, command_buffer + command_length, ':'); 678 auto len_pos = std::find(start_offset, command_buffer + command_length, ':');
677 u32 len = HexToInt(start_offset, static_cast<u32>(len_pos - start_offset)); 679 u32 len = HexToInt(start_offset, static_cast<u32>(len_pos - start_offset));
678 680
679 u8* dst = Memory::GetPointer(addr); 681 if (!Memory::IsValidVirtualAddress(addr)) {
680 if (!dst) {
681 return SendReply("E00"); 682 return SendReply("E00");
682 } 683 }
683 684
684 GdbHexToMem(dst, len_pos + 1, len); 685 std::vector<u8> data(len);
686
687 GdbHexToMem(data.data(), len_pos + 1, len);
688 Memory::WriteBlock(addr, data.data(), len);
685 SendReply("OK"); 689 SendReply("OK");
686} 690}
687 691