General tidying, addressing issues found by static analysis tool.

This commit is contained in:
Nav
2021-06-22 23:52:31 +01:00
parent 69cee4d579
commit d365f6348b
151 changed files with 386 additions and 420 deletions

View File

@@ -37,7 +37,7 @@ namespace Bloom::DebugServers::Gdb::CommandPackets
class CommandPacket: public Packet
{
public:
CommandPacket(const std::vector<unsigned char>& rawPacket): Packet(rawPacket) {}
explicit CommandPacket(const std::vector<unsigned char>& rawPacket): Packet(rawPacket) {}
/**
* Double dispatches the packet to the appropriate overload of handleGdbPacket(), within the passed instance of

View File

@@ -8,7 +8,6 @@ using namespace Bloom::DebugServers::Gdb;
using namespace Bloom::DebugServers::Gdb::CommandPackets;
std::unique_ptr<CommandPacket> CommandPacketFactory::create(std::vector<unsigned char> rawPacket) {
if (rawPacket.size() == 5 && rawPacket[1] == 0x03) {
// This is an interrupt request - create a fake packet for it
return std::make_unique<CommandPackets::InterruptExecution>(rawPacket);
@@ -27,8 +26,8 @@ std::unique_ptr<CommandPacket> CommandPacketFactory::create(std::vector<unsigned
} else if (rawPacketString[1] == 'g' || rawPacketString[1] == 'p') {
return std::make_unique<CommandPackets::ReadGeneralRegisters>(rawPacket);
} else if (rawPacketString[1] == 'G' || rawPacketString[1] == 'P') {
return std::make_unique<CommandPackets::WriteGeneralRegisters>(rawPacket);
} else if (rawPacketString[1] == 'P') {
return std::make_unique<CommandPackets::WriteGeneralRegister>(rawPacket);
} else if (rawPacketString[1] == 'c') {
return std::make_unique<CommandPackets::ContinueExecution>(rawPacket);
@@ -127,4 +126,4 @@ std::vector<std::vector<unsigned char>> CommandPacketFactory::extractRawPackets(
}
return output;
}
}

View File

@@ -8,7 +8,7 @@
#include "InterruptExecution.hpp"
#include "SupportedFeaturesQuery.hpp"
#include "ReadGeneralRegisters.hpp"
#include "WriteGeneralRegisters.hpp"
#include "WriteGeneralRegister.hpp"
#include "ReadMemory.hpp"
#include "WriteMemory.hpp"
#include "StepExecution.hpp"

View File

@@ -27,10 +27,10 @@ namespace Bloom::DebugServers::Gdb::CommandPackets
*/
std::optional<std::uint32_t> fromProgramCounter;
ContinueExecution(std::vector<unsigned char> rawPacket): CommandPacket(rawPacket) {
explicit ContinueExecution(const std::vector<unsigned char>& rawPacket): CommandPacket(rawPacket) {
init();
}
virtual void dispatchToHandler(Gdb::GdbRspDebugServer& gdbRspDebugServer) override;
void dispatchToHandler(Gdb::GdbRspDebugServer& gdbRspDebugServer) override;
};
}

View File

@@ -15,8 +15,8 @@ namespace Bloom::DebugServers::Gdb::CommandPackets
class InterruptExecution: public CommandPacket
{
public:
InterruptExecution(std::vector<unsigned char> rawPacket): CommandPacket(rawPacket) {}
explicit InterruptExecution(const std::vector<unsigned char>& rawPacket): CommandPacket(rawPacket) {}
virtual void dispatchToHandler(Gdb::GdbRspDebugServer& gdbRspDebugServer) override;
void dispatchToHandler(Gdb::GdbRspDebugServer& gdbRspDebugServer) override;
};
}

View File

@@ -26,10 +26,10 @@ namespace Bloom::DebugServers::Gdb::CommandPackets
*/
std::optional<int> registerNumber;
ReadGeneralRegisters(std::vector<unsigned char> rawPacket): CommandPacket(rawPacket) {
explicit ReadGeneralRegisters(const std::vector<unsigned char>& rawPacket): CommandPacket(rawPacket) {
init();
};
virtual void dispatchToHandler(Gdb::GdbRspDebugServer& gdbRspDebugServer) override;
void dispatchToHandler(Gdb::GdbRspDebugServer& gdbRspDebugServer) override;
};
}

