Removed unnecessary init() member functions in command packet classes.

This commit is contained in:
Nav
2022-04-03 17:25:21 +01:00
parent ffd57c94fa
commit d8a25fe264
14 changed files with 37 additions and 52 deletions

View File

@@ -10,7 +10,9 @@ namespace Bloom::DebugServer::Gdb::CommandPackets
using ResponsePackets::ErrorResponsePacket;
using Exceptions::Exception;
void ContinueExecution::init() {
ContinueExecution::ContinueExecution(const std::vector<unsigned char>& rawPacket)
: CommandPacket(rawPacket)
{
if (this->data.size() > 1) {
this->fromProgramCounter = static_cast<std::uint32_t>(
std::stoi(std::string(this->data.begin(), this->data.end()), nullptr, 16)

View File

@@ -24,13 +24,8 @@ namespace Bloom::DebugServer::Gdb::CommandPackets
*/
std::optional<std::uint32_t> fromProgramCounter;
explicit ContinueExecution(const std::vector<unsigned char>& rawPacket): CommandPacket(rawPacket) {
init();
}
explicit ContinueExecution(const std::vector<unsigned char>& rawPacket);
void handle(DebugSession& debugSession, TargetControllerConsole& targetControllerConsole) override;
private:
void init();
};
}

View File

@@ -17,7 +17,9 @@ namespace Bloom::DebugServer::Gdb::CommandPackets
using Exceptions::Exception;
void ReadRegisters::init() {
ReadRegisters::ReadRegisters(const std::vector<unsigned char>& rawPacket)
: CommandPacket(rawPacket)
{
if (this->data.size() >= 2 && this->data.front() == 'p') {
// This command packet is requesting a specific register
this->registerNumber = static_cast<size_t>(

View File

@@ -25,13 +25,8 @@ namespace Bloom::DebugServer::Gdb::CommandPackets
*/
std::optional<GdbRegisterNumberType> registerNumber;
explicit ReadRegisters(const std::vector<unsigned char>& rawPacket): CommandPacket(rawPacket) {
init();
};
explicit ReadRegisters(const std::vector<unsigned char>& rawPacket);
void handle(DebugSession& debugSession, TargetControllerConsole& targetControllerConsole) override;
private:
void init();
};
}

View File

@@ -19,7 +19,9 @@ namespace Bloom::DebugServer::Gdb::CommandPackets
using Exceptions::Exception;
void RemoveBreakpoint::init() {
RemoveBreakpoint::RemoveBreakpoint(const std::vector<unsigned char>& rawPacket)
: CommandPacket(rawPacket)
{
if (this->data.size() < 6) {
throw Exception("Unexpected RemoveBreakpoint packet size");
}

View File

@@ -26,13 +26,8 @@ namespace Bloom::DebugServer::Gdb::CommandPackets
*/
std::uint32_t address = 0;
explicit RemoveBreakpoint(const std::vector<unsigned char>& rawPacket): CommandPacket(rawPacket) {
this->init();
};
explicit RemoveBreakpoint(const std::vector<unsigned char>& rawPacket);
void handle(DebugSession& debugSession, TargetControllerConsole& targetControllerConsole) override;
private:
void init();
};
}

View File

@@ -19,7 +19,9 @@ namespace Bloom::DebugServer::Gdb::CommandPackets
using Exceptions::Exception;
void SetBreakpoint::init() {
SetBreakpoint::SetBreakpoint(const std::vector<unsigned char>& rawPacket)
: CommandPacket(rawPacket)
{
if (this->data.size() < 6) {
throw Exception("Unexpected SetBreakpoint packet size");
}

View File

@@ -26,13 +26,8 @@ namespace Bloom::DebugServer::Gdb::CommandPackets
*/
std::uint32_t address = 0;
explicit SetBreakpoint(const std::vector<unsigned char>& rawPacket): CommandPacket(rawPacket) {
this->init();
};
explicit SetBreakpoint(const std::vector<unsigned char>& rawPacket);
void handle(DebugSession& debugSession, TargetControllerConsole& targetControllerConsole) override;
private:
void init();
};
}

View File

@@ -11,7 +11,9 @@ namespace Bloom::DebugServer::Gdb::CommandPackets
using Exceptions::Exception;
void StepExecution::init() {
StepExecution::StepExecution(const std::vector<unsigned char>& rawPacket)
: CommandPacket(rawPacket)
{
if (this->data.size() > 1) {
this->fromProgramCounter = static_cast<std::uint32_t>(
std::stoi(std::string(this->data.begin(), this->data.end()), nullptr, 16)

View File

@@ -19,13 +19,8 @@ namespace Bloom::DebugServer::Gdb::CommandPackets
*/
std::optional<std::size_t> fromProgramCounter;
explicit StepExecution(const std::vector<unsigned char>& rawPacket): CommandPacket(rawPacket) {
init();
};
explicit StepExecution(const std::vector<unsigned char>& rawPacket);
void handle(DebugSession& debugSession, TargetControllerConsole& targetControllerConsole) override;
private:
void init();
};
}

View File

@@ -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<unsigned char>& 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

View File

@@ -22,9 +22,7 @@ namespace Bloom::DebugServer::Gdb::CommandPackets
class SupportedFeaturesQuery: public CommandPacket
{
public:
explicit SupportedFeaturesQuery(const std::vector<unsigned char>& rawPacket): CommandPacket(rawPacket) {
this->init();
};
explicit SupportedFeaturesQuery(const std::vector<unsigned char>& 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<Feature> supportedFeatures;
void init();
};
}

View File

@@ -20,7 +20,9 @@ namespace Bloom::DebugServer::Gdb::CommandPackets
using Exceptions::Exception;
void WriteRegister::init() {
WriteRegister::WriteRegister(const std::vector<unsigned char>& 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) {

View File

@@ -17,13 +17,8 @@ namespace Bloom::DebugServer::Gdb::CommandPackets
int registerNumber = 0;
std::vector<unsigned char> registerValue;
explicit WriteRegister(const std::vector<unsigned char>& rawPacket): CommandPacket(rawPacket) {
init();
};
explicit WriteRegister(const std::vector<unsigned char>& rawPacket);
void handle(DebugSession& debugSession, TargetControllerConsole& targetControllerConsole) override;
private:
void init();
};
}