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

@@ -83,7 +83,6 @@ add_executable(Bloom
src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/EdbgInterface.cpp src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/EdbgInterface.cpp
src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.cpp src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.cpp
src/Targets/Target.cpp
src/Targets/TargetDescription/TargetDescriptionFile.cpp src/Targets/TargetDescription/TargetDescriptionFile.cpp
src/Targets/Microchip/AVR/AVR8/Avr8.cpp src/Targets/Microchip/AVR/AVR8/Avr8.cpp
src/Targets/Microchip/AVR/AVR8/Mega/Mega.cpp src/Targets/Microchip/AVR/AVR8/Mega/Mega.cpp
@@ -96,7 +95,7 @@ add_executable(Bloom
src/DebugServers/GdbRsp/CommandPackets/CommandPacketFactory.cpp src/DebugServers/GdbRsp/CommandPackets/CommandPacketFactory.cpp
src/DebugServers/GdbRsp/CommandPackets/SupportedFeaturesQuery.cpp src/DebugServers/GdbRsp/CommandPackets/SupportedFeaturesQuery.cpp
src/DebugServers/GdbRsp/CommandPackets/ReadGeneralRegisters.cpp src/DebugServers/GdbRsp/CommandPackets/ReadGeneralRegisters.cpp
src/DebugServers/GdbRsp/CommandPackets/WriteGeneralRegisters.cpp src/DebugServers/GdbRsp/CommandPackets/WriteGeneralRegister.cpp
src/DebugServers/GdbRsp/CommandPackets/ContinueExecution.cpp src/DebugServers/GdbRsp/CommandPackets/ContinueExecution.cpp
src/DebugServers/GdbRsp/CommandPackets/StepExecution.cpp src/DebugServers/GdbRsp/CommandPackets/StepExecution.cpp
src/DebugServers/GdbRsp/CommandPackets/InterruptExecution.cpp src/DebugServers/GdbRsp/CommandPackets/InterruptExecution.cpp

View File

@@ -3,7 +3,6 @@
#include <QtCore> #include <QtCore>
#include <thread> #include <thread>
#include <QJsonDocument> #include <QJsonDocument>
#include <QCoreApplication>
#include <unistd.h> #include <unistd.h>
#include <filesystem> #include <filesystem>

View File

@@ -1,5 +1,4 @@
#include <variant> #include <variant>
#include <cstdint>
#include "DebugServer.hpp" #include "DebugServer.hpp"
#include "src/Exceptions/InvalidConfig.hpp" #include "src/Exceptions/InvalidConfig.hpp"

View File

@@ -98,7 +98,7 @@ namespace Bloom::DebugServers
virtual void close() = 0; virtual void close() = 0;
public: public:
DebugServer(EventManager& eventManager): eventManager(eventManager) {}; explicit DebugServer(EventManager& eventManager): eventManager(eventManager) {};
void setApplicationConfig(const ApplicationConfig& applicationConfig) { void setApplicationConfig(const ApplicationConfig& applicationConfig) {
this->applicationConfig = applicationConfig; this->applicationConfig = applicationConfig;

View File

@@ -116,10 +116,10 @@ namespace Bloom::DebugServers::Gdb
}; };
public: public:
AvrGdbRsp(EventManager& eventManager): GdbRspDebugServer(eventManager) {}; explicit AvrGdbRsp(EventManager& eventManager): GdbRspDebugServer(eventManager) {};
std::string getName() const override { std::string getName() const override {
return "AVR GDB Remote Serial Protocol Debug Server"; return "AVR GDB Remote Serial Protocol Debug Server";
} }
}; };
} }

View File

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

View File

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

View File

@@ -27,10 +27,10 @@ namespace Bloom::DebugServers::Gdb::CommandPackets
*/ */
std::optional<std::uint32_t> fromProgramCounter; 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(); 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 class InterruptExecution: public CommandPacket
{ {
public: 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; std::optional<int> registerNumber;
ReadGeneralRegisters(std::vector<unsigned char> rawPacket): CommandPacket(rawPacket) { explicit ReadGeneralRegisters(const std::vector<unsigned char>& rawPacket): CommandPacket(rawPacket) {
init(); 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. * 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. * 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(); 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. * 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(); 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. * 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(); 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; std::optional<size_t> fromProgramCounter;
StepExecution(std::vector<unsigned char> rawPacket): CommandPacket(rawPacket) { explicit StepExecution(const std::vector<unsigned char>& rawPacket): CommandPacket(rawPacket) {
init(); 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(); void init();
public: public:
SupportedFeaturesQuery(std::vector<unsigned char> rawPacket): CommandPacket(rawPacket) { explicit SupportedFeaturesQuery(const std::vector<unsigned char>& rawPacket): CommandPacket(rawPacket) {
this->init(); this->init();
}; };
bool isFeatureSupported(const Feature& feature) const { [[nodiscard]] bool isFeatureSupported(const Feature& feature) const {
return this->supportedFeatures.find(feature) != this->supportedFeatures.end(); return this->supportedFeatures.find(feature) != this->supportedFeatures.end();
} }
const std::set<Feature>& getSupportedFeatures() const { [[nodiscard]] const std::set<Feature>& getSupportedFeatures() const {
return this->supportedFeatures; 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/DebugServers/GdbRsp/GdbRspDebugServer.hpp"
#include "src/Exceptions/Exception.hpp" #include "src/Exceptions/Exception.hpp"
using namespace Bloom::DebugServers::Gdb::CommandPackets; using namespace Bloom::DebugServers::Gdb::CommandPackets;
using namespace Bloom::Exceptions; using namespace Bloom::Exceptions;
void WriteGeneralRegisters::init() { void WriteGeneralRegister::init() {
// The P packet updates a single register // The P packet updates a single register
auto packet = std::string(this->data.begin(), this->data.end()); 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."); 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"); throw Exception("Invalid P command packet - unexpected format");
} }
auto packetSegments = QString::fromStdString(packet).split("="); auto packetSegments = QString::fromStdString(packet).split("=");
this->registerNumber = packetSegments.front().mid(1).toUInt(nullptr, 16); this->registerNumber = static_cast<int>(packetSegments.front().midRef(1).toUInt(nullptr, 16));
this->registerValue = this->hexToData(packetSegments.back().toStdString()); this->registerValue = Packet::hexToData(packetSegments.back().toStdString());
std::reverse(this->registerValue.begin(), this->registerValue.end()); std::reverse(this->registerValue.begin(), this->registerValue.end());
} }
void WriteGeneralRegisters::dispatchToHandler(Gdb::GdbRspDebugServer& gdbRspDebugServer) { void WriteGeneralRegister::dispatchToHandler(Gdb::GdbRspDebugServer& gdbRspDebugServer) {
gdbRspDebugServer.handleGdbPacket(*this); 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"); 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) { if (this->buffer.size() != bufferSize) {
throw Exception("Buffer size does not match length value given in write memory packet"); 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 * Like with the ReadMemory command packet, the start address carries additional bits that indicate
* the memory type. * the memory type.
*/ */
std::uint32_t startAddress; std::uint32_t startAddress = 0;
Targets::TargetMemoryBuffer buffer; Targets::TargetMemoryBuffer buffer;
WriteMemory(std::vector<unsigned char> rawPacket): CommandPacket(rawPacket) { explicit WriteMemory(const std::vector<unsigned char>& rawPacket): CommandPacket(rawPacket) {
init(); init();
}; };
virtual void dispatchToHandler(Gdb::GdbRspDebugServer& gdbRspDebugServer) override; void dispatchToHandler(Gdb::GdbRspDebugServer& gdbRspDebugServer) override;
}; };
} }

View File

@@ -1,6 +1,6 @@
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/epoll.h> #include <sys/epoll.h>
#include <errno.h> #include <cerrno>
#include <fcntl.h> #include <fcntl.h>
#include "src/Logger/Logger.hpp" #include "src/Logger/Logger.hpp"
@@ -117,7 +117,7 @@ void Connection::writePacket(const ResponsePacket& packet) {
std::vector<unsigned char> Connection::read(size_t bytes, bool interruptible, std::optional<int> msTimeout) { std::vector<unsigned char> Connection::read(size_t bytes, bool interruptible, std::optional<int> msTimeout) {
auto output = std::vector<unsigned char>(); auto output = std::vector<unsigned char>();
constexpr size_t bufferSize = 1024; constexpr size_t bufferSize = 1024;
std::array<unsigned char, bufferSize> buffer; std::array<unsigned char, bufferSize> buffer = {};
ssize_t bytesRead; ssize_t bytesRead;
if (interruptible) { if (interruptible) {

View File

@@ -1,6 +1,7 @@
#pragma once #pragma once
#include <cstdint> #include <cstdint>
#include <utility>
#include <vector> #include <vector>
#include <netinet/in.h> #include <netinet/in.h>
#include <queue> #include <queue>
@@ -83,8 +84,8 @@ namespace Bloom::DebugServers::Gdb
*/ */
bool waitingForBreak = false; bool waitingForBreak = false;
Connection(std::shared_ptr<EventNotifier> interruptEventNotifier) explicit Connection(std::shared_ptr<EventNotifier> interruptEventNotifier)
: interruptEventNotifier(interruptEventNotifier) {}; : interruptEventNotifier(std::move(interruptEventNotifier)) {};
/** /**
* Accepts a connection on serverSocketFileDescriptor. * Accepts a connection on serverSocketFileDescriptor.
@@ -104,7 +105,7 @@ namespace Bloom::DebugServers::Gdb
* @return * @return
*/ */
std::string getIpAddress() { std::string getIpAddress() {
std::array<char, INET_ADDRSTRLEN> ipAddress; std::array<char, INET_ADDRSTRLEN> ipAddress = {};
if (::inet_ntop(AF_INET, &(socketAddress.sin_addr), ipAddress.data(), INET_ADDRSTRLEN) == nullptr) { if (::inet_ntop(AF_INET, &(socketAddress.sin_addr), ipAddress.data(), INET_ADDRSTRLEN) == nullptr) {
throw Exceptions::Exception("Failed to convert client IP address to text form."); throw Exceptions::Exception("Failed to convert client IP address to text form.");
@@ -127,7 +128,7 @@ namespace Bloom::DebugServers::Gdb
*/ */
void writePacket(const ResponsePackets::ResponsePacket& packet); void writePacket(const ResponsePackets::ResponsePacket& packet);
int getMaxPacketSize() { [[nodiscard]] int getMaxPacketSize() const {
return this->maxPacketSize; return this->maxPacketSize;
} }
}; };

View File

@@ -330,7 +330,7 @@ void GdbRspDebugServer::handleGdbPacket(CommandPackets::ReadGeneralRegisters& pa
} }
} }
void GdbRspDebugServer::handleGdbPacket(CommandPackets::WriteGeneralRegisters& packet) { void GdbRspDebugServer::handleGdbPacket(CommandPackets::WriteGeneralRegister& packet) {
Logger::debug("Handling WriteGeneralRegisters packet"); Logger::debug("Handling WriteGeneralRegisters packet");
try { try {

View File

@@ -200,11 +200,11 @@ namespace Bloom::DebugServers::Gdb
virtual void handleGdbPacket(CommandPackets::ReadGeneralRegisters& packet); virtual void handleGdbPacket(CommandPackets::ReadGeneralRegisters& packet);
/** /**
* Handles the write general registers ("G" and "P") command packet. * Handles the write general register ("P") command packet.
* *
* @param packet * @param packet
*/ */
virtual void handleGdbPacket(CommandPackets::WriteGeneralRegisters& packet); virtual void handleGdbPacket(CommandPackets::WriteGeneralRegister& packet);
/** /**
* Handles the continue execution ("c") command packet. * Handles the continue execution ("c") command packet.

View File

@@ -28,11 +28,11 @@ namespace Bloom::DebugServers::Gdb
} }
public: public:
Packet() = default; Packet() = default;
Packet(const std::vector<unsigned char>& rawPacket) { explicit Packet(const std::vector<unsigned char>& rawPacket) {
this->init(rawPacket); this->init(rawPacket);
} }
virtual std::vector<unsigned char> getData() const { [[nodiscard]] virtual std::vector<unsigned char> getData() const {
return this->data; return this->data;
} }
@@ -45,7 +45,7 @@ namespace Bloom::DebugServers::Gdb
* *
* @return * @return
*/ */
std::vector<unsigned char> toRawPacket() const { [[nodiscard]] std::vector<unsigned char> toRawPacket() const {
std::vector<unsigned char> packet = {'$'}; std::vector<unsigned char> packet = {'$'};
auto data = this->getData(); auto data = this->getData();
@@ -90,7 +90,7 @@ namespace Bloom::DebugServers::Gdb
* @param data * @param data
* @return * @return
*/ */
static std::string dataToHex(std::vector<unsigned char> data) { static std::string dataToHex(const std::vector<unsigned char>& data) {
std::stringstream stream; std::stringstream stream;
stream << std::hex << std::setfill('0'); stream << std::hex << std::setfill('0');

View File

@@ -18,7 +18,7 @@ namespace Bloom::DebugServers::Gdb::ResponsePackets
public: public:
Ok() = default; Ok() = default;
std::vector<unsigned char> getData() const override { [[nodiscard]] std::vector<unsigned char> getData() const override {
return {'O', 'K'}; return {'O', 'K'};
} }
}; };

View File

@@ -1,6 +1,7 @@
#pragma once #pragma once
#include <set> #include <set>
#include <utility>
#include "ResponsePacket.hpp" #include "ResponsePacket.hpp"
#include "../Feature.hpp" #include "../Feature.hpp"
@@ -17,9 +18,9 @@ namespace Bloom::DebugServers::Gdb::ResponsePackets
public: public:
SupportedFeaturesResponse() = default; SupportedFeaturesResponse() = default;
SupportedFeaturesResponse(const std::set<std::pair<Feature, std::optional<std::string>>>& supportedFeatures) explicit SupportedFeaturesResponse(std::set<std::pair<Feature, std::optional<std::string>>> supportedFeatures)
: supportedFeatures(supportedFeatures) {}; : supportedFeatures(std::move(supportedFeatures)) {};
std::vector<unsigned char> getData() const override; [[nodiscard]] std::vector<unsigned char> getData() const override;
}; };
} }

View File

@@ -18,10 +18,10 @@ namespace Bloom::DebugServers::Gdb::ResponsePackets
std::optional<Targets::TargetRegisterMap> registerMap; std::optional<Targets::TargetRegisterMap> registerMap;
std::optional<StopReason> stopReason; std::optional<StopReason> stopReason;
TargetStopped(Signal signal): signal(signal) {} explicit TargetStopped(Signal signal): signal(signal) {}
std::vector<unsigned char> getData() const override { [[nodiscard]] std::vector<unsigned char> getData() const override {
std::string output = "T" + this->dataToHex({static_cast<unsigned char>(this->signal)}); std::string output = "T" + Packet::dataToHex({static_cast<unsigned char>(this->signal)});
if (this->stopReason.has_value()) { if (this->stopReason.has_value()) {
auto stopReasonMapping = getStopReasonToNameMapping(); auto stopReasonMapping = getStopReasonToNameMapping();
@@ -34,8 +34,8 @@ namespace Bloom::DebugServers::Gdb::ResponsePackets
if (this->registerMap.has_value()) { if (this->registerMap.has_value()) {
for (const auto& [registerId, registerValue] : this->registerMap.value()) { for (const auto& [registerId, registerValue] : this->registerMap.value()) {
output += this->dataToHex({static_cast<unsigned char>(registerId)}); output += Packet::dataToHex({static_cast<unsigned char>(registerId)});
output += ":" + this->dataToHex(registerValue.value) + ";"; output += ":" + Packet::dataToHex(registerValue.value) + ";";
} }
} }

View File

@@ -23,7 +23,7 @@ namespace Bloom
} }
public: public:
bool isInitialised() const { [[nodiscard]] bool isInitialised() const {
return this->initialised; return this->initialised;
} }

View File

@@ -2,8 +2,7 @@
using namespace Bloom::DebugToolDrivers::Protocols::CmsisDap; using namespace Bloom::DebugToolDrivers::Protocols::CmsisDap;
Command::operator std::vector<unsigned char> () const Command::operator std::vector<unsigned char> () const {
{
auto rawCommand = std::vector<unsigned char>(1, this->getCommandId()); auto rawCommand = std::vector<unsigned char>(1, this->getCommandId());
auto commandData = this->getData(); auto commandData = this->getData();
rawCommand.insert(rawCommand.end(), commandData.begin(), commandData.end()); rawCommand.insert(rawCommand.end(), commandData.begin(), commandData.end());

View File

@@ -12,7 +12,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap
std::vector<unsigned char> data; std::vector<unsigned char> data;
public: public:
unsigned char getCommandId() const { [[nodiscard]] unsigned char getCommandId() const {
return this->commandId; return this->commandId;
} }
@@ -20,7 +20,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap
this->commandId = commandId; this->commandId = commandId;
} }
virtual std::vector<unsigned char> getData() const { [[nodiscard]] virtual std::vector<unsigned char> getData() const {
return this->data; return this->data;
} }
@@ -33,7 +33,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap
return (int) (1 + this->getData().size()); return (int) (1 + this->getData().size());
} }
std::uint16_t getDataSize() const { [[nodiscard]] std::uint16_t getDataSize() const {
return (std::uint16_t) this->getData().size(); return (std::uint16_t) this->getData().size();
} }
@@ -46,7 +46,5 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap
explicit virtual operator std::vector<unsigned char>() const; explicit virtual operator std::vector<unsigned char>() const;
virtual ~Command() = default; virtual ~Command() = default;
}; };
} }

View File

@@ -3,13 +3,11 @@
using namespace Bloom::DebugToolDrivers::Protocols::CmsisDap; using namespace Bloom::DebugToolDrivers::Protocols::CmsisDap;
void Response::init(const std::vector<unsigned char>& rawResponse) void Response::init(const std::vector<unsigned char>& rawResponse) {
{ if (rawResponse.empty()) {
if (rawResponse.size() < 1) {
throw Exceptions::Exception("Failed to process CMSIS-DAP response - invalid response"); throw Exceptions::Exception("Failed to process CMSIS-DAP response - invalid response");
} }
this->setResponseId(rawResponse[0]); this->setResponseId(rawResponse[0]);
this->setData(std::vector<unsigned char>(rawResponse.begin() + 1, rawResponse.end())); this->setData(std::vector<unsigned char>(rawResponse.begin() + 1, rawResponse.end()));
} }

View File

@@ -24,11 +24,11 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap
Response() = default; Response() = default;
virtual void init(const std::vector<unsigned char>& rawResponse); virtual void init(const std::vector<unsigned char>& rawResponse);
unsigned char getResponseId() const { [[nodiscard]] unsigned char getResponseId() const {
return this->responseId; return this->responseId;
} }
virtual const std::vector<unsigned char>& getData() const { [[nodiscard]] virtual const std::vector<unsigned char>& getData() const {
return this->data; return this->data;
} }

View File

@@ -2,8 +2,7 @@
using namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr; using namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr;
std::vector<unsigned char> AvrCommand::getData() const std::vector<unsigned char> AvrCommand::getData() const {
{
std::vector<unsigned char> data; std::vector<unsigned char> data;
auto commandPacket = this->getCommandPacket(); auto commandPacket = this->getCommandPacket();
std::size_t commandPacketSize = commandPacket.size(); std::size_t commandPacketSize = commandPacket.size();
@@ -21,4 +20,3 @@ std::vector<unsigned char> AvrCommand::getData() const
return data; return data;
} }

View File

@@ -24,9 +24,9 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
* *
* @return * @return
*/ */
std::vector<unsigned char> getData() const override; [[nodiscard]] std::vector<unsigned char> getData() const override;
size_t getFragmentNumber() const { [[nodiscard]] size_t getFragmentNumber() const {
return this->fragmentNumber; return this->fragmentNumber;
} }
@@ -34,7 +34,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
this->fragmentNumber = fragmentNumber; this->fragmentNumber = fragmentNumber;
} }
size_t getFragmentCount() const { [[nodiscard]] size_t getFragmentCount() const {
return this->fragmentCount; return this->fragmentCount;
} }
@@ -42,7 +42,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
this->fragmentCount = fragmentCount; this->fragmentCount = fragmentCount;
} }
const std::vector<unsigned char>& getCommandPacket() const { [[nodiscard]] const std::vector<unsigned char>& getCommandPacket() const {
return this->commandPacket; return this->commandPacket;
} }
@@ -50,5 +50,4 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
this->commandPacket = commandPacket; this->commandPacket = commandPacket;
} }
}; };
} }

View File

@@ -20,7 +20,7 @@ void AvrEvent::init(const std::vector<unsigned char>& rawResponse) {
} }
// Response size is two bytes, MSB // Response size is two bytes, MSB
size_t responsePacketSize = static_cast<size_t>((responseData[0] << 8) | responseData[1]); auto responsePacketSize = static_cast<size_t>((responseData[0] << 8) | responseData[1]);
if (responseData.size() < 2) { if (responseData.size() < 2) {
// All AVR_EVT responses should consist of at least two bytes (excluding the AVR_EVT ID) // All AVR_EVT responses should consist of at least two bytes (excluding the AVR_EVT ID)
@@ -42,8 +42,7 @@ void AvrEvent::init(const std::vector<unsigned char>& rawResponse) {
this->setEventData(eventData); this->setEventData(eventData);
if (eventData.size() >= 1) { if (!eventData.empty()) {
this->eventId = eventData[0]; this->eventId = eventData[0];
} }
} }

View File

@@ -23,7 +23,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
class AvrEvent: public Response class AvrEvent: public Response
{ {
private: private:
unsigned char eventId; unsigned char eventId = 0;
std::vector<unsigned char> eventData; std::vector<unsigned char> eventData;
@@ -48,15 +48,15 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
void init(const std::vector<unsigned char>& rawResponse) override; void init(const std::vector<unsigned char>& rawResponse) override;
const std::vector<unsigned char>& getEventData() const { [[nodiscard]] const std::vector<unsigned char>& getEventData() const {
return this->eventData; return this->eventData;
} }
size_t getEventDataSize() const { [[nodiscard]] size_t getEventDataSize() const {
return this->eventData.size(); return this->eventData.size();
} }
AvrEventId getEventId() { [[nodiscard]] AvrEventId getEventId() const {
return static_cast<AvrEventId>(this->eventId); return static_cast<AvrEventId>(this->eventId);
} }
}; };

View File

@@ -44,15 +44,15 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
void init(const std::vector<unsigned char>& rawResponse) override; void init(const std::vector<unsigned char>& rawResponse) override;
std::uint8_t getFragmentNumber() const { [[nodiscard]] std::uint8_t getFragmentNumber() const {
return this->fragmentNumber; return this->fragmentNumber;
} }
std::uint8_t getFragmentCount() const { [[nodiscard]] std::uint8_t getFragmentCount() const {
return this->fragmentCount; return this->fragmentCount;
} }
const std::vector<unsigned char>& getResponsePacket() const { [[nodiscard]] const std::vector<unsigned char>& getResponsePacket() const {
return this->responsePacket; return this->responsePacket;
} }
}; };

View File

@@ -11,13 +11,13 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
public: public:
ActivatePhysical() = default; ActivatePhysical() = default;
ActivatePhysical(bool reset): reset(reset) {}; explicit ActivatePhysical(bool reset): reset(reset) {};
void setReset(bool reset) { void setReset(bool reset) {
this->reset = reset; this->reset = reset;
} }
std::vector<unsigned char> getPayload() const override { [[nodiscard]] std::vector<unsigned char> getPayload() const override {
/* /*
* The activate physical command consists of 3 bytes: * The activate physical command consists of 3 bytes:
* 1. Command ID (0x10) * 1. Command ID (0x10)

View File

@@ -11,13 +11,13 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
public: public:
Attach() = default; Attach() = default;
Attach(bool breakAfterAttach): breakAfterAttach(breakAfterAttach) {}; explicit Attach(bool breakAfterAttach): breakAfterAttach(breakAfterAttach) {};
void setBreadAfterAttach(bool breakAfterAttach) { void setBreadAfterAttach(bool breakAfterAttach) {
this->breakAfterAttach = breakAfterAttach; this->breakAfterAttach = breakAfterAttach;
} }
std::vector<unsigned char> getPayload() const override { [[nodiscard]] std::vector<unsigned char> getPayload() const override {
/* /*
* The attach command consists of 3 bytes: * The attach command consists of 3 bytes:
* 1. Command ID (0x13) * 1. Command ID (0x13)

View File

@@ -13,8 +13,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
using ResponseFrameType = ResponseFrames::Avr8Generic::Avr8GenericResponseFrame; using ResponseFrameType = ResponseFrames::Avr8Generic::Avr8GenericResponseFrame;
Avr8GenericCommandFrame() { Avr8GenericCommandFrame() {
this->setProtocolHandlerId(ProtocolHandlerId::Avr8Generic); this->setProtocolHandlerId(ProtocolHandlerId::AVR8_GENERIC);
} }
}; };
} }

View File

@@ -24,5 +24,4 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
init(); init();
}; };
}; };
} }

View File

@@ -1,6 +1,7 @@
#pragma once #pragma once
#include <cstdint> #include <cstdint>
#include <utility>
#include "Avr8GenericCommandFrame.hpp" #include "Avr8GenericCommandFrame.hpp"
@@ -14,13 +15,13 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
public: public:
ClearSoftwareBreakpoints() = default; ClearSoftwareBreakpoints() = default;
ClearSoftwareBreakpoints(const std::vector<std::uint32_t>& addresses): addresses(addresses) {} explicit ClearSoftwareBreakpoints(std::vector<std::uint32_t> addresses): addresses(std::move(addresses)) {}
void setAddresses(const std::vector<std::uint32_t>& addresses) { void setAddresses(const std::vector<std::uint32_t>& addresses) {
this->addresses = addresses; this->addresses = addresses;
} }
virtual std::vector<unsigned char> getPayload() const override { [[nodiscard]] std::vector<unsigned char> getPayload() const override {
/* /*
* The clear software breakpoints command consists of 2 bytes + 4*n bytes, where n is the number * The clear software breakpoints command consists of 2 bytes + 4*n bytes, where n is the number
* of breakpoints to clear: * of breakpoints to clear:
@@ -43,5 +44,4 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
return output; return output;
} }
}; };
} }

View File

@@ -24,5 +24,4 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
init(); init();
}; };
}; };
} }

View File

@@ -24,5 +24,4 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
init(); init();
}; };
}; };
} }

View File

@@ -24,5 +24,4 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
init(); init();
}; };
}; };
} }

View File

@@ -27,5 +27,4 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
init(); init();
}; };
}; };
} }

View File

@@ -10,12 +10,12 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
{ {
private: private:
Avr8EdbgParameter parameter; Avr8EdbgParameter parameter;
std::uint8_t size; std::uint8_t size = 0;
public: public:
GetParameter() = default; GetParameter() = default;
GetParameter(const Avr8EdbgParameter& parameter) { explicit GetParameter(const Avr8EdbgParameter& parameter) {
this->setParameter(parameter); this->setParameter(parameter);
} }
@@ -31,7 +31,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
this->size = size; this->size = size;
} }
virtual std::vector<unsigned char> getPayload() const override { [[nodiscard]] std::vector<unsigned char> getPayload() const override {
/* /*
* The get param command consists of 5 bytes: * The get param command consists of 5 bytes:
* 1. Command ID (0x02) * 1. Command ID (0x02)
@@ -50,5 +50,4 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
return output; return output;
} }
}; };
} }

View File

@@ -27,5 +27,4 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
init(); init();
}; };
}; };
} }

View File

@@ -10,7 +10,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
class ReadMemory: public Avr8GenericCommandFrame class ReadMemory: public Avr8GenericCommandFrame
{ {
private: private:
Avr8MemoryType type; Avr8MemoryType type = Avr8MemoryType::SRAM;
std::uint32_t address = 0; std::uint32_t address = 0;
std::uint32_t bytes = 0; std::uint32_t bytes = 0;
@@ -31,7 +31,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
this->bytes = bytes; this->bytes = bytes;
} }
virtual std::vector<unsigned char> getPayload() const override { [[nodiscard]] std::vector<unsigned char> getPayload() const override {
/* /*
* The read memory command consists of 11 bytes: * The read memory command consists of 11 bytes:
* 1. Command ID (0x21) * 1. Command ID (0x21)
@@ -56,5 +56,4 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
return output; return output;
} }
}; };
} }

View File

@@ -11,13 +11,13 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
public: public:
Reset() = default; Reset() = default;
Reset(bool stopAtMainAddress): stopAtMainAddress(stopAtMainAddress) {}; explicit Reset(bool stopAtMainAddress): stopAtMainAddress(stopAtMainAddress) {};
void setStopAtMainAddress(bool stopAtMainAddress) { void setStopAtMainAddress(bool stopAtMainAddress) {
this->stopAtMainAddress = stopAtMainAddress; this->stopAtMainAddress = stopAtMainAddress;
} }
virtual std::vector<unsigned char> getPayload() const override { [[nodiscard]] std::vector<unsigned char> getPayload() const override {
/* /*
* The reset command consists of 3 bytes: * The reset command consists of 3 bytes:
* 1. Command ID (0x30) * 1. Command ID (0x30)
@@ -32,5 +32,4 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
return output; return output;
} }
}; };
} }

View File

@@ -24,5 +24,4 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
init(); init();
}; };
}; };
} }

View File

@@ -9,18 +9,18 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
class RunTo: public Avr8GenericCommandFrame class RunTo: public Avr8GenericCommandFrame
{ {
private: private:
std::uint32_t address; std::uint32_t address = 0;
public: public:
RunTo() = default; RunTo() = default;
RunTo(const std::uint32_t& address): address(address) {} explicit RunTo(const std::uint32_t& address): address(address) {}
void setAddress(const std::uint32_t& address) { void setAddress(const std::uint32_t& address) {
this->address = address; this->address = address;
} }
virtual std::vector<unsigned char> getPayload() const override { [[nodiscard]] std::vector<unsigned char> getPayload() const override {
/* /*
* The run-to command consists of 6 bytes: * The run-to command consists of 6 bytes:
* *

View File

@@ -13,7 +13,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
public: public:
SetParameter() = default; SetParameter() = default;
SetParameter(const Avr8EdbgParameter& parameter) { explicit SetParameter(const Avr8EdbgParameter& parameter) {
this->setParameter(parameter); this->setParameter(parameter);
} }
@@ -37,7 +37,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
this->value.resize(1, value); this->value.resize(1, value);
} }
virtual std::vector<unsigned char> getPayload() const override { [[nodiscard]] std::vector<unsigned char> getPayload() const override {
/* /*
* The set param command consists of this->value.size() + 5 bytes. The first five bytes consist of: * The set param command consists of this->value.size() + 5 bytes. The first five bytes consist of:
* 1. Command ID (0x01) * 1. Command ID (0x01)
@@ -58,5 +58,4 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
return output; return output;
} }
}; };
} }

View File

@@ -12,9 +12,9 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
std::uint32_t programCounter = 0; std::uint32_t programCounter = 0;
public: public:
SetProgramCounter(std::uint32_t programCounter): programCounter(programCounter) {} explicit SetProgramCounter(std::uint32_t programCounter): programCounter(programCounter) {}
virtual std::vector<unsigned char> getPayload() const override { [[nodiscard]] std::vector<unsigned char> getPayload() const override {
/* /*
* The PC write command consists of 6 bytes: * The PC write command consists of 6 bytes:
* 1. Command ID (0x01) * 1. Command ID (0x01)

View File

@@ -1,6 +1,7 @@
#pragma once #pragma once
#include <cstdint> #include <cstdint>
#include <utility>
#include "Avr8GenericCommandFrame.hpp" #include "Avr8GenericCommandFrame.hpp"
@@ -14,13 +15,13 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
public: public:
SetSoftwareBreakpoints() = default; SetSoftwareBreakpoints() = default;
SetSoftwareBreakpoints(const std::vector<std::uint32_t>& addresses): addresses(addresses) {} explicit SetSoftwareBreakpoints(std::vector<std::uint32_t> addresses): addresses(std::move(addresses)) {}
void setAddresses(const std::vector<std::uint32_t>& addresses) { void setAddresses(const std::vector<std::uint32_t>& addresses) {
this->addresses = addresses; this->addresses = addresses;
} }
virtual std::vector<unsigned char> getPayload() const override { [[nodiscard]] std::vector<unsigned char> getPayload() const override {
/* /*
* The set software breakpoint command consists of 2 bytes + 4*n bytes, where n is the number * The set software breakpoint command consists of 2 bytes + 4*n bytes, where n is the number
* of breakpoints to set: * of breakpoints to set:
@@ -43,5 +44,4 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
return output; return output;
} }
}; };
} }

View File

@@ -9,18 +9,18 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
class SetXmegaSoftwareBreakpoint: public Avr8GenericCommandFrame class SetXmegaSoftwareBreakpoint: public Avr8GenericCommandFrame
{ {
private: private:
std::uint32_t address; std::uint32_t address = 0;
public: public:
SetXmegaSoftwareBreakpoint() = default; SetXmegaSoftwareBreakpoint() = default;
SetXmegaSoftwareBreakpoint(std::uint32_t address): address(address) {} explicit SetXmegaSoftwareBreakpoint(std::uint32_t address): address(address) {}
void setAddress(std::uint32_t address) { void setAddress(std::uint32_t address) {
this->address = address; this->address = address;
} }
virtual std::vector<unsigned char> getPayload() const override { [[nodiscard]] std::vector<unsigned char> getPayload() const override {
/* /*
* The set software breakpoint command consists of 6 bytes bytes * The set software breakpoint command consists of 6 bytes bytes
* *
@@ -41,5 +41,4 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
return output; return output;
} }
}; };
} }

View File

@@ -9,7 +9,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
public: public:
Step() = default; Step() = default;
virtual std::vector<unsigned char> getPayload() const override { [[nodiscard]] std::vector<unsigned char> getPayload() const override {
/* /*
* The step command consists of 4 bytes: * The step command consists of 4 bytes:
* 1. Command ID (0x34) * 1. Command ID (0x34)
@@ -26,5 +26,4 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
return output; return output;
} }
}; };
} }

View File

@@ -11,13 +11,13 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
public: public:
Stop() = default; Stop() = default;
Stop(bool stopImmediately): stopImmediately(stopImmediately) {}; explicit Stop(bool stopImmediately): stopImmediately(stopImmediately) {};
void setStopImmediately(bool stopImmediately) { void setStopImmediately(bool stopImmediately) {
this->stopImmediately = stopImmediately; this->stopImmediately = stopImmediately;
} }
virtual std::vector<unsigned char> getPayload() const override { [[nodiscard]] std::vector<unsigned char> getPayload() const override {
/* /*
* The stop command consists of 3 bytes: * The stop command consists of 3 bytes:
* 1. Command ID (0x31) * 1. Command ID (0x31)
@@ -32,5 +32,4 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
return output; return output;
} }
}; };
} }

View File

@@ -10,7 +10,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
class WriteMemory: public Avr8GenericCommandFrame class WriteMemory: public Avr8GenericCommandFrame
{ {
private: private:
Avr8MemoryType type; Avr8MemoryType type = Avr8MemoryType::SRAM;
std::uint32_t address = 0; std::uint32_t address = 0;
Targets::TargetMemoryBuffer buffer; Targets::TargetMemoryBuffer buffer;
@@ -29,7 +29,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
this->buffer = buffer; this->buffer = buffer;
} }
virtual std::vector<unsigned char> getPayload() const override { [[nodiscard]] std::vector<unsigned char> getPayload() const override {
/* /*
* The write memory command consists of 12 bytes + the buffer size: * The write memory command consists of 12 bytes + the buffer size:
* 1. Command ID (0x23) * 1. Command ID (0x23)
@@ -63,5 +63,4 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
return output; return output;
} }
}; };
} }

View File

@@ -7,7 +7,9 @@ using namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr;
std::vector<AvrCommand> AvrCommandFrame::generateAvrCommands(std::size_t maximumCommandPacketSize) const { std::vector<AvrCommand> AvrCommandFrame::generateAvrCommands(std::size_t maximumCommandPacketSize) const {
auto rawCommandFrame = static_cast<std::vector<unsigned char>>(*this); auto rawCommandFrame = static_cast<std::vector<unsigned char>>(*this);
std::size_t commandFrameSize = rawCommandFrame.size(); std::size_t commandFrameSize = rawCommandFrame.size();
std::size_t commandsRequired = static_cast<std::size_t>(ceil(static_cast<float>(commandFrameSize) / static_cast<float>(maximumCommandPacketSize))); auto commandsRequired = static_cast<std::size_t>(
ceil(static_cast<float>(commandFrameSize) / static_cast<float>(maximumCommandPacketSize))
);
std::vector<AvrCommand> avrCommands; std::vector<AvrCommand> avrCommands;
std::size_t copiedPacketSize = 0; std::size_t copiedPacketSize = 0;

View File

@@ -28,7 +28,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
/** /**
* Destination sub-protocol handler ID * Destination sub-protocol handler ID
*/ */
ProtocolHandlerId protocolHandlerID; ProtocolHandlerId protocolHandlerID = ProtocolHandlerId::DISCOVERY;
std::vector<unsigned char> payload; std::vector<unsigned char> payload;
@@ -36,16 +36,16 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
using ResponseFrameType = AvrResponseFrame; using ResponseFrameType = AvrResponseFrame;
AvrCommandFrame() { AvrCommandFrame() {
if (this->lastSequenceId < std::numeric_limits<decltype(this->lastSequenceId)>::max()) { if (AvrCommandFrame::lastSequenceId < std::numeric_limits<decltype(AvrCommandFrame::lastSequenceId)>::max()) {
this->sequenceId = ++(this->lastSequenceId); this->sequenceId = ++(AvrCommandFrame::lastSequenceId);
} else { } else {
this->sequenceId = 0; this->sequenceId = 0;
this->lastSequenceId = 0; AvrCommandFrame::lastSequenceId = 0;
} }
}; };
unsigned char getProtocolVersion() const { [[nodiscard]] unsigned char getProtocolVersion() const {
return this->protocolVersion; return this->protocolVersion;
} }
@@ -53,11 +53,11 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
this->protocolVersion = protocolVersion; this->protocolVersion = protocolVersion;
} }
std::uint16_t getSequenceId() const { [[nodiscard]] std::uint16_t getSequenceId() const {
return this->sequenceId; return this->sequenceId;
} }
ProtocolHandlerId getProtocolHandlerId() const { [[nodiscard]] ProtocolHandlerId getProtocolHandlerId() const {
return this->protocolHandlerID; return this->protocolHandlerID;
} }
@@ -69,7 +69,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
this->protocolHandlerID = static_cast<ProtocolHandlerId>(protocolHandlerId); this->protocolHandlerID = static_cast<ProtocolHandlerId>(protocolHandlerId);
} }
virtual std::vector<unsigned char> getPayload() const { [[nodiscard]] virtual std::vector<unsigned char> getPayload() const {
return this->payload; return this->payload;
} }
@@ -94,7 +94,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
* @return * @return
* A vector of sequenced AVRCommands, each containing a segment of the AvrCommandFrame. * A vector of sequenced AVRCommands, each containing a segment of the AvrCommandFrame.
*/ */
std::vector<AvrCommand> generateAvrCommands(std::size_t maximumCommandPacketSize) const; [[nodiscard]] std::vector<AvrCommand> generateAvrCommands(std::size_t maximumCommandPacketSize) const;
/** /**
* Converts instance of a CMSIS Command to an unsigned char, for sending to the Atmel ICE device. * Converts instance of a CMSIS Command to an unsigned char, for sending to the Atmel ICE device.

View File

@@ -40,7 +40,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
using ResponseFrameType = ResponseFrames::DiscoveryResponseFrame; using ResponseFrameType = ResponseFrames::DiscoveryResponseFrame;
DiscoveryCommandFrame() { DiscoveryCommandFrame() {
this->setProtocolHandlerId(ProtocolHandlerId::Discovery); this->setProtocolHandlerId(ProtocolHandlerId::DISCOVERY);
} }
}; };
} }

View File

@@ -22,12 +22,12 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
class Query: public DiscoveryCommandFrame class Query: public DiscoveryCommandFrame
{ {
private: private:
QueryContext context; QueryContext context = QueryContext::COMMAND_HANDLERS;
public: public:
Query(): DiscoveryCommandFrame() {} Query(): DiscoveryCommandFrame() {}
Query(QueryContext context): DiscoveryCommandFrame() { explicit Query(QueryContext context): DiscoveryCommandFrame() {
this->setContext(context); this->setContext(context);
} }
@@ -35,7 +35,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
this->context = context; this->context = context;
} }
virtual std::vector<unsigned char> getPayload() const override { [[nodiscard]] std::vector<unsigned char> getPayload() const override {
/* /*
* The payload for the Query command consists of three bytes. A command ID (0x00), version (0x00) and a * The payload for the Query command consists of three bytes. A command ID (0x00), version (0x00) and a
* query context. * query context.

View File

@@ -27,5 +27,4 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
this->init(); this->init();
} }
}; };
} }

View File

@@ -25,8 +25,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
{ {
public: public:
HouseKeepingCommandFrame() { HouseKeepingCommandFrame() {
this->setProtocolHandlerId(ProtocolHandlerId::HouseKeeping); this->setProtocolHandlerId(ProtocolHandlerId::HOUSE_KEEPING);
} }
}; };
} }

View File

@@ -26,5 +26,4 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
this->init(); this->init();
} }
}; };
} }

View File

@@ -42,6 +42,7 @@ using Bloom::Targets::TargetState;
using Bloom::Targets::TargetMemoryType; using Bloom::Targets::TargetMemoryType;
using Bloom::Targets::TargetMemoryBuffer; using Bloom::Targets::TargetMemoryBuffer;
using Bloom::Targets::TargetRegister; using Bloom::Targets::TargetRegister;
using Bloom::Targets::TargetRegisterDescriptor;
using Bloom::Targets::TargetRegisterType; using Bloom::Targets::TargetRegisterType;
using Bloom::Targets::TargetRegisters; using Bloom::Targets::TargetRegisters;
@@ -554,7 +555,7 @@ std::uint32_t EdbgAvr8Interface::getProgramCounter() {
} }
TargetRegister EdbgAvr8Interface::getStackPointerRegister() { TargetRegister EdbgAvr8Interface::getStackPointerRegister() {
return TargetRegister(TargetRegisterType::STACK_POINTER, this->readMemory( return TargetRegister(TargetRegisterDescriptor(TargetRegisterType::STACK_POINTER), this->readMemory(
Avr8MemoryType::SRAM, Avr8MemoryType::SRAM,
this->targetParameters.stackPointerRegisterStartAddress.value(), this->targetParameters.stackPointerRegisterStartAddress.value(),
this->targetParameters.stackPointerRegisterSize.value() this->targetParameters.stackPointerRegisterSize.value()
@@ -562,7 +563,7 @@ TargetRegister EdbgAvr8Interface::getStackPointerRegister() {
} }
TargetRegister EdbgAvr8Interface::getStatusRegister() { TargetRegister EdbgAvr8Interface::getStatusRegister() {
return TargetRegister(TargetRegisterType::STATUS_REGISTER, this->readMemory( return TargetRegister(TargetRegisterDescriptor(TargetRegisterType::STATUS_REGISTER), this->readMemory(
Avr8MemoryType::SRAM, Avr8MemoryType::SRAM,
this->targetParameters.statusRegisterStartAddress.value(), this->targetParameters.statusRegisterStartAddress.value(),
this->targetParameters.statusRegisterSize.value() this->targetParameters.statusRegisterSize.value()
@@ -840,7 +841,7 @@ TargetMemoryBuffer EdbgAvr8Interface::readMemory(Avr8MemoryType type, std::uint3
return response.getMemoryBuffer(); return response.getMemoryBuffer();
} }
void EdbgAvr8Interface::writeMemory(Avr8MemoryType type, std::uint32_t address, TargetMemoryBuffer buffer) { void EdbgAvr8Interface::writeMemory(Avr8MemoryType type, std::uint32_t address, const TargetMemoryBuffer& buffer) {
if (type == Avr8MemoryType::FLASH_PAGE) { if (type == Avr8MemoryType::FLASH_PAGE) {
// TODO: Implement support for writing to flash // TODO: Implement support for writing to flash
throw Exception("Cannot write to flash"); throw Exception("Cannot write to flash");
@@ -855,8 +856,6 @@ void EdbgAvr8Interface::writeMemory(Avr8MemoryType type, std::uint32_t address,
if (response.getResponseId() == Avr8ResponseId::FAILED) { if (response.getResponseId() == Avr8ResponseId::FAILED) {
throw Avr8CommandFailure("Write memory AVR8 from target command failed", response); throw Avr8CommandFailure("Write memory AVR8 from target command failed", response);
} }
return;
} }
TargetRegisters EdbgAvr8Interface::readGeneralPurposeRegisters(std::set<std::size_t> registerIds) { TargetRegisters EdbgAvr8Interface::readGeneralPurposeRegisters(std::set<std::size_t> registerIds) {

View File

@@ -350,7 +350,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
* @param address * @param address
* @param buffer * @param buffer
*/ */
void writeMemory(Avr8MemoryType type, std::uint32_t address, Targets::TargetMemoryBuffer buffer); void writeMemory(Avr8MemoryType type, std::uint32_t address, const Targets::TargetMemoryBuffer& buffer);
/** /**
* Fetches the current target state. * Fetches the current target state.
@@ -413,7 +413,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
void waitForStoppedEvent(); void waitForStoppedEvent();
public: public:
EdbgAvr8Interface(EdbgInterface& edbgInterface) explicit EdbgAvr8Interface(EdbgInterface& edbgInterface)
: edbgInterface(edbgInterface) {}; : edbgInterface(edbgInterface) {};
/* /*
@@ -427,7 +427,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
* *
* @param targetConfig * @param targetConfig
*/ */
virtual void configure(const TargetConfig& targetConfig) override; void configure(const TargetConfig& targetConfig) override;
/** /**
* Configures the target family. For some physical interfaces, the target family is required in order * Configures the target family. For some physical interfaces, the target family is required in order
@@ -445,22 +445,22 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
* *
* @param config * @param config
*/ */
virtual void setTargetParameters(const Targets::Microchip::Avr::Avr8Bit::TargetParameters& config) override; void setTargetParameters(const Targets::Microchip::Avr::Avr8Bit::TargetParameters& config) override;
/** /**
* Initialises the AVR8 Generic protocol interface by setting the appropriate parameters on the debug tool. * Initialises the AVR8 Generic protocol interface by setting the appropriate parameters on the debug tool.
*/ */
virtual void init() override; void init() override;
/** /**
* Issues the "stop" command to the debug tool, halting target execution. * Issues the "stop" command to the debug tool, halting target execution.
*/ */
virtual void stop() override; void stop() override;
/** /**
* Issues the "run" command to the debug tool, resuming execution on the target. * Issues the "run" command to the debug tool, resuming execution on the target.
*/ */
virtual void run() override; void run() override;
/** /**
* Issues the "run to" command to the debug tool, resuming execution on the target, up to a specific byte * Issues the "run to" command to the debug tool, resuming execution on the target, up to a specific byte
@@ -469,65 +469,65 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
* @param address * @param address
* The (byte) address to run to. * The (byte) address to run to.
*/ */
virtual void runTo(std::uint32_t address) override; void runTo(std::uint32_t address) override;
/** /**
* Issues the "step" command to the debug tool, stepping the execution on the target. The stepping can be * Issues the "step" command to the debug tool, stepping the execution on the target. The stepping can be
* configured to step in, out or over. But currently we only support stepping in. The target will dispatch * configured to step in, out or over. But currently we only support stepping in. The target will dispatch
* an AVR BREAK event once it reaches the next instruction. * an AVR BREAK event once it reaches the next instruction.
*/ */
virtual void step() override; void step() override;
/** /**
* Issues the "reset" command to the debug tool, resetting target execution. * Issues the "reset" command to the debug tool, resetting target execution.
*/ */
virtual void reset() override; void reset() override;
/** /**
* Activates the physical interface and starts a debug session on the target (via attach()). * Activates the physical interface and starts a debug session on the target (via attach()).
*/ */
virtual void activate() override; void activate() override;
/** /**
* Terminates any active debug session on the target and severs the connection between the debug tool and * Terminates any active debug session on the target and severs the connection between the debug tool and
* the target (by deactivating the physical interface). * the target (by deactivating the physical interface).
*/ */
virtual void deactivate() override; void deactivate() override;
/** /**
* Issues the "PC Read" command to the debug tool, to extract the current program counter. * Issues the "PC Read" command to the debug tool, to extract the current program counter.
* *
* @return * @return
*/ */
virtual std::uint32_t getProgramCounter() override; std::uint32_t getProgramCounter() override;
/** /**
* Reads the stack pointer register from the target. * Reads the stack pointer register from the target.
* *
* @return * @return
*/ */
virtual Targets::TargetRegister getStackPointerRegister() override; Targets::TargetRegister getStackPointerRegister() override;
/** /**
* Reads the status register from the target. * Reads the status register from the target.
* *
* @return * @return
*/ */
virtual Targets::TargetRegister getStatusRegister() override; Targets::TargetRegister getStatusRegister() override;
/** /**
* Updates the stack pointer register on ther target. * Updates the stack pointer register on ther target.
* *
* @param stackPointerRegister * @param stackPointerRegister
*/ */
virtual void setStackPointerRegister(const Targets::TargetRegister& stackPointerRegister) override; void setStackPointerRegister(const Targets::TargetRegister& stackPointerRegister) override;
/** /**
* Updates the status register on the target. * Updates the status register on the target.
* *
* @param statusRegister * @param statusRegister
*/ */
virtual void setStatusRegister(const Targets::TargetRegister& statusRegister) override; void setStatusRegister(const Targets::TargetRegister& statusRegister) override;
/** /**
* Issues the "PC Write" command to the debug tool, setting the program counter on the target. * Issues the "PC Write" command to the debug tool, setting the program counter on the target.
@@ -535,14 +535,14 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
* @param programCounter * @param programCounter
* The byte address to set as the program counter. * The byte address to set as the program counter.
*/ */
virtual void setProgramCounter(std::uint32_t programCounter) override; void setProgramCounter(std::uint32_t programCounter) override;
/** /**
* Issues the "Get ID" command to the debug tool, to extract the signature from the target. * Issues the "Get ID" command to the debug tool, to extract the signature from the target.
* *
* @return * @return
*/ */
virtual Targets::Microchip::Avr::TargetSignature getDeviceId() override; Targets::Microchip::Avr::TargetSignature getDeviceId() override;
/** /**
* Issues the "Software Breakpoint Set" command to the debug tool, setting a software breakpoint at the given * Issues the "Software Breakpoint Set" command to the debug tool, setting a software breakpoint at the given
@@ -551,7 +551,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
* @param address * @param address
* The byte address to position the breakpoint. * The byte address to position the breakpoint.
*/ */
virtual void setBreakpoint(std::uint32_t address) override; void setBreakpoint(std::uint32_t address) override;
/** /**
* Issues the "Software Breakpoint Clear" command to the debug tool, clearing any breakpoint at the given * Issues the "Software Breakpoint Clear" command to the debug tool, clearing any breakpoint at the given
@@ -560,7 +560,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
* @param address * @param address
* The byte address of the breakpoint to clear. * The byte address of the breakpoint to clear.
*/ */
virtual void clearBreakpoint(std::uint32_t address) override; void clearBreakpoint(std::uint32_t address) override;
/** /**
* Issues the "Software Breakpoint Clear All" command to the debug tool, clearing all software breakpoints * Issues the "Software Breakpoint Clear All" command to the debug tool, clearing all software breakpoints
@@ -568,7 +568,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
* *
* If the debug session ended before any of the set breakpoints were cleared, this will *not* clear them. * If the debug session ended before any of the set breakpoints were cleared, this will *not* clear them.
*/ */
virtual void clearAllBreakpoints() override; void clearAllBreakpoints() override;
/** /**
* Reads gernal purpose registers from the target. * Reads gernal purpose registers from the target.
@@ -576,14 +576,14 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
* @param registerIds * @param registerIds
* @return * @return
*/ */
virtual Targets::TargetRegisters readGeneralPurposeRegisters(std::set<std::size_t> registerIds) override; Targets::TargetRegisters readGeneralPurposeRegisters(std::set<std::size_t> registerIds) override;
/** /**
* Writes general purpose registers to target. * Writes general purpose registers to target.
* *
* @param registers * @param registers
*/ */
virtual void writeGeneralPurposeRegisters(const Targets::TargetRegisters& registers) override; void writeGeneralPurposeRegisters(const Targets::TargetRegisters& registers) override;
/** /**
* This is an overloaded method. * This is an overloaded method.
@@ -595,7 +595,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
* @param bytes * @param bytes
* @return * @return
*/ */
virtual Targets::TargetMemoryBuffer readMemory( Targets::TargetMemoryBuffer readMemory(
Targets::TargetMemoryType memoryType, Targets::TargetMemoryType memoryType,
std::uint32_t startAddress, std::uint32_t startAddress,
std::uint32_t bytes std::uint32_t bytes
@@ -610,7 +610,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
* @param startAddress * @param startAddress
* @param buffer * @param buffer
*/ */
virtual void writeMemory( void writeMemory(
Targets::TargetMemoryType memoryType, Targets::TargetMemoryType memoryType,
std::uint32_t startAddress, std::uint32_t startAddress,
const Targets::TargetMemoryBuffer& buffer const Targets::TargetMemoryBuffer& buffer
@@ -621,6 +621,6 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
* *
* @return * @return
*/ */
virtual Targets::TargetState getTargetState() override; Targets::TargetState getTargetState() override;
}; };
} }

View File

@@ -10,21 +10,21 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
class BreakEvent: public AvrEvent class BreakEvent: public AvrEvent
{ {
private: private:
std::uint32_t programCounter; std::uint32_t programCounter = 0;
Targets::TargetBreakCause breakCause; Targets::TargetBreakCause breakCause = Targets::TargetBreakCause::UNKNOWN;
void init(const AvrEvent& event); void init(const AvrEvent& event);
public: public:
BreakEvent(const AvrEvent& event) { explicit BreakEvent(const AvrEvent& event) {
this->init(event); this->init(event);
} }
std::uint32_t getProgramCounter() { [[nodiscard]] std::uint32_t getProgramCounter() const {
return this->programCounter; return this->programCounter;
} }
Targets::TargetBreakCause getBreakCause() { [[nodiscard]] Targets::TargetBreakCause getBreakCause() const {
return this->breakCause; return this->breakCause;
} }
}; };

View File

@@ -7,13 +7,14 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::ResponseFrame
class Avr8GenericResponseFrame: public AvrResponseFrame class Avr8GenericResponseFrame: public AvrResponseFrame
{ {
public: public:
Avr8GenericResponseFrame(const std::vector<AvrResponse>& AVRResponses): AvrResponseFrame(AVRResponses) {} Avr8GenericResponseFrame() = default;
Avr8GenericResponseFrame() {} explicit Avr8GenericResponseFrame(const std::vector<AvrResponse>& AVRResponses)
: AvrResponseFrame(AVRResponses) {}
/** /**
* See parent method. * See parent method.
*/ */
std::vector<unsigned char> getPayloadData() override { [[nodiscard]] std::vector<unsigned char> getPayloadData() override {
/* /*
* AVR8 data payloads are in little endian form and include two bytes before the data (response ID and * AVR8 data payloads are in little endian form and include two bytes before the data (response ID and
* version byte) as well as an additional byte after the data, known as the 'status code'. * version byte) as well as an additional byte after the data, known as the 'status code'.
@@ -27,5 +28,4 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::ResponseFrame
return data; return data;
} }
}; };
} }

View File

@@ -8,8 +8,8 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::ResponseFrame
class GetDeviceId: public Avr8GenericResponseFrame class GetDeviceId: public Avr8GenericResponseFrame
{ {
public: public:
GetDeviceId(const std::vector<AvrResponse>& AvrResponses): Avr8GenericResponseFrame(AvrResponses) {} GetDeviceId() = default;
GetDeviceId() {} explicit GetDeviceId(const std::vector<AvrResponse>& AvrResponses): Avr8GenericResponseFrame(AvrResponses) {}
Targets::Microchip::Avr::TargetSignature extractSignature(Avr8PhysicalInterface physicalInterface) { Targets::Microchip::Avr::TargetSignature extractSignature(Avr8PhysicalInterface physicalInterface) {
auto payloadData = this->getPayloadData(); auto payloadData = this->getPayloadData();

View File

@@ -10,8 +10,8 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::ResponseFrame
class GetProgramCounter: public Avr8GenericResponseFrame class GetProgramCounter: public Avr8GenericResponseFrame
{ {
public: public:
GetProgramCounter(const std::vector<AvrResponse>& AVRResponses): Avr8GenericResponseFrame(AVRResponses) {} GetProgramCounter() = default;
GetProgramCounter() {} explicit GetProgramCounter(const std::vector<AvrResponse>& AVRResponses): Avr8GenericResponseFrame(AVRResponses) {}
std::uint32_t extractProgramCounter() { std::uint32_t extractProgramCounter() {
/* /*

View File

@@ -8,8 +8,8 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::ResponseFrame
class ReadMemory: public Avr8GenericResponseFrame class ReadMemory: public Avr8GenericResponseFrame
{ {
public: public:
ReadMemory(const std::vector<AvrResponse>& AVRResponses): Avr8GenericResponseFrame(AVRResponses) {} ReadMemory() = default;
ReadMemory() {} explicit ReadMemory(const std::vector<AvrResponse>& AVRResponses): Avr8GenericResponseFrame(AVRResponses) {}
Targets::TargetMemoryBuffer getMemoryBuffer() { Targets::TargetMemoryBuffer getMemoryBuffer() {
/* /*
@@ -24,5 +24,4 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::ResponseFrame
return data; return data;
} }
}; };
} }

View File

@@ -35,4 +35,4 @@ void AvrResponseFrame::initFromRawFrame(const std::vector<unsigned char>& rawFra
auto& payload = this->getPayload(); auto& payload = this->getPayload();
payload.insert(payload.begin(), rawFrame.begin() + 4, rawFrame.end()); payload.insert(payload.begin(), rawFrame.begin() + 4, rawFrame.end());
} }

View File

@@ -24,7 +24,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
/** /**
* Destination sub-protocol handler ID * Destination sub-protocol handler ID
*/ */
ProtocolHandlerId protocolHandlerID; ProtocolHandlerId protocolHandlerID = ProtocolHandlerId::AVR8_GENERIC;
std::vector<unsigned char> payload; std::vector<unsigned char> payload;
@@ -48,12 +48,12 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
} }
public: public:
explicit AvrResponseFrame() = default;
explicit AvrResponseFrame(const std::vector<AvrResponse>& AVRResponses) { explicit AvrResponseFrame(const std::vector<AvrResponse>& AVRResponses) {
this->initFromAvrResponses(AVRResponses); this->initFromAvrResponses(AVRResponses);
} }
explicit AvrResponseFrame() {}
/** /**
* An AVRResponse contains a single fragment of an AvrResponseFrame. * An AVRResponse contains a single fragment of an AvrResponseFrame.
* *
@@ -63,11 +63,11 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
*/ */
void initFromAvrResponses(const std::vector<AvrResponse>& avrResponses); void initFromAvrResponses(const std::vector<AvrResponse>& avrResponses);
std::uint16_t getSequenceId() const { [[nodiscard]] std::uint16_t getSequenceId() const {
return this->sequenceID; return this->sequenceID;
} }
ProtocolHandlerId getProtocolHandlerId() const { [[nodiscard]] ProtocolHandlerId getProtocolHandlerId() const {
return this->protocolHandlerID; return this->protocolHandlerID;
} }
@@ -79,8 +79,8 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
return this->payload[0]; return this->payload[0];
} }
virtual std::vector<unsigned char> getPayloadData() { [[nodiscard]] virtual std::vector<unsigned char> getPayloadData() {
return this->getPayload(); return this->payload;
} }
}; };
} }

View File

@@ -7,8 +7,8 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::ResponseFrame
class DiscoveryResponseFrame: public AvrResponseFrame class DiscoveryResponseFrame: public AvrResponseFrame
{ {
public: public:
DiscoveryResponseFrame(const std::vector<AvrResponse>& AVRResponses): AvrResponseFrame(AVRResponses) {} DiscoveryResponseFrame() = default;
DiscoveryResponseFrame() {} explicit DiscoveryResponseFrame(const std::vector<AvrResponse>& AVRResponses): AvrResponseFrame(AVRResponses) {}
/** /**
* See parent method. * See parent method.
@@ -25,5 +25,4 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::ResponseFrame
return data; return data;
} }
}; };
} }

View File

@@ -4,9 +4,9 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg
{ {
enum class ProtocolHandlerId: unsigned char enum class ProtocolHandlerId: unsigned char
{ {
Discovery = 0x00, DISCOVERY = 0x00,
HouseKeeping = 0x01, HOUSE_KEEPING = 0x01,
Avr8Generic = 0x12, AVR8_GENERIC = 0x12,
Avr32Generic = 0x13, AVR32_GENERIC = 0x13,
}; };
} }

View File

@@ -89,4 +89,4 @@ std::vector<Protocols::CmsisDap::Edbg::Avr::AvrResponse> EdbgInterface::requestA
} }
return responses; return responses;
} }

View File

@@ -65,7 +65,7 @@ namespace Bloom::Usb
} }
public: public:
std::size_t getInputReportSize() { std::size_t getInputReportSize() const {
return this->inputReportSize; return this->inputReportSize;
} }

View File

@@ -8,7 +8,8 @@
* *
* https://github.com/signal11/hidapi * https://github.com/signal11/hidapi
*/ */
struct hid_device_ { struct hid_device_
{
// Handle to the actual device. // Handle to the actual device.
libusb_device_handle* device_handle; libusb_device_handle* device_handle;

View File

@@ -1,9 +1,7 @@
#include <libusb-1.0/libusb.h> #include <libusb-1.0/libusb.h>
#include <chrono> #include <chrono>
#include <thread>
#include "Interface.hpp" #include "Interface.hpp"
#include "src/Logger/Logger.hpp"
#include "src/Exceptions/Exception.hpp" #include "src/Exceptions/Exception.hpp"
using namespace Bloom::Usb; using namespace Bloom::Usb;

View File

@@ -18,7 +18,7 @@ namespace Bloom::Usb
std::uint16_t productId = 0; std::uint16_t productId = 0;
std::uint8_t number = 0; std::uint8_t number = 0;
std::string name = ""; std::string name;
bool initialised = false; bool initialised = false;
bool claimed = false; bool claimed = false;
@@ -52,11 +52,11 @@ namespace Bloom::Usb
this->name = name; this->name = name;
} }
bool isClaimed() { bool isClaimed() const {
return this->claimed; return this->claimed;
} }
bool isInitialised() { bool isInitialised() const {
return this->initialised; return this->initialised;
} }

View File

@@ -26,8 +26,6 @@ namespace Bloom::Usb
void close(); void close();
public: public:
void init();
UsbDevice(std::uint16_t vendorId, std::uint16_t productId) { UsbDevice(std::uint16_t vendorId, std::uint16_t productId) {
this->vendorId = vendorId; this->vendorId = vendorId;
this->productId = productId; this->productId = productId;
@@ -35,6 +33,8 @@ namespace Bloom::Usb
~UsbDevice() = default; ~UsbDevice() = default;
void init();
[[nodiscard]] libusb_device* getLibUsbDevice() const { [[nodiscard]] libusb_device* getLibUsbDevice() const {
return this->libUsbDevice; return this->libUsbDevice;
} }
@@ -43,11 +43,11 @@ namespace Bloom::Usb
this->libUsbDevice = libUsbDevice; this->libUsbDevice = libUsbDevice;
} }
std::uint16_t getVendorId() const { [[nodiscard]] std::uint16_t getVendorId() const {
return this->vendorId; return this->vendorId;
} }
std::uint16_t getProductId() const { [[nodiscard]] std::uint16_t getProductId() const {
return this->productId; return this->productId;
} }

View File

@@ -86,6 +86,7 @@ void EventListener::waitAndDispatch(int msTimeout) {
if (msTimeout > 0) { if (msTimeout > 0) {
this->eventQueueByEventTypeCV.wait_for(queueLock, std::chrono::milliseconds(msTimeout), eventsFound); this->eventQueueByEventTypeCV.wait_for(queueLock, std::chrono::milliseconds(msTimeout), eventsFound);
} else { } else {
this->eventQueueByEventTypeCV.wait(queueLock, eventsFound); this->eventQueueByEventTypeCV.wait(queueLock, eventsFound);
} }

View File

@@ -4,7 +4,7 @@ using namespace Bloom;
void EventManager::registerListener(std::shared_ptr<EventListener> listener) { void EventManager::registerListener(std::shared_ptr<EventListener> listener) {
auto registerListenersLock = std::unique_lock(this->registerListenerMutex); auto registerListenersLock = std::unique_lock(this->registerListenerMutex);
this->registeredListeners.insert(std::pair(listener->getId(), listener)); this->registeredListeners.insert(std::pair(listener->getId(), std::move(listener)));
} }
void EventManager::deregisterListener(size_t listenerId) { void EventManager::deregisterListener(size_t listenerId) {
@@ -12,10 +12,11 @@ void EventManager::deregisterListener(size_t listenerId) {
this->registeredListeners.erase(listenerId); this->registeredListeners.erase(listenerId);
} }
void EventManager::triggerEvent(std::shared_ptr<const Events::Event> event) { void EventManager::triggerEvent(const std::shared_ptr<const Events::Event>& event) {
auto registerListenersLock = std::unique_lock(this->registerListenerMutex); auto registerListenersLock = std::unique_lock(this->registerListenerMutex);
for(auto const& [listenerId, listener] : this->registeredListeners) { for(auto const& [listenerId, listener] : this->registeredListeners) {
auto registeredEventTypes = listener->getRegisteredEventTypeNames(); auto registeredEventTypes = listener->getRegisteredEventTypeNames();
if (registeredEventTypes.contains(event->getName())) { if (registeredEventTypes.contains(event->getName())) {
listener->registerEvent(event); listener->registerEvent(event);
} }

View File

@@ -53,7 +53,6 @@ namespace Bloom
* *
* @param event * @param event
*/ */
void triggerEvent(Events::SharedGenericEventPointer event); void triggerEvent(const Events::SharedGenericEventPointer& event);
}; };
} }

View File

@@ -11,7 +11,7 @@ namespace Bloom::Events
public: public:
static inline const std::string name = "BreakpointRemovedOnTarget"; static inline const std::string name = "BreakpointRemovedOnTarget";
std::string getName() const override { [[nodiscard]] std::string getName() const override {
return BreakpointRemovedOnTarget::name; return BreakpointRemovedOnTarget::name;
} }
}; };

View File

@@ -11,7 +11,7 @@ namespace Bloom::Events
public: public:
static inline const std::string name = "BreakpointSetOnTarget"; static inline const std::string name = "BreakpointSetOnTarget";
std::string getName() const override { [[nodiscard]] std::string getName() const override {
return BreakpointSetOnTarget::name; return BreakpointSetOnTarget::name;
} }
}; };

View File

@@ -12,15 +12,15 @@ namespace Bloom::Events
private: private:
ThreadState state; ThreadState state;
public: public:
DebugServerThreadStateChanged(ThreadState state): state(state) {}; explicit DebugServerThreadStateChanged(ThreadState state): state(state) {};
static inline const std::string name = "DebugServerThreadStateChanged"; static inline const std::string name = "DebugServerThreadStateChanged";
std::string getName() const override { [[nodiscard]] std::string getName() const override {
return DebugServerThreadStateChanged::name; return DebugServerThreadStateChanged::name;
} }
ThreadState getState() const { [[nodiscard]] ThreadState getState() const {
return this->state; return this->state;
} }
}; };

View File

@@ -11,7 +11,7 @@ namespace Bloom::Events
public: public:
static inline const std::string name = "DebugSessionFinished"; static inline const std::string name = "DebugSessionFinished";
std::string getName() const override { [[nodiscard]] std::string getName() const override {
return DebugSessionFinished::name; return DebugSessionFinished::name;
} }
}; };

View File

@@ -11,7 +11,7 @@ namespace Bloom::Events
public: public:
static inline const std::string name = "DebugSessionStarted"; static inline const std::string name = "DebugSessionStarted";
std::string getName() const override { [[nodiscard]] std::string getName() const override {
return DebugSessionStarted::name; return DebugSessionStarted::name;
} }
}; };

View File

@@ -11,7 +11,7 @@ namespace Bloom::Events
public: public:
static inline const std::string name = "ExtractTargetDescriptor"; static inline const std::string name = "ExtractTargetDescriptor";
std::string getName() const override { [[nodiscard]] std::string getName() const override {
return ExtractTargetDescriptor::name; return ExtractTargetDescriptor::name;
} }
}; };

View File

@@ -12,11 +12,11 @@ namespace Bloom::Events
private: private:
ThreadState state; ThreadState state;
public: public:
InsightThreadStateChanged(ThreadState state): state(state) {}; explicit InsightThreadStateChanged(ThreadState state): state(state) {};
static inline const std::string name = "InsightThreadStateChanged"; static inline const std::string name = "InsightThreadStateChanged";
std::string getName() const override { [[nodiscard]] std::string getName() const override {
return InsightThreadStateChanged::name; return InsightThreadStateChanged::name;
} }

View File

@@ -13,7 +13,7 @@ namespace Bloom::Events
static inline const std::string name = "MemoryRetrievedFromTarget"; static inline const std::string name = "MemoryRetrievedFromTarget";
Targets::TargetMemoryBuffer data; Targets::TargetMemoryBuffer data;
std::string getName() const override { [[nodiscard]] std::string getName() const override {
return MemoryRetrievedFromTarget::name; return MemoryRetrievedFromTarget::name;
} }
}; };

View File

@@ -12,7 +12,7 @@ namespace Bloom::Events
public: public:
static inline const std::string name = "MemoryWrittenToTarget"; static inline const std::string name = "MemoryWrittenToTarget";
std::string getName() const override { [[nodiscard]] std::string getName() const override {
return MemoryWrittenToTarget::name; return MemoryWrittenToTarget::name;
} }

View File

@@ -11,7 +11,7 @@ namespace Bloom::Events
public: public:
static inline const std::string name = "ProgramCounterSetOnTarget"; static inline const std::string name = "ProgramCounterSetOnTarget";
std::string getName() const override { [[nodiscard]] std::string getName() const override {
return ProgramCounterSetOnTarget::name; return ProgramCounterSetOnTarget::name;
} }
}; };

View File

@@ -13,7 +13,7 @@ namespace Bloom::Events
static inline const std::string name = "RegistersRetrievedFromTarget"; static inline const std::string name = "RegistersRetrievedFromTarget";
Targets::TargetRegisters registers; Targets::TargetRegisters registers;
std::string getName() const override { [[nodiscard]] std::string getName() const override {
return RegistersRetrievedFromTarget::name; return RegistersRetrievedFromTarget::name;
} }
}; };

View File

@@ -11,7 +11,7 @@ namespace Bloom::Events
public: public:
static inline const std::string name = "RegistersWrittenToTarget"; static inline const std::string name = "RegistersWrittenToTarget";
std::string getName() const override { [[nodiscard]] std::string getName() const override {
return RegistersWrittenToTarget::name; return RegistersWrittenToTarget::name;
} }
}; };

Some files were not shown because too many files have changed in this diff Show More