Tidying
This commit is contained in:
@@ -207,7 +207,7 @@ namespace DebugServer::Gdb
|
||||
bool interruptible,
|
||||
std::optional<std::chrono::milliseconds> timeout
|
||||
) {
|
||||
auto output = std::vector<unsigned char>();
|
||||
auto output = std::vector<unsigned char>{};
|
||||
|
||||
if (this->readInterruptEnabled != interruptible) {
|
||||
if (interruptible) {
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
#include "src/Helpers/EventFdNotifier.hpp"
|
||||
#include "src/Helpers/EpollInstance.hpp"
|
||||
|
||||
#include "src/DebugServer/Gdb/Packet.hpp"
|
||||
#include "src/DebugServer/Gdb/ResponsePackets/ResponsePacket.hpp"
|
||||
#include "Packet.hpp"
|
||||
#include "ResponsePackets/ResponsePacket.hpp"
|
||||
|
||||
namespace DebugServer::Gdb
|
||||
{
|
||||
|
||||
@@ -159,15 +159,17 @@ namespace DebugServer::Gdb
|
||||
}
|
||||
|
||||
const auto commandPacket = this->waitForCommandPacket();
|
||||
if (commandPacket) {
|
||||
commandPacket->handle(
|
||||
*(this->getActiveDebugSession()),
|
||||
this->getGdbTargetDescriptor(),
|
||||
this->targetDescriptor,
|
||||
this->targetControllerService
|
||||
);
|
||||
if (!commandPacket) {
|
||||
return;
|
||||
}
|
||||
|
||||
commandPacket->handle(
|
||||
*(this->getActiveDebugSession()),
|
||||
this->getGdbTargetDescriptor(),
|
||||
this->targetDescriptor,
|
||||
this->targetControllerService
|
||||
);
|
||||
|
||||
} catch (const ClientDisconnected&) {
|
||||
Logger::info("GDB RSP client disconnected");
|
||||
this->endDebugSession();
|
||||
|
||||
@@ -361,8 +361,6 @@ namespace DebugToolDrivers::Protocols::RiscVDebugSpec
|
||||
TargetMemorySize bytes,
|
||||
const std::set<TargetMemoryAddressRange>& excludedAddressRanges
|
||||
) {
|
||||
using DebugModule::Registers::MemoryAccessControlField;
|
||||
|
||||
// TODO: excluded addresses
|
||||
|
||||
const auto pageSize = 4;
|
||||
@@ -383,34 +381,7 @@ namespace DebugToolDrivers::Protocols::RiscVDebugSpec
|
||||
return TargetMemoryBuffer{offset, offset + bytes};
|
||||
}
|
||||
|
||||
auto output = TargetMemoryBuffer{};
|
||||
output.reserve(bytes);
|
||||
|
||||
/*
|
||||
* We only need to set the address once. No need to update it as we use the post-increment function to
|
||||
* increment the address. See MemoryAccessControlField::postIncrement
|
||||
*/
|
||||
this->dtmInterface.writeDebugModuleRegister(RegisterAddress::ABSTRACT_DATA_1, startAddress);
|
||||
|
||||
constexpr auto command = AbstractCommandRegister{
|
||||
.control = MemoryAccessControlField{
|
||||
.postIncrement = true,
|
||||
.size = MemoryAccessControlField::MemorySize::SIZE_32,
|
||||
}.value(),
|
||||
.commandType = AbstractCommandRegister::CommandType::MEMORY_ACCESS
|
||||
};
|
||||
|
||||
for (auto address = startAddress; address <= (startAddress + bytes - 1); address += 4) {
|
||||
this->executeAbstractCommand(command);
|
||||
|
||||
const auto data = this->dtmInterface.readDebugModuleRegister(RegisterAddress::ABSTRACT_DATA_0);
|
||||
output.emplace_back(static_cast<unsigned char>(data));
|
||||
output.emplace_back(static_cast<unsigned char>(data >> 8));
|
||||
output.emplace_back(static_cast<unsigned char>(data >> 16));
|
||||
output.emplace_back(static_cast<unsigned char>(data >> 24));
|
||||
}
|
||||
|
||||
return output;
|
||||
return this->readMemoryViaAbstractCommand(startAddress, bytes);
|
||||
}
|
||||
|
||||
void DebugTranslator::writeMemory(
|
||||
@@ -462,30 +433,7 @@ namespace DebugToolDrivers::Protocols::RiscVDebugSpec
|
||||
);
|
||||
}
|
||||
|
||||
this->dtmInterface.writeDebugModuleRegister(RegisterAddress::ABSTRACT_DATA_1, startAddress);
|
||||
|
||||
constexpr auto command = AbstractCommandRegister{
|
||||
.control = MemoryAccessControlField{
|
||||
.write = true,
|
||||
.postIncrement = true,
|
||||
.size = MemoryAccessControlField::MemorySize::SIZE_32,
|
||||
}.value(),
|
||||
.commandType = AbstractCommandRegister::CommandType::MEMORY_ACCESS
|
||||
};
|
||||
|
||||
for (TargetMemoryAddress offset = 0; offset < buffer.size(); offset += 4) {
|
||||
this->dtmInterface.writeDebugModuleRegister(
|
||||
RegisterAddress::ABSTRACT_DATA_0,
|
||||
static_cast<RegisterValue>(
|
||||
(buffer[offset + 3] << 24)
|
||||
| (buffer[offset + 2] << 16)
|
||||
| (buffer[offset + 1] << 8)
|
||||
| (buffer[offset])
|
||||
)
|
||||
);
|
||||
|
||||
this->executeAbstractCommand(command);
|
||||
}
|
||||
return this->writeMemoryViaAbstractCommand(startAddress, buffer);
|
||||
}
|
||||
|
||||
std::vector<DebugModule::HartIndex> DebugTranslator::discoverHartIndices() {
|
||||
@@ -800,6 +748,74 @@ namespace DebugToolDrivers::Protocols::RiscVDebugSpec
|
||||
) * alignTo;
|
||||
}
|
||||
|
||||
Targets::TargetMemoryBuffer DebugTranslator::readMemoryViaAbstractCommand(
|
||||
Targets::TargetMemoryAddress startAddress,
|
||||
Targets::TargetMemorySize bytes
|
||||
) {
|
||||
using DebugModule::Registers::MemoryAccessControlField;
|
||||
|
||||
auto output = TargetMemoryBuffer{};
|
||||
output.reserve(bytes);
|
||||
|
||||
/*
|
||||
* We only need to set the address once. No need to update it as we use the post-increment function to
|
||||
* increment the address. See MemoryAccessControlField::postIncrement
|
||||
*/
|
||||
this->dtmInterface.writeDebugModuleRegister(RegisterAddress::ABSTRACT_DATA_1, startAddress);
|
||||
|
||||
constexpr auto command = AbstractCommandRegister{
|
||||
.control = MemoryAccessControlField{
|
||||
.postIncrement = true,
|
||||
.size = MemoryAccessControlField::MemorySize::SIZE_32,
|
||||
}.value(),
|
||||
.commandType = AbstractCommandRegister::CommandType::MEMORY_ACCESS
|
||||
};
|
||||
|
||||
for (auto address = startAddress; address <= (startAddress + bytes - 1); address += 4) {
|
||||
this->executeAbstractCommand(command);
|
||||
|
||||
const auto data = this->dtmInterface.readDebugModuleRegister(RegisterAddress::ABSTRACT_DATA_0);
|
||||
output.emplace_back(static_cast<unsigned char>(data));
|
||||
output.emplace_back(static_cast<unsigned char>(data >> 8));
|
||||
output.emplace_back(static_cast<unsigned char>(data >> 16));
|
||||
output.emplace_back(static_cast<unsigned char>(data >> 24));
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
void DebugTranslator::writeMemoryViaAbstractCommand(
|
||||
Targets::TargetMemoryAddress startAddress,
|
||||
const TargetMemoryBuffer& buffer
|
||||
) {
|
||||
using DebugModule::Registers::MemoryAccessControlField;
|
||||
|
||||
this->dtmInterface.writeDebugModuleRegister(RegisterAddress::ABSTRACT_DATA_1, startAddress);
|
||||
|
||||
constexpr auto command = AbstractCommandRegister{
|
||||
.control = MemoryAccessControlField{
|
||||
.write = true,
|
||||
.postIncrement = true,
|
||||
.size = MemoryAccessControlField::MemorySize::SIZE_32,
|
||||
}.value(),
|
||||
.commandType = AbstractCommandRegister::CommandType::MEMORY_ACCESS
|
||||
};
|
||||
|
||||
for (TargetMemoryAddress offset = 0; offset < buffer.size(); offset += 4) {
|
||||
this->dtmInterface.writeDebugModuleRegister(
|
||||
RegisterAddress::ABSTRACT_DATA_0,
|
||||
static_cast<RegisterValue>(
|
||||
(buffer[offset + 3] << 24)
|
||||
| (buffer[offset + 2] << 16)
|
||||
| (buffer[offset + 1] << 8)
|
||||
| (buffer[offset])
|
||||
)
|
||||
);
|
||||
|
||||
this->executeAbstractCommand(command);
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<
|
||||
std::reference_wrapper<const TriggerModule::TriggerDescriptor>
|
||||
> DebugTranslator::getAvailableTrigger() {
|
||||
|
||||
@@ -140,6 +140,15 @@ namespace DebugToolDrivers::Protocols::RiscVDebugSpec
|
||||
);
|
||||
Targets::TargetMemorySize alignMemorySize(Targets::TargetMemorySize size, Targets::TargetMemorySize alignTo);
|
||||
|
||||
Targets::TargetMemoryBuffer readMemoryViaAbstractCommand(
|
||||
Targets::TargetMemoryAddress startAddress,
|
||||
Targets::TargetMemorySize bytes
|
||||
);
|
||||
void writeMemoryViaAbstractCommand(
|
||||
Targets::TargetMemoryAddress startAddress,
|
||||
const Targets::TargetMemoryBuffer& buffer
|
||||
);
|
||||
|
||||
std::optional<std::reference_wrapper<const TriggerModule::TriggerDescriptor>> getAvailableTrigger();
|
||||
void clearTrigger(const TriggerModule::TriggerDescriptor& triggerDescriptor);
|
||||
};
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace DebugToolDrivers::Wch
|
||||
this->wchLinkUsbInterface->init();
|
||||
|
||||
this->wchLinkInterface = std::make_unique<Protocols::WchLink::WchLinkInterface>(
|
||||
*(this->wchLinkUsbInterface.get()),
|
||||
*(this->wchLinkUsbInterface),
|
||||
*this
|
||||
);
|
||||
|
||||
@@ -78,7 +78,7 @@ namespace DebugToolDrivers::Wch
|
||||
|
||||
if (!this->wchRiscVTranslator) {
|
||||
this->wchRiscVTranslator = std::make_unique<DebugTranslator>(
|
||||
*(this->wchLinkInterface.get()),
|
||||
*(this->wchLinkInterface),
|
||||
this->toolConfig.riscVDebugTranslatorConfig,
|
||||
targetDescriptionFile,
|
||||
targetConfig
|
||||
|
||||
Reference in New Issue
Block a user