Passed target state to GDB command handlers, and removed unnecessary PC read

This commit is contained in:
Nav
2024-12-14 16:17:02 +00:00
parent 87ffc10306
commit 48a7ae5dd0
55 changed files with 66 additions and 25 deletions

View File

@@ -4,6 +4,7 @@
#include "src/DebugServer/Gdb/DebugSession.hpp" #include "src/DebugServer/Gdb/DebugSession.hpp"
#include "src/DebugServer/Gdb/AvrGdb/AvrGdbTargetDescriptor.hpp" #include "src/DebugServer/Gdb/AvrGdb/AvrGdbTargetDescriptor.hpp"
#include "src/Targets/TargetDescriptor.hpp" #include "src/Targets/TargetDescriptor.hpp"
#include "src/Targets/TargetState.hpp"
#include "src/Services/TargetControllerService.hpp" #include "src/Services/TargetControllerService.hpp"
namespace DebugServer::Gdb::AvrGdb::CommandPackets namespace DebugServer::Gdb::AvrGdb::CommandPackets
@@ -25,6 +26,7 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
DebugSession& debugSession, DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor, const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
Services::TargetControllerService& targetControllerService Services::TargetControllerService& targetControllerService
) = 0; ) = 0;
}; };

View File

@@ -32,6 +32,7 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
DebugSession& debugSession, DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor, const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
TargetControllerService& targetControllerService TargetControllerService& targetControllerService
) { ) {
Logger::info("Handling EepromFill packet"); Logger::info("Handling EepromFill packet");

View File

@@ -26,6 +26,7 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
DebugSession& debugSession, DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor, const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
Services::TargetControllerService& targetControllerService Services::TargetControllerService& targetControllerService
) override; ) override;
}; };

View File

@@ -23,6 +23,7 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
DebugSession& debugSession, DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor, const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
TargetControllerService& targetControllerService TargetControllerService& targetControllerService
) { ) {
Logger::info("Handling FlashDone packet"); Logger::info("Handling FlashDone packet");

View File

@@ -22,6 +22,7 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
DebugSession& debugSession, DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor, const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
Services::TargetControllerService& targetControllerService Services::TargetControllerService& targetControllerService
) override; ) override;
}; };

View File

@@ -46,6 +46,7 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
DebugSession& debugSession, DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor, const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
TargetControllerService& targetControllerService TargetControllerService& targetControllerService
) { ) {
Logger::info("Handling FlashErase packet"); Logger::info("Handling FlashErase packet");

View File

@@ -26,6 +26,7 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
DebugSession& debugSession, DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor, const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
Services::TargetControllerService& targetControllerService Services::TargetControllerService& targetControllerService
) override; ) override;
}; };

View File

@@ -43,6 +43,7 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
DebugSession& debugSession, DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor, const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
TargetControllerService& targetControllerService TargetControllerService& targetControllerService
) { ) {
Logger::info("Handling FlashWrite packet"); Logger::info("Handling FlashWrite packet");

View File

@@ -28,6 +28,7 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
DebugSession& debugSession, DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor, const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
Services::TargetControllerService& targetControllerService Services::TargetControllerService& targetControllerService
) override; ) override;
}; };

View File

@@ -27,6 +27,7 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
DebugSession& debugSession, DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor, const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
TargetControllerService& targetControllerService TargetControllerService& targetControllerService
) { ) {
Logger::info("Handling ReadMemory packet"); Logger::info("Handling ReadMemory packet");

View File

@@ -31,6 +31,7 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
DebugSession& debugSession, DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor, const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
Services::TargetControllerService& targetControllerService Services::TargetControllerService& targetControllerService
) override; ) override;

View File

@@ -41,6 +41,7 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
DebugSession& debugSession, DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor, const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
TargetControllerService& targetControllerService TargetControllerService& targetControllerService
) { ) {
Logger::info("Handling ReadMemoryMap packet"); Logger::info("Handling ReadMemoryMap packet");

View File

@@ -32,6 +32,7 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
DebugSession& debugSession, DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor, const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
Services::TargetControllerService& targetControllerService Services::TargetControllerService& targetControllerService
) override; ) override;
}; };

View File