View File

@@ -24,17 +24,17 @@ namespace Bloom::DebugServers::Gdb::CommandPackets
*
* For an example of where GDB does this, see the AvrGdbRsp class.
*/
std::uint32_t startAddress;
std::uint32_t startAddress = 0;
/**
* Number of bytes to read.
*/
std::uint32_t bytes;
std::uint32_t bytes = 0;
ReadMemory(std::vector<unsigned char> rawPacket): CommandPacket(rawPacket) {
explicit ReadMemory(const std::vector<unsigned char>& rawPacket): CommandPacket(rawPacket) {
init();
};
virtual void dispatchToHandler(Gdb::GdbRspDebugServer& gdbRspDebugServer) override;
void dispatchToHandler(Gdb::GdbRspDebugServer& gdbRspDebugServer) override;
};
}

View File

@@ -32,12 +32,12 @@ namespace Bloom::DebugServers::Gdb::CommandPackets
/**
* Address at which the breakpoint should be located.
*/
std::uint32_t address;
std::uint32_t address = 0;
RemoveBreakpoint(std::vector<unsigned char> rawPacket): CommandPacket(rawPacket) {
explicit RemoveBreakpoint(const std::vector<unsigned char>& rawPacket): CommandPacket(rawPacket) {
this->init();
};
virtual void dispatchToHandler(Gdb::GdbRspDebugServer& gdbRspDebugServer) override;
void dispatchToHandler(Gdb::GdbRspDebugServer& gdbRspDebugServer) override;
};
}

View File

@@ -32,12 +32,12 @@ namespace Bloom::DebugServers::Gdb::CommandPackets
/**
* Address at which the breakpoint should be located.
*/
std::uint32_t address;
std::uint32_t address = 0;
SetBreakpoint(std::vector<unsigned char> rawPacket): CommandPacket(rawPacket) {
explicit SetBreakpoint(const std::vector<unsigned char>& rawPacket): CommandPacket(rawPacket) {
this->init();
};
virtual void dispatchToHandler(Gdb::GdbRspDebugServer& gdbRspDebugServer) override;
void dispatchToHandler(Gdb::GdbRspDebugServer& gdbRspDebugServer) override;
};
}

View File

@@ -21,10 +21,10 @@ namespace Bloom::DebugServers::Gdb::CommandPackets
*/
std::optional<size_t> fromProgramCounter;
StepExecution(std::vector<unsigned char> rawPacket): CommandPacket(rawPacket) {
explicit StepExecution(const std::vector<unsigned char>& rawPacket): CommandPacket(rawPacket) {
init();
};
virtual void dispatchToHandler(Gdb::GdbRspDebugServer& gdbRspDebugServer) override;
void dispatchToHandler(Gdb::GdbRspDebugServer& gdbRspDebugServer) override;
};
}

View File

