From d8a25fe2643374dc68749fd56e6a9f38914df141 Mon Sep 17 00:00:00 2001 From: Nav Date: Sun, 3 Apr 2022 17:25:21 +0100 Subject: [PATCH] Removed unnecessary init() member functions in command packet classes. --- .../Gdb/CommandPackets/ContinueExecution.cpp | 4 +++- .../Gdb/CommandPackets/ContinueExecution.hpp | 7 +------ .../Gdb/CommandPackets/ReadRegisters.cpp | 4 +++- .../Gdb/CommandPackets/ReadRegisters.hpp | 7 +------ .../Gdb/CommandPackets/RemoveBreakpoint.cpp | 4 +++- .../Gdb/CommandPackets/RemoveBreakpoint.hpp | 7 +------ .../Gdb/CommandPackets/SetBreakpoint.cpp | 4 +++- .../Gdb/CommandPackets/SetBreakpoint.hpp | 7 +------ .../Gdb/CommandPackets/StepExecution.cpp | 4 +++- .../Gdb/CommandPackets/StepExecution.hpp | 7 +------ .../Gdb/CommandPackets/SupportedFeaturesQuery.cpp | 8 +++++--- .../Gdb/CommandPackets/SupportedFeaturesQuery.hpp | 6 +----- .../Gdb/CommandPackets/WriteRegister.cpp | 13 ++++++++++--- .../Gdb/CommandPackets/WriteRegister.hpp | 7 +------ 14 files changed, 37 insertions(+), 52 deletions(-) diff --git a/src/DebugServer/Gdb/CommandPackets/ContinueExecution.cpp b/src/DebugServer/Gdb/CommandPackets/ContinueExecution.cpp index c3a5dcf4..c640826a 100644 --- a/src/DebugServer/Gdb/CommandPackets/ContinueExecution.cpp +++ b/src/DebugServer/Gdb/CommandPackets/ContinueExecution.cpp @@ -10,7 +10,9 @@ namespace Bloom::DebugServer::Gdb::CommandPackets using ResponsePackets::ErrorResponsePacket; using Exceptions::Exception; - void ContinueExecution::init() { + ContinueExecution::ContinueExecution(const std::vector& rawPacket) + : CommandPacket(rawPacket) + { if (this->data.size() > 1) { this->fromProgramCounter = static_cast( std::stoi(std::string(this->data.begin(), this->data.end()), nullptr, 16) diff --git a/src/DebugServer/Gdb/CommandPackets/ContinueExecution.hpp b/src/DebugServer/Gdb/CommandPackets/ContinueExecution.hpp index a056eb7f..baafc027 100644 --- a/src/DebugServer/Gdb/CommandPackets/ContinueExecution.hpp +++ b/src/DebugServer/Gdb/CommandPackets/ContinueExecution.hpp @@ -24,13 +24,8 @@ namespace Bloom::DebugServer::Gdb::CommandPackets */ std::optional fromProgramCounter; - explicit ContinueExecution(const std::vector& rawPacket): CommandPacket(rawPacket) { - init(); - } + explicit ContinueExecution(const std::vector& rawPacket); void handle(DebugSession& debugSession, TargetControllerConsole& targetControllerConsole) override; - - private: - void init(); }; } diff --git a/src/DebugServer/Gdb/CommandPackets/ReadRegisters.cpp b/src/DebugServer/Gdb/CommandPackets/ReadRegisters.cpp index 9fdb48bc..5c647f80 100644 --- a/src/DebugServer/Gdb/CommandPackets/ReadRegisters.cpp +++ b/src/DebugServer/Gdb/CommandPackets/ReadRegisters.cpp @@ -17,7 +17,9 @@ namespace Bloom::DebugServer::Gdb::CommandPackets using Exceptions::Exception; - void ReadRegisters::init() { + ReadRegisters::ReadRegisters(const std::vector& rawPacket) + : CommandPacket(rawPacket) + { if (this->data.size() >= 2 && this->data.front() == 'p') { // This command packet is requesting a specific register this->registerNumber = static_cast( diff --git a/src/DebugServer/Gdb/CommandPackets/ReadRegisters.hpp b/src/DebugServer/Gdb/CommandPackets/ReadRegisters.hpp index 87931feb..2c314165 100644 --- a/src/DebugServer/Gdb/CommandPackets/ReadRegisters.hpp +++ b/src/DebugServer/Gdb/CommandPackets/ReadRegisters.hpp @@ -25,13 +25,8 @@ namespace Bloom::DebugServer::Gdb::CommandPackets */ std::optional registerNumber; - explicit ReadRegisters(const std::vector& rawPacket): CommandPacket(rawPacket) { - init(); - }; + explicit ReadRegisters(const std::vector& rawPacket); void handle(DebugSession& debugSession, TargetControllerConsole& targetControllerConsole) override; - - private: - void init(); }; } diff --git a/src/DebugServer/Gdb/CommandPackets/RemoveBreakpoint.cpp b/src/DebugServer/Gdb/CommandPackets/RemoveBreakpoint.cpp index 4b7acef7..5261e492 100644 --- a/src/DebugServer/Gdb/CommandPackets/RemoveBreakpoint.cpp +++ b/src/DebugServer/Gdb/CommandPackets/RemoveBreakpoint.cpp @@ -19,7 +19,9 @@ namespace Bloom::DebugServer::Gdb::CommandPackets using Exceptions::Exception; - void RemoveBreakpoint::init() { + RemoveBreakpoint::RemoveBreakpoint(const std::vector& rawPacket) + : CommandPacket(rawPacket) + { if (this->data.size() < 6) { throw Exception("Unexpected RemoveBreakpoint packet size"); } diff --git a/src/DebugServer/Gdb/CommandPackets/RemoveBreakpoint.hpp b/src/DebugServer/Gdb/CommandPackets/RemoveBreakpoint.hpp index fe46aa35..aaa777c5 100644 --- a/src/DebugServer/Gdb/CommandPackets/RemoveBreakpoint.hpp +++ b/src/DebugServer/Gdb/CommandPackets/RemoveBreakpoint.hpp @@ -26,13 +26,8 @@ namespace Bloom::DebugServer::Gdb::CommandPackets */ std::uint32_t address = 0; - explicit RemoveBreakpoint(const std::vector& rawPacket): CommandPacket(rawPacket) { - this->init(); - }; + explicit RemoveBreakpoint(const std::vector& rawPacket); void handle(DebugSession& debugSession, TargetControllerConsole& targetControllerConsole) override; - - private: - void init(); }; } diff --git a/src/DebugServer/Gdb/CommandPackets/SetBreakpoint.cpp b/src/DebugServer/Gdb/CommandPackets/SetBreakpoint.cpp index e71dddb8..091a078a 100644 --- a/src/DebugServer/Gdb/CommandPackets/SetBreakpoint.cpp +++ b/src/DebugServer/Gdb/CommandPackets/SetBreakpoint.cpp @@ -19,7 +19,9 @@ namespace Bloom::DebugServer::Gdb::CommandPackets using Exceptions::Exception; - void SetBreakpoint::init() { + SetBreakpoint::SetBreakpoint(const std::vector& rawPacket) + : CommandPacket(rawPacket) + { if (this->data.size() < 6) { throw Exception("Unexpected SetBreakpoint packet size"); } diff --git a/src/DebugServer/Gdb/CommandPackets/SetBreakpoint.hpp b/src/DebugServer/Gdb/CommandPackets/SetBreakpoint.hpp index 08312197..b9331388 100644 --- a/src/DebugServer/Gdb/CommandPackets/SetBreakpoint.hpp +++ b/src/DebugServer/Gdb/CommandPackets/SetBreakpoint.hpp @@ -26,13 +26,8 @@ namespace Bloom::DebugServer::Gdb::CommandPackets */ std::uint32_t address = 0; - explicit SetBreakpoint(const std::vector& rawPacket): CommandPacket(rawPacket) { - this->init(); - }; + explicit SetBreakpoint(const std::vector& rawPacket); void handle(DebugSession& debugSession, TargetControllerConsole& targetControllerConsole) override; - - private: - void init(); }; } diff --git a/src/DebugServer/Gdb/CommandPackets/StepExecution.cpp b/src/DebugServer/Gdb/CommandPackets/StepExecution.cpp index d21a6f9f..dbd100ee 100644 --- a/src/DebugServer/Gdb/CommandPackets/StepExecution.cpp +++ b/src/DebugServer/Gdb/CommandPackets/StepExecution.cpp @@ -11,7 +11,9 @@ namespace Bloom::DebugServer::Gdb::CommandPackets using Exceptions::Exception; - void StepExecution::init() { + StepExecution::StepExecution(const std::vector& rawPacket) + : CommandPacket(rawPacket) + { if (this->data.size() > 1) { this->fromProgramCounter = static_cast( std::stoi(std::string(this->data.begin(), this->data.end()), nullptr, 16) diff --git a/src/DebugServer/Gdb/CommandPackets/StepExecution.hpp b/src/DebugServer/Gdb/CommandPackets/StepExecution.hpp index 97f59000..832af8fb 100644 --- a/src/DebugServer/Gdb/CommandPackets/StepExecution.hpp +++ b/src/DebugServer/Gdb/CommandPackets/StepExecution.hpp @@ -19,13 +19,8 @@ namespace Bloom::DebugServer::Gdb::CommandPackets */ std::optional fromProgramCounter; - explicit StepExecution(const std::vector& rawPacket): CommandPacket(rawPacket) { - init(); - }; + explicit StepExecution(const std::vector& rawPacket); void handle(DebugSession& debugSession, TargetControllerConsole& targetControllerConsole) override; - - private: - void init(); }; } diff --git a/src/DebugServer/Gdb/CommandPackets/SupportedFeaturesQuery.cpp b/src/DebugServer/Gdb/CommandPackets/SupportedFeaturesQuery.cpp index f16a319e..b700e33d 100644 --- a/src/DebugServer/Gdb/CommandPackets/SupportedFeaturesQuery.cpp +++ b/src/DebugServer/Gdb/CommandPackets/SupportedFeaturesQuery.cpp @@ -19,10 +19,12 @@ namespace Bloom::DebugServer::Gdb::CommandPackets using Bloom::Exceptions::Exception; using Gdb::Exceptions::ClientNotSupported; - void SupportedFeaturesQuery::init() { + SupportedFeaturesQuery::SupportedFeaturesQuery(const std::vector& rawPacket) + : CommandPacket(rawPacket) + { /* - * For qSupported packets, supported and unsupported GDB features are reported in the packet - * data, where each GDB feature is separated by a semicolon. + * For qSupported packets, supported and unsupported GDB features are reported in the packet data, where each + * GDB feature is separated by a semicolon. */ // The "qSupported:" prefix occupies 11 bytes diff --git a/src/DebugServer/Gdb/CommandPackets/SupportedFeaturesQuery.hpp b/src/DebugServer/Gdb/CommandPackets/SupportedFeaturesQuery.hpp index 8911a698..6b345de9 100644 --- a/src/DebugServer/Gdb/CommandPackets/SupportedFeaturesQuery.hpp +++ b/src/DebugServer/Gdb/CommandPackets/SupportedFeaturesQuery.hpp @@ -22,9 +22,7 @@ namespace Bloom::DebugServer::Gdb::CommandPackets class SupportedFeaturesQuery: public CommandPacket { public: - explicit SupportedFeaturesQuery(const std::vector& rawPacket): CommandPacket(rawPacket) { - this->init(); - }; + explicit SupportedFeaturesQuery(const std::vector& rawPacket); [[nodiscard]] bool isFeatureSupported(const Feature& feature) const { return this->supportedFeatures.find(feature) != this->supportedFeatures.end(); @@ -38,7 +36,5 @@ namespace Bloom::DebugServer::Gdb::CommandPackets private: std::set supportedFeatures; - - void init(); }; } diff --git a/src/DebugServer/Gdb/CommandPackets/WriteRegister.cpp b/src/DebugServer/Gdb/CommandPackets/WriteRegister.cpp index a3e8d7e2..48b0afe6 100644 --- a/src/DebugServer/Gdb/CommandPackets/WriteRegister.cpp +++ b/src/DebugServer/Gdb/CommandPackets/WriteRegister.cpp @@ -20,7 +20,9 @@ namespace Bloom::DebugServer::Gdb::CommandPackets using Exceptions::Exception; - void WriteRegister::init() { + WriteRegister::WriteRegister(const std::vector& rawPacket) + : CommandPacket(rawPacket) + { // The P packet updates a single register auto packet = std::string(this->data.begin(), this->data.end()); @@ -42,7 +44,9 @@ namespace Bloom::DebugServer::Gdb::CommandPackets Logger::debug("Handling WriteRegister packet"); try { - auto targetRegisterDescriptor = debugSession.targetDescriptor.getTargetRegisterDescriptorFromNumber(this->registerNumber); + auto targetRegisterDescriptor = debugSession.targetDescriptor.getTargetRegisterDescriptorFromNumber( + this->registerNumber + ); const auto valueSize = this->registerValue.size(); if (valueSize > 0 && valueSize > targetRegisterDescriptor.size) { @@ -57,7 +61,9 @@ namespace Bloom::DebugServer::Gdb::CommandPackets } if (this->registerValue.size() > targetRegisterDescriptor.size) { - const auto& gdbRegisterDescriptor = debugSession.targetDescriptor.getRegisterDescriptorFromNumber(this->registerNumber); + const auto& gdbRegisterDescriptor = debugSession.targetDescriptor.getRegisterDescriptorFromNumber( + this->registerNumber + ); throw Exception("Cannot set value for " + gdbRegisterDescriptor.name + " - value size exceeds register size." ); @@ -67,6 +73,7 @@ namespace Bloom::DebugServer::Gdb::CommandPackets targetControllerConsole.writeRegisters({ TargetRegister(targetRegisterDescriptor, this->registerValue) }); + debugSession.connection.writePacket(OkResponsePacket()); } catch (const Exception& exception) { diff --git a/src/DebugServer/Gdb/CommandPackets/WriteRegister.hpp b/src/DebugServer/Gdb/CommandPackets/WriteRegister.hpp index f38b21f9..ec543f43 100644 --- a/src/DebugServer/Gdb/CommandPackets/WriteRegister.hpp +++ b/src/DebugServer/Gdb/CommandPackets/WriteRegister.hpp @@ -17,13 +17,8 @@ namespace Bloom::DebugServer::Gdb::CommandPackets int registerNumber = 0; std::vector registerValue; - explicit WriteRegister(const std::vector& rawPacket): CommandPacket(rawPacket) { - init(); - }; + explicit WriteRegister(const std::vector& rawPacket); void handle(DebugSession& debugSession, TargetControllerConsole& targetControllerConsole) override; - - private: - void init(); }; }