@@ -38,6 +38,7 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
DebugSession& debugSession, DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor, const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
TargetControllerService& targetControllerService TargetControllerService& targetControllerService
) { ) {
Logger::info("Handling ReadRegister packet"); Logger::info("Handling ReadRegister packet");
@@ -46,12 +47,7 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
Logger::debug("Reading GDB register ID: " + std::to_string(this->registerId)); Logger::debug("Reading GDB register ID: " + std::to_string(this->registerId));
if (this->registerId == AvrGdbTargetDescriptor::PROGRAM_COUNTER_GDB_REGISTER_ID) { if (this->registerId == AvrGdbTargetDescriptor::PROGRAM_COUNTER_GDB_REGISTER_ID) {
/* const auto programCounter = targetState.programCounter.load().value();
* GDB has requested the program counter. We can't access this in the same way as we do with other
* registers.
*/
const auto programCounter = targetControllerService.getProgramCounter();
debugSession.connection.writePacket( debugSession.connection.writePacket(
ResponsePacket{Services::StringService::toHex(Targets::TargetMemoryBuffer{ ResponsePacket{Services::StringService::toHex(Targets::TargetMemoryBuffer{
static_cast<unsigned char>(programCounter), static_cast<unsigned char>(programCounter),

View File

@@ -24,6 +24,7 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
DebugSession& debugSession, DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor, const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
Services::TargetControllerService& targetControllerService Services::TargetControllerService& targetControllerService
) override; ) override;
}; };

View File

@@ -30,6 +30,7 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
DebugSession& debugSession, DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor, const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
TargetControllerService& targetControllerService TargetControllerService& targetControllerService
) { ) {
Logger::info("Handling ReadRegisters packet"); Logger::info("Handling ReadRegisters packet");
@@ -76,7 +77,7 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
buffer[33] = static_cast<unsigned char>(spValue); buffer[33] = static_cast<unsigned char>(spValue);
buffer[34] = static_cast<unsigned char>(spValue >> 8); buffer[34] = static_cast<unsigned char>(spValue >> 8);
const auto pcValue = targetControllerService.getProgramCounter(); const auto pcValue = targetState.programCounter.load().value();
buffer[35] = static_cast<unsigned char>(pcValue); buffer[35] = static_cast<unsigned char>(pcValue);
buffer[36] = static_cast<unsigned char>(pcValue >> 8); buffer[36] = static_cast<unsigned char>(pcValue >> 8);
buffer[37] = static_cast<unsigned char>(pcValue >> 16); buffer[37] = static_cast<unsigned char>(pcValue >> 16);

View File

@@ -24,6 +24,7 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
DebugSession& debugSession, DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor, const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
Services::TargetControllerService& targetControllerService Services::TargetControllerService& targetControllerService
) override; ) override;
}; };

View File

@@ -56,6 +56,7 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
DebugSession& debugSession, DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor, const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor&, const Targets::TargetDescriptor&,
const Targets::TargetState& targetState,
TargetControllerService& targetControllerService TargetControllerService& targetControllerService
) { ) {
Logger::info("Handling RemoveBreakpoint packet"); Logger::info("Handling RemoveBreakpoint packet");

View File

@@ -36,6 +36,7 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
DebugSession& debugSession, DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor, const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
Services::TargetControllerService& targetControllerService Services::TargetControllerService& targetControllerService
) override; ) override;
}; };

View File

@@ -57,6 +57,7 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
DebugSession& debugSession, DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor, const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor&, const Targets::TargetDescriptor&,
const Targets::TargetState& targetState,
TargetControllerService& targetControllerService TargetControllerService& targetControllerService
) { ) {
Logger::info("Handling SetBreakpoint packet"); Logger::info("Handling SetBreakpoint packet");

View File

@@ -25,6 +25,7 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
DebugSession& debugSession, DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor, const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
Services::TargetControllerService& targetControllerService Services::TargetControllerService& targetControllerService
) override; ) override;
}; };

View File

@@ -45,6 +45,7 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
DebugSession& debugSession, DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor, const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
TargetControllerService& targetControllerService TargetControllerService& targetControllerService
) { ) {
using Targets::Microchip::Avr8::OpcodeDecoder::Decoder; using Targets::Microchip::Avr8::OpcodeDecoder::Decoder;

View File

@@ -28,6 +28,7 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
DebugSession& debugSession, DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor, const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
Services::TargetControllerService& targetControllerService Services::TargetControllerService& targetControllerService
) override; ) override;
}; };

View File

@@ -16,6 +16,7 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
DebugSession& debugSession, DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor, const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
TargetControllerService& targetControllerService TargetControllerService& targetControllerService
) { ) {
Logger::info("Handling VContSupportedActionsQuery packet"); Logger::info("Handling VContSupportedActionsQuery packet");

View File

@@ -25,6 +25,7 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
DebugSession& debugSession, DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor, const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
Services::TargetControllerService& targetControllerService Services::TargetControllerService& targetControllerService
) override; ) override;
}; };

View File

@@ -24,6 +24,7 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
DebugSession& debugSession, DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor, const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
TargetControllerService& targetControllerService TargetControllerService& targetControllerService
) { ) {
Logger::info("Handling WriteMemory packet"); Logger::info("Handling WriteMemory packet");

View File

@@ -31,6 +31,7 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
DebugSession& debugSession, DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor, const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
Services::TargetControllerService& targetControllerService Services::TargetControllerService& targetControllerService
) override; ) override;

View File

@@ -49,6 +49,7 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
DebugSession& debugSession, DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor, const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
TargetControllerService& targetControllerService TargetControllerService& targetControllerService
) { ) {
Logger::info("Handling WriteRegister packet"); Logger::info("Handling WriteRegister packet");

View File

@@ -26,6 +26,7 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
DebugSession& debugSession, DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor, const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
Services::TargetControllerService& targetControllerService Services::TargetControllerService& targetControllerService
) override; ) override;
}; };

View File

@@ -55,6 +55,7 @@
#include "src/Services/ProcessService.hpp" #include "src/Services/ProcessService.hpp"
#include "src/Services/StringService.hpp" #include "src/Services/StringService.hpp"
#include "src/Targets/TargetDescriptor.hpp" #include "src/Targets/TargetDescriptor.hpp"
#include "src/Targets/TargetState.hpp"
#include "src/Logger/Logger.hpp" #include "src/Logger/Logger.hpp"
#include "src/EventManager/Events/TargetStateChanged.hpp" #include "src/EventManager/Events/TargetStateChanged.hpp"
@@ -104,6 +105,7 @@ namespace DebugServer::Gdb
, gdbTargetDescriptor(std::move(gdbTargetDescriptor)) , gdbTargetDescriptor(std::move(gdbTargetDescriptor))
, eventListener(eventListener) , eventListener(eventListener)
, interruptEventNotifier(eventNotifier) , interruptEventNotifier(eventNotifier)
, targetState(this->targetControllerService.getTargetState())
{}; {};
GdbRspDebugServer() = delete; GdbRspDebugServer() = delete;
@@ -238,6 +240,7 @@ namespace DebugServer::Gdb
*(this->debugSession), *(this->debugSession),
this->gdbTargetDescriptor, this->gdbTargetDescriptor,
this->targetDescriptor, this->targetDescriptor,
this->targetState,
this->targetControllerService this->targetControllerService
); );
@@ -321,6 +324,8 @@ namespace DebugServer::Gdb
Services::TargetControllerService targetControllerService = {}; Services::TargetControllerService targetControllerService = {};
const Targets::TargetState& targetState;
struct sockaddr_in socketAddress = {}; struct sockaddr_in socketAddress = {};
std::optional<int> serverSocketFileDescriptor; std::optional<int> serverSocketFileDescriptor;

View File

@@ -23,6 +23,7 @@ namespace DebugServer::Gdb::RiscVGdb::CommandPackets
Gdb::DebugSession& debugSession, Gdb::DebugSession& debugSession,
const RiscVGdbTargetDescriptor& gdbTargetDescriptor, const RiscVGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
TargetControllerService& targetControllerService TargetControllerService& targetControllerService
) { ) {
Logger::info("Handling FlashDone packet"); Logger::info("Handling FlashDone packet");

View File

@@ -22,6 +22,7 @@ namespace DebugServer::Gdb::RiscVGdb::CommandPackets
Gdb::DebugSession& debugSession, Gdb::DebugSession& debugSession,
const RiscVGdbTargetDescriptor& gdbTargetDescriptor, const RiscVGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
Services::TargetControllerService& targetControllerService Services::TargetControllerService& targetControllerService
) override; ) override;
}; };

View File

@@ -40,6 +40,7 @@ namespace DebugServer::Gdb::RiscVGdb::CommandPackets
Gdb::DebugSession& debugSession, Gdb::DebugSession& debugSession,
const RiscVGdbTargetDescriptor& gdbTargetDescriptor, const RiscVGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
TargetControllerService& targetControllerService TargetControllerService& targetControllerService
) { ) {
Logger::info("Handling FlashErase packet"); Logger::info("Handling FlashErase packet");

View File

@@ -25,6 +25,7 @@ namespace DebugServer::Gdb::RiscVGdb::CommandPackets
Gdb::DebugSession& debugSession, Gdb::DebugSession& debugSession,
const RiscVGdbTargetDescriptor& gdbTargetDescriptor, const RiscVGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
Services::TargetControllerService& targetControllerService Services::TargetControllerService& targetControllerService
) override; ) override;
}; };

View File

@@ -43,6 +43,7 @@ namespace DebugServer::Gdb::RiscVGdb::CommandPackets
Gdb::DebugSession& debugSession, Gdb::DebugSession& debugSession,
const RiscVGdbTargetDescriptor& gdbTargetDescriptor, const RiscVGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
TargetControllerService& targetControllerService TargetControllerService& targetControllerService
) { ) {
Logger::info("Handling FlashWrite packet"); Logger::info("Handling FlashWrite packet");

View File

@@ -24,6 +24,7 @@ namespace DebugServer::Gdb::RiscVGdb::CommandPackets
Gdb::DebugSession& debugSession, Gdb::DebugSession& debugSession,
const RiscVGdbTargetDescriptor& gdbTargetDescriptor, const RiscVGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
Services::TargetControllerService& targetControllerService Services::TargetControllerService& targetControllerService
) override; ) override;
}; };

View File

@@ -27,6 +27,7 @@ namespace DebugServer::Gdb::RiscVGdb::CommandPackets
Gdb::DebugSession& debugSession, Gdb::DebugSession& debugSession,
const RiscVGdbTargetDescriptor& gdbTargetDescriptor, const RiscVGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
TargetControllerService& targetControllerService TargetControllerService& targetControllerService
) { ) {
Logger::info("Handling ReadMemory packet"); Logger::info("Handling ReadMemory packet");

View File

@@ -27,6 +27,7 @@ namespace DebugServer::Gdb::RiscVGdb::CommandPackets
Gdb::DebugSession& debugSession, Gdb::DebugSession& debugSession,
const RiscVGdbTargetDescriptor& gdbTargetDescriptor, const RiscVGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
Services::TargetControllerService& targetControllerService Services::TargetControllerService& targetControllerService
) override; ) override;

View File

@@ -41,6 +41,7 @@ namespace DebugServer::Gdb::RiscVGdb::CommandPackets
Gdb::DebugSession& debugSession, Gdb::DebugSession& debugSession,
const RiscVGdbTargetDescriptor& gdbTargetDescriptor, const RiscVGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
TargetControllerService& targetControllerService TargetControllerService& targetControllerService
) { ) {
using Targets::TargetMemorySegmentType; using Targets::TargetMemorySegmentType;

View File

@@ -31,6 +31,7 @@ namespace DebugServer::Gdb::RiscVGdb::CommandPackets
Gdb::DebugSession& debugSession, Gdb::DebugSession& debugSession,
const RiscVGdbTargetDescriptor& gdbTargetDescriptor, const RiscVGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
Services::TargetControllerService& targetControllerService Services::TargetControllerService& targetControllerService
) override; ) override;
}; };

View File

@@ -38,6 +38,7 @@ namespace DebugServer::Gdb::RiscVGdb::CommandPackets
Gdb::DebugSession& debugSession, Gdb::DebugSession& debugSession,
const RiscVGdbTargetDescriptor& gdbTargetDescriptor, const RiscVGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
TargetControllerService& targetControllerService TargetControllerService& targetControllerService
) { ) {
Logger::info("Handling ReadRegister packet"); Logger::info("Handling ReadRegister packet");
@@ -46,12 +47,7 @@ namespace DebugServer::Gdb::RiscVGdb::CommandPackets
Logger::debug("Reading GDB register ID: " + std::to_string(this->registerId)); Logger::debug("Reading GDB register ID: " + std::to_string(this->registerId));
if (this->registerId == gdbTargetDescriptor.programCounterGdbRegisterId) { if (this->registerId == gdbTargetDescriptor.programCounterGdbRegisterId) {
/* const auto programCounter = targetState.programCounter.load().value();
* GDB has requested the program counter. We can't access this in the same way as we do with other
* registers.
*/
const auto programCounter = targetControllerService.getProgramCounter();
debugSession.connection.writePacket( debugSession.connection.writePacket(
ResponsePacket{Services::StringService::toHex(Targets::TargetMemoryBuffer{ ResponsePacket{Services::StringService::toHex(Targets::TargetMemoryBuffer{
static_cast<unsigned char>(programCounter), static_cast<unsigned char>(programCounter),

View File

@@ -20,6 +20,7 @@ namespace DebugServer::Gdb::RiscVGdb::CommandPackets
Gdb::DebugSession& debugSession, Gdb::DebugSession& debugSession,
const RiscVGdbTargetDescriptor& gdbTargetDescriptor, const RiscVGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
Services::TargetControllerService& targetControllerService Services::TargetControllerService& targetControllerService
) override; ) override;
}; };

View File

@@ -30,6 +30,7 @@ namespace DebugServer::Gdb::RiscVGdb::CommandPackets
Gdb::DebugSession& debugSession, Gdb::DebugSession& debugSession,
const RiscVGdbTargetDescriptor& gdbTargetDescriptor, const RiscVGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
TargetControllerService& targetControllerService TargetControllerService& targetControllerService
) { ) {
Logger::info("Handling ReadRegisters packet"); Logger::info("Handling ReadRegisters packet");
@@ -58,13 +59,11 @@ namespace DebugServer::Gdb::RiscVGdb::CommandPackets
assert((buffer.size() - bufferOffset) >= regVal.size()); assert((buffer.size() - bufferOffset) >= regVal.size());
/* // GDB expects register values in LSB form, which is why we use reverse iterators below.
* GDB expects register values in LSB form, which is why we use reverse iterators below.
*/
std::copy(regVal.rbegin(), regVal.rend(), buffer.begin() + bufferOffset); std::copy(regVal.rbegin(), regVal.rend(), buffer.begin() + bufferOffset);
} }
const auto pcValue = targetControllerService.getProgramCounter(); const auto pcValue = targetState.programCounter.load().value();
buffer[totalRegBytes - 4] = static_cast<unsigned char>(pcValue); buffer[totalRegBytes - 4] = static_cast<unsigned char>(pcValue);
buffer[totalRegBytes - 3] = static_cast<unsigned char>(pcValue >> 8); buffer[totalRegBytes - 3] = static_cast<unsigned char>(pcValue >> 8);
buffer[totalRegBytes - 2] = static_cast<unsigned char>(pcValue >> 16); buffer[totalRegBytes - 2] = static_cast<unsigned char>(pcValue >> 16);

View File

@@ -21,6 +21,7 @@ namespace DebugServer::Gdb::RiscVGdb::CommandPackets
Gdb::DebugSession& debugSession, Gdb::DebugSession& debugSession,
const RiscVGdbTargetDescriptor& gdbTargetDescriptor, const RiscVGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
Services::TargetControllerService& targetControllerService Services::TargetControllerService& targetControllerService
) override; ) override;
}; };

View File

@@ -56,6 +56,7 @@ namespace DebugServer::Gdb::RiscVGdb::CommandPackets
DebugSession& debugSession, DebugSession& debugSession,
const RiscVGdbTargetDescriptor& gdbTargetDescriptor, const RiscVGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor&, const Targets::TargetDescriptor&,
const Targets::TargetState& targetState,
TargetControllerService& targetControllerService TargetControllerService& targetControllerService
) { ) {
Logger::info("Handling RemoveBreakpoint packet"); Logger::info("Handling RemoveBreakpoint packet");

View File

@@ -25,6 +25,7 @@ namespace DebugServer::Gdb::RiscVGdb::CommandPackets
DebugSession& debugSession, DebugSession& debugSession,
const RiscVGdbTargetDescriptor& gdbTargetDescriptor, const RiscVGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
Services::TargetControllerService& targetControllerService Services::TargetControllerService& targetControllerService
) override; ) override;
}; };

View File

@@ -4,6 +4,7 @@
#include "src/DebugServer/Gdb/DebugSession.hpp" #include "src/DebugServer/Gdb/DebugSession.hpp"
#include "src/DebugServer/Gdb/RiscVGdb/RiscVGdbTargetDescriptor.hpp" #include "src/DebugServer/Gdb/RiscVGdb/RiscVGdbTargetDescriptor.hpp"
#include "src/Targets/TargetDescriptor.hpp" #include "src/Targets/TargetDescriptor.hpp"
#include "src/Targets/TargetState.hpp"
#include "src/Services/TargetControllerService.hpp" #include "src/Services/TargetControllerService.hpp"
namespace DebugServer::Gdb::RiscVGdb::CommandPackets namespace DebugServer::Gdb::RiscVGdb::CommandPackets
@@ -13,18 +14,11 @@ namespace DebugServer::Gdb::RiscVGdb::CommandPackets
public: public:
virtual ~RiscVGdbCommandPacketInterface() = default; virtual ~RiscVGdbCommandPacketInterface() = default;
/**
* Should handle the command for the current active debug session.
*
* @param debugSession
* The current active debug session.
*
* @param TargetControllerService
*/
virtual void handle( virtual void handle(
DebugSession& debugSession, DebugSession& debugSession,
const RiscVGdbTargetDescriptor& gdbTargetDescriptor, const RiscVGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
Services::TargetControllerService& targetControllerService Services::TargetControllerService& targetControllerService
) = 0; ) = 0;
}; };

View File

@@ -57,6 +57,7 @@ namespace DebugServer::Gdb::RiscVGdb::CommandPackets
DebugSession& debugSession, DebugSession& debugSession,
const RiscVGdbTargetDescriptor& gdbTargetDescriptor, const RiscVGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor&, const Targets::TargetDescriptor&,
const Targets::TargetState& targetState,
TargetControllerService& targetControllerService TargetControllerService& targetControllerService
) { ) {
Logger::info("Handling SetBreakpoint packet"); Logger::info("Handling SetBreakpoint packet");

View File

@@ -32,6 +32,7 @@ namespace DebugServer::Gdb::RiscVGdb::CommandPackets
DebugSession& debugSession, DebugSession& debugSession,
const RiscVGdbTargetDescriptor& gdbTargetDescriptor, const RiscVGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
Services::TargetControllerService& targetControllerService Services::TargetControllerService& targetControllerService
) override; ) override;
}; };

View File

@@ -16,6 +16,7 @@ namespace DebugServer::Gdb::RiscVGdb::CommandPackets
Gdb::DebugSession& debugSession, Gdb::DebugSession& debugSession,
const RiscVGdbTargetDescriptor& gdbTargetDescriptor, const RiscVGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
TargetControllerService& targetControllerService TargetControllerService& targetControllerService
) { ) {
Logger::info("Handling VContSupportedActionsQuery packet"); Logger::info("Handling VContSupportedActionsQuery packet");

View File

@@ -19,6 +19,7 @@ namespace DebugServer::Gdb::RiscVGdb::CommandPackets
Gdb::DebugSession& debugSession, Gdb::DebugSession& debugSession,
const RiscVGdbTargetDescriptor& gdbTargetDescriptor, const RiscVGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
Services::TargetControllerService& targetControllerService Services::TargetControllerService& targetControllerService
) override; ) override;
}; };

View File

@@ -24,6 +24,7 @@ namespace DebugServer::Gdb::RiscVGdb::CommandPackets
Gdb::DebugSession& debugSession, Gdb::DebugSession& debugSession,
const RiscVGdbTargetDescriptor& gdbTargetDescriptor, const RiscVGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
TargetControllerService& targetControllerService TargetControllerService& targetControllerService
) { ) {
Logger::info("Handling WriteMemory packet"); Logger::info("Handling WriteMemory packet");

View File

@@ -25,6 +25,7 @@ namespace DebugServer::Gdb::RiscVGdb::CommandPackets
Gdb::DebugSession& debugSession, Gdb::DebugSession& debugSession,
const RiscVGdbTargetDescriptor& gdbTargetDescriptor, const RiscVGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
Services::TargetControllerService& targetControllerService Services::TargetControllerService& targetControllerService
) override; ) override;

View File

@@ -49,6 +49,7 @@ namespace DebugServer::Gdb::RiscVGdb::CommandPackets
Gdb::DebugSession& debugSession, Gdb::DebugSession& debugSession,
const RiscVGdbTargetDescriptor& gdbTargetDescriptor, const RiscVGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
TargetControllerService& targetControllerService TargetControllerService& targetControllerService
) { ) {
Logger::info("Handling WriteRegister packet"); Logger::info("Handling WriteRegister packet");

View File

@@ -23,6 +23,7 @@ namespace DebugServer::Gdb::RiscVGdb::CommandPackets
Gdb::DebugSession& debugSession, Gdb::DebugSession& debugSession,
const RiscVGdbTargetDescriptor& gdbTargetDescriptor, const RiscVGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor, const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState,
Services::TargetControllerService& targetControllerService Services::TargetControllerService& targetControllerService
) override; ) override;
}; };