@@ -27,18 +27,18 @@ namespace Bloom::DebugServers::Gdb::CommandPackets
void init();
public:
SupportedFeaturesQuery(std::vector<unsigned char> rawPacket): CommandPacket(rawPacket) {
explicit SupportedFeaturesQuery(const std::vector<unsigned char>& rawPacket): CommandPacket(rawPacket) {
this->init();
};
bool isFeatureSupported(const Feature& feature) const {
[[nodiscard]] bool isFeatureSupported(const Feature& feature) const {
return this->supportedFeatures.find(feature) != this->supportedFeatures.end();
}
const std::set<Feature>& getSupportedFeatures() const {
[[nodiscard]] const std::set<Feature>& getSupportedFeatures() const {
return this->supportedFeatures;
}
virtual void dispatchToHandler(Gdb::GdbRspDebugServer& gdbRspDebugServer) override;
void dispatchToHandler(Gdb::GdbRspDebugServer& gdbRspDebugServer) override;
};
}

View File

@@ -1,11 +1,11 @@
#include "WriteGeneralRegisters.hpp"
#include "WriteGeneralRegister.hpp"
#include "src/DebugServers/GdbRsp/GdbRspDebugServer.hpp"
#include "src/Exceptions/Exception.hpp"
using namespace Bloom::DebugServers::Gdb::CommandPackets;
using namespace Bloom::Exceptions;
void WriteGeneralRegisters::init() {
void WriteGeneralRegister::init() {
// The P packet updates a single register
auto packet = std::string(this->data.begin(), this->data.end());
@@ -13,16 +13,16 @@ void WriteGeneralRegisters::init() {
throw Exception("Invalid P command packet - insufficient data in packet.");
}
if (packet.find("=") == std::string::npos) {
if (packet.find('=') == std::string::npos) {
throw Exception("Invalid P command packet - unexpected format");
}
auto packetSegments = QString::fromStdString(packet).split("=");
this->registerNumber = packetSegments.front().mid(1).toUInt(nullptr, 16);
this->registerValue = this->hexToData(packetSegments.back().toStdString());
this->registerNumber = static_cast<int>(packetSegments.front().midRef(1).toUInt(nullptr, 16));
this->registerValue = Packet::hexToData(packetSegments.back().toStdString());
std::reverse(this->registerValue.begin(), this->registerValue.end());
}
void WriteGeneralRegisters::dispatchToHandler(Gdb::GdbRspDebugServer& gdbRspDebugServer) {
void WriteGeneralRegister::dispatchToHandler(Gdb::GdbRspDebugServer& gdbRspDebugServer) {
gdbRspDebugServer.handleGdbPacket(*this);
}

View File

@@ -0,0 +1,29 @@
#pragma once
#include <optional>
#include "CommandPacket.hpp"
#include "src/Targets/TargetRegister.hpp"
namespace Bloom::DebugServers::Gdb::CommandPackets
{
/**
* The WriteGeneralRegisters class implements the structure for "P" packets. Upon receiving this packet,
* server is expected to update a register value to the target.
*/
class WriteGeneralRegister: public CommandPacket
{
private:
void init();
public:
int registerNumber = 0;
std::vector<unsigned char> registerValue;
explicit WriteGeneralRegister(const std::vector<unsigned char>& rawPacket): CommandPacket(rawPacket) {
init();
};
void dispatchToHandler(Gdb::GdbRspDebugServer& gdbRspDebugServer) override;
};
}

View File

@@ -1,30 +0,0 @@
#pragma once
#include <optional>
#include "CommandPacket.hpp"
#include "src/Targets/TargetRegister.hpp"
namespace Bloom::DebugServers::Gdb::CommandPackets
{
/**
* The WriteGeneralRegisters class implements the structure for "G" and "P" packets. Upon receiving this packet,
* server is expected to write register values to the target.
*/
class WriteGeneralRegisters: public CommandPacket
{
private:
void init();
public:
Bloom::Targets::TargetRegisterMap registerMap;
int registerNumber;
std::vector<unsigned char> registerValue;
WriteGeneralRegisters(std::vector<unsigned char> rawPacket): CommandPacket(rawPacket) {
init();
};
virtual void dispatchToHandler(Gdb::GdbRspDebugServer& gdbRspDebugServer) override;
};
}

View File

@@ -40,7 +40,7 @@ void WriteMemory::init() {
throw Exception("Failed to parse write length from write memory packet data");
}
this->buffer = this->hexToData(lengthAndBufferSegments.at(1).toStdString());
this->buffer = Packet::hexToData(lengthAndBufferSegments.at(1).toStdString());
if (this->buffer.size() != bufferSize) {
throw Exception("Buffer size does not match length value given in write memory packet");

View File

@@ -22,14 +22,14 @@ namespace Bloom::DebugServers::Gdb::CommandPackets
* Like with the ReadMemory command packet, the start address carries additional bits that indicate
* the memory type.
*/
std::uint32_t startAddress;
std::uint32_t startAddress = 0;
Targets::TargetMemoryBuffer buffer;
WriteMemory(std::vector<unsigned char> rawPacket): CommandPacket(rawPacket) {
explicit WriteMemory(const std::vector<unsigned char>& rawPacket): CommandPacket(rawPacket) {
init();
};
virtual void dispatchToHandler(Gdb::GdbRspDebugServer& gdbRspDebugServer) override;
void dispatchToHandler(Gdb::GdbRspDebugServer& gdbRspDebugServer) override;
};
}