From c299f282cac97d375d9d15c75fa09c1bed000818 Mon Sep 17 00:00:00 2001 From: Nav Date: Fri, 28 Oct 2022 23:31:16 +0100 Subject: [PATCH] More tidying --- .../Gdb/AvrGdb/CommandPackets/ReadMemory.cpp | 7 +++---- .../Gdb/AvrGdb/CommandPackets/WriteMemory.cpp | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/DebugServer/Gdb/AvrGdb/CommandPackets/ReadMemory.cpp b/src/DebugServer/Gdb/AvrGdb/CommandPackets/ReadMemory.cpp index d6a62aed..aced4312 100644 --- a/src/DebugServer/Gdb/AvrGdb/CommandPackets/ReadMemory.cpp +++ b/src/DebugServer/Gdb/AvrGdb/CommandPackets/ReadMemory.cpp @@ -108,7 +108,8 @@ namespace Bloom::DebugServer::Gdb::AvrGdb::CommandPackets * GDB with an error response. */ Logger::debug( - "GDB requested access to memory which is outside the target's memory range - returning error response" + "GDB requested access to memory which is outside the target's memory range - returning error " + "response" ); debugSession.connection.writePacket(ErrorResponsePacket()); return; @@ -139,9 +140,7 @@ namespace Bloom::DebugServer::Gdb::AvrGdb::CommandPackets memoryBuffer.insert(memoryBuffer.end(), (this->bytes - bytesToRead), 0x00); } - debugSession.connection.writePacket( - ResponsePacket(Packet::toHex(memoryBuffer)) - ); + debugSession.connection.writePacket(ResponsePacket(Packet::toHex(memoryBuffer))); } catch (const Exception& exception) { Logger::error("Failed to read memory from target - " + exception.getMessage()); diff --git a/src/DebugServer/Gdb/AvrGdb/CommandPackets/WriteMemory.cpp b/src/DebugServer/Gdb/AvrGdb/CommandPackets/WriteMemory.cpp index d98e9ac5..9fdf3649 100644 --- a/src/DebugServer/Gdb/AvrGdb/CommandPackets/WriteMemory.cpp +++ b/src/DebugServer/Gdb/AvrGdb/CommandPackets/WriteMemory.cpp @@ -78,6 +78,21 @@ namespace Bloom::DebugServer::Gdb::AvrGdb::CommandPackets throw Exception("Target does not support the requested memory type."); } + if (this->memoryType == Targets::TargetMemoryType::FLASH) { + /* + * This shouldn't happen - GDB should send the FlashWrite (vFlashWrite) packet to write to the target's + * program memory. + * + * A number of actions have to be taken before we can write to the target's program memory - this is + * all covered in the FlashWrite and FlashDone command classes. I don't want to cover it again in here, + * so just respond with an error and request that this issue be reported. + */ + throw Exception( + "GDB attempted to write to program memory via an \"M\" packet - this is not supported. Please " + "report this issue to Bloom developers with the full debug log." + ); + } + if (this->buffer.size() == 0) { debugSession.connection.writePacket(OkResponsePacket()); return;