Formatting keys in log output
This commit is contained in:
@@ -48,7 +48,7 @@ namespace DebugServer::Gdb::CommandPackets
|
||||
const auto peripheralDescriptorOpt = targetDescriptor.tryGetPeripheralDescriptor(peripheralKey);
|
||||
|
||||
if (!peripheralDescriptorOpt.has_value()) {
|
||||
throw Exception{"Unknown peripheral key \"" + peripheralKey + "\""};
|
||||
throw Exception{"Unknown peripheral key `" + peripheralKey + "`"};
|
||||
}
|
||||
|
||||
const auto& peripheralDescriptor = peripheralDescriptorOpt->get();
|
||||
@@ -67,7 +67,7 @@ namespace DebugServer::Gdb::CommandPackets
|
||||
);
|
||||
|
||||
if (!registerGroupDescriptorOpt.has_value()) {
|
||||
throw Exception{"Unknown register group key \"" + registerGroupKey + "\""};
|
||||
throw Exception{"Unknown register group key `" + registerGroupKey + "`"};
|
||||
}
|
||||
|
||||
const auto& registerGroupDescriptor = registerGroupDescriptorOpt->get();
|
||||
@@ -99,10 +99,8 @@ namespace DebugServer::Gdb::CommandPackets
|
||||
"---------- \"" + StringService::applyTerminalColor(
|
||||
peripheralDescriptor.name,
|
||||
StringService::TerminalColor::DARK_GREEN
|
||||
) + "\" (`" + StringService::applyTerminalColor(
|
||||
peripheralDescriptor.key,
|
||||
StringService::TerminalColor::DARK_YELLOW
|
||||
) + "`) peripheral registers ----------\n\n"
|
||||
) + "\" (" + StringService::formatKey(peripheralDescriptor.key)
|
||||
+ ") peripheral registers ----------\n\n"
|
||||
)});
|
||||
|
||||
for (const auto& [groupKey, groupDescriptor] : peripheralDescriptor.registerGroupDescriptorsByKey) {
|
||||
@@ -115,13 +113,11 @@ namespace DebugServer::Gdb::CommandPackets
|
||||
DebugSession& debugSession
|
||||
) {
|
||||
for (const auto* registerDescriptor : this->sortRegisterDescriptors(groupDescriptor.registerDescriptorsByKey)) {
|
||||
auto output = std::string{"`" + registerDescriptor->absoluteGroupKey + "`, "};
|
||||
output += "`" + registerDescriptor->key + "`, ";
|
||||
auto output = StringService::formatKey(registerDescriptor->absoluteGroupKey) + ", ";
|
||||
output += StringService::formatKey(registerDescriptor->key) + ", ";
|
||||
output += "\"" + registerDescriptor->name + "\", ";
|
||||
output += StringService::applyTerminalColor(
|
||||
"0x" + StringService::asciiToUpper(StringService::toHex(registerDescriptor->startAddress)),
|
||||
StringService::TerminalColor::BLUE
|
||||
) + ", ";
|
||||
output += "0x" + StringService::asciiToUpper(StringService::toHex(registerDescriptor->startAddress))
|
||||
+ ", ";
|
||||
output += std::to_string(registerDescriptor->size * 8) + "-bit";
|
||||
|
||||
if (registerDescriptor->description.has_value()) {
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace DebugServer::Gdb::CommandPackets
|
||||
const auto peripheralDescriptorOpt = targetDescriptor.tryGetPeripheralDescriptor(peripheralKey);
|
||||
|
||||
if (!peripheralDescriptorOpt.has_value()) {
|
||||
throw Exception{"Unknown peripheral key \"" + peripheralKey + "\""};
|
||||
throw Exception{"Unknown peripheral key `" + peripheralKey + "`"};
|
||||
}
|
||||
|
||||
const auto& peripheralDescriptor = peripheralDescriptorOpt->get();
|
||||
@@ -67,7 +67,7 @@ namespace DebugServer::Gdb::CommandPackets
|
||||
|
||||
if (!registerGroupDescriptorOpt.has_value()) {
|
||||
if (peripheralDescriptor.registerGroupDescriptorsByKey.size() != 1 || argCount >= 4) {
|
||||
throw Exception{"Unknown register group key \"" + registerGroupKey + "\""};
|
||||
throw Exception{"Unknown register group key `" + registerGroupKey + "`"};
|
||||
}
|
||||
|
||||
registerGroupDescriptorOpt = peripheralDescriptor.registerGroupDescriptorsByKey.begin()->second;
|
||||
@@ -89,7 +89,7 @@ namespace DebugServer::Gdb::CommandPackets
|
||||
const auto registerDescriptorOpt = registerGroupDescriptor.tryGetRegisterDescriptor(*registerKey);
|
||||
|
||||
if (!registerDescriptorOpt.has_value()) {
|
||||
throw Exception{"Unknown register key \"" + *registerKey + "\""};
|
||||
throw Exception{"Unknown register key `" + *registerKey + "`"};
|
||||
}
|
||||
|
||||
this->handleSingleRegisterOutput(registerDescriptorOpt->get(), debugSession, targetControllerService);
|
||||
@@ -112,10 +112,8 @@ namespace DebugServer::Gdb::CommandPackets
|
||||
TargetControllerService& targetControllerService
|
||||
) {
|
||||
auto output = std::string{"\nName: \"" + registerDescriptor.name + "\"\n"};
|
||||
output += "Address: " + StringService::applyTerminalColor(
|
||||
"0x" + StringService::asciiToUpper(StringService::toHex(registerDescriptor.startAddress)),
|
||||
StringService::TerminalColor::BLUE
|
||||
) + "\n";
|
||||
output += "Address: 0x" + StringService::asciiToUpper(StringService::toHex(registerDescriptor.startAddress))
|
||||
+ "\n";
|
||||
output += "Width: " + std::to_string(registerDescriptor.size * 8) + "-bit\n\n";
|
||||
|
||||
output += "----------- Value -----------\n";
|
||||
@@ -177,13 +175,11 @@ namespace DebugServer::Gdb::CommandPackets
|
||||
TargetControllerService& targetControllerService
|
||||
) {
|
||||
for (const auto* registerDescriptor : this->sortRegisterDescriptors(groupDescriptor.registerDescriptorsByKey)) {
|
||||
auto output = std::string{"`" + registerDescriptor->absoluteGroupKey + "`, "};
|
||||
output += "`" + registerDescriptor->key + "`, ";
|
||||
auto output = StringService::formatKey(registerDescriptor->absoluteGroupKey) + ", ";
|
||||
output += StringService::formatKey(registerDescriptor->key) + ", ";
|
||||
output += "\"" + registerDescriptor->name + "\", ";
|
||||
output += StringService::applyTerminalColor(
|
||||
"0x" + StringService::asciiToUpper(StringService::toHex(registerDescriptor->startAddress)),
|
||||
StringService::TerminalColor::BLUE
|
||||
) + ", ";
|
||||
output += "0x" + StringService::asciiToUpper(StringService::toHex(registerDescriptor->startAddress))
|
||||
+ ", ";
|
||||
output += std::to_string(registerDescriptor->size * 8) + "-bit | ";
|
||||
|
||||
if (registerDescriptor->access.readable) {
|
||||
|
||||
@@ -38,13 +38,9 @@ namespace DebugServer::Gdb::CommandPackets
|
||||
|
||||
debugSession.connection.writePacket(ResponsePacket{Services::StringService::toHex(
|
||||
"Target reset complete\n"
|
||||
"Current PC: " + StringService::applyTerminalColor(
|
||||
"0x" + StringService::asciiToUpper(
|
||||
StringService::toHex(targetControllerService.getProgramCounter())
|
||||
),
|
||||
StringService::TerminalColor::BLUE
|
||||
) + "\n"
|
||||
"Use the 'continue' command to begin execution\n"
|
||||
"Current PC: 0x" + StringService::asciiToUpper(
|
||||
StringService::toHex(targetControllerService.getProgramCounter())
|
||||
) + "\nUse the 'continue' command to begin execution\n"
|
||||
)});
|
||||
|
||||
} catch (const Exception& exception) {
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace DebugServer::Gdb::CommandPackets
|
||||
|
||||
const auto peripheralDescriptorOpt = targetDescriptor.tryGetPeripheralDescriptor(peripheralKey);
|
||||
if (!peripheralDescriptorOpt.has_value()) {
|
||||
throw Exception{"Unknown peripheral key \"" + peripheralKey + "\""};
|
||||
throw Exception{"Unknown peripheral key `" + peripheralKey + "`"};
|
||||
}
|
||||
|
||||
const auto& peripheralDescriptor = peripheralDescriptorOpt->get();
|
||||
@@ -63,7 +63,7 @@ namespace DebugServer::Gdb::CommandPackets
|
||||
const auto& registerGroupKey = this->commandArguments[2];
|
||||
registerGroupDescriptorOpt = peripheralDescriptor.tryGetRegisterGroupDescriptor(registerGroupKey);
|
||||
if (!registerGroupDescriptorOpt.has_value()) {
|
||||
throw Exception{"Unknown absolute register group key \"" + registerGroupKey + "\""};
|
||||
throw Exception{"Unknown absolute register group key `" + registerGroupKey + "`"};
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -83,7 +83,7 @@ namespace DebugServer::Gdb::CommandPackets
|
||||
const auto& registerKey = registerGroupKeyProvided ? this->commandArguments[3] : this->commandArguments[2];
|
||||
const auto registerDescriptorOpt = registerGroupDescriptor.tryGetRegisterDescriptor(registerKey);
|
||||
if (!registerDescriptorOpt.has_value()) {
|
||||
throw Exception{"Unknown register key \"" + registerKey + "\""};
|
||||
throw Exception{"Unknown register key `" + registerKey + "`"};
|
||||
}
|
||||
|
||||
const auto& registerDescriptor = registerDescriptorOpt->get();
|
||||
@@ -103,7 +103,7 @@ namespace DebugServer::Gdb::CommandPackets
|
||||
const auto& bitFieldKey = registerGroupKeyProvided ? this->commandArguments[4] : this->commandArguments[3];
|
||||
const auto bitFieldDescriptorOpt = registerDescriptor.tryGetBitFieldDescriptor(bitFieldKey);
|
||||
if (!bitFieldDescriptorOpt.has_value()) {
|
||||
throw Exception{"Unknown bit field key \"" + bitFieldKey + "\""};
|
||||
throw Exception{"Unknown bit field key `" + bitFieldKey + "`"};
|
||||
}
|
||||
|
||||
const auto& bitFieldDescriptor = bitFieldDescriptorOpt->get();
|
||||
@@ -181,10 +181,8 @@ namespace DebugServer::Gdb::CommandPackets
|
||||
"0x" + newValueHex,
|
||||
StringService::TerminalColor::DARK_YELLOW
|
||||
) + " (" + std::to_string(registerDescriptor.size * 8) + "-bit" + ") to \"" + registerDescriptor.name
|
||||
+ "\" register, at address " + StringService::applyTerminalColor(
|
||||
"0x" + StringService::toHex(registerDescriptor.startAddress),
|
||||
StringService::TerminalColor::BLUE
|
||||
) + ", via `" + registerDescriptor.addressSpaceKey + "` address space...\n"
|
||||
+ "\" register, at address 0x" + StringService::toHex(registerDescriptor.startAddress) + ", via "
|
||||
+ StringService::formatKey(registerDescriptor.addressSpaceKey) + " address space...\n"
|
||||
)});
|
||||
|
||||
targetControllerService.writeRegister(registerDescriptor, dynamicValue.data());
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace DebugServer::Gdb::CommandPackets
|
||||
|
||||
const auto peripheralDescriptorOpt = targetDescriptor.tryGetPeripheralDescriptor(peripheralKey);
|
||||
if (!peripheralDescriptorOpt.has_value()) {
|
||||
throw Exception{"Unknown peripheral key \"" + peripheralKey + "\""};
|
||||
throw Exception{"Unknown peripheral key `" + peripheralKey + "`"};
|
||||
}
|
||||
|
||||
const auto& peripheralDescriptor = peripheralDescriptorOpt->get();
|
||||
@@ -62,7 +62,7 @@ namespace DebugServer::Gdb::CommandPackets
|
||||
const auto& registerGroupKey = this->commandArguments[2];
|
||||
registerGroupDescriptorOpt = peripheralDescriptor.tryGetRegisterGroupDescriptor(registerGroupKey);
|
||||
if (!registerGroupDescriptorOpt.has_value()) {
|
||||
throw Exception{"Unknown absolute register group key \"" + registerGroupKey + "\""};
|
||||
throw Exception{"Unknown absolute register group key `" + registerGroupKey + "`"};
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -82,7 +82,7 @@ namespace DebugServer::Gdb::CommandPackets
|
||||
const auto& registerKey = registerGroupKeyProvided ? this->commandArguments[3] : this->commandArguments[2];
|
||||
const auto registerDescriptorOpt = registerGroupDescriptor.tryGetRegisterDescriptor(registerKey);
|
||||
if (!registerDescriptorOpt.has_value()) {
|
||||
throw Exception{"Unknown register key \"" + registerKey + "\""};
|
||||
throw Exception{"Unknown register key `" + registerKey + "`"};
|
||||
}
|
||||
|
||||
const auto& registerDescriptor = registerDescriptorOpt->get();
|
||||
@@ -121,10 +121,8 @@ namespace DebugServer::Gdb::CommandPackets
|
||||
"0x" + StringService::toHex(value).substr(16 - (registerDescriptor.size * 2)),
|
||||
StringService::TerminalColor::DARK_YELLOW
|
||||
) + " (" + std::to_string(buffer.size() * 8) + "-bit" + ") to \"" + registerDescriptor.name
|
||||
+ "\" register, at address " + StringService::applyTerminalColor(
|
||||
"0x" + StringService::toHex(registerDescriptor.startAddress),
|
||||
StringService::TerminalColor::BLUE
|
||||
) + ", via `" + registerDescriptor.addressSpaceKey + "` address space...\n"
|
||||
+ "\" register, at address 0x" + StringService::toHex(registerDescriptor.startAddress) + ", via "
|
||||
+ StringService::formatKey(registerDescriptor.addressSpaceKey) + " address space...\n"
|
||||
)});
|
||||
|
||||
targetControllerService.writeRegister(registerDescriptor, buffer);
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace DebugServer::Gdb::RiscVGdb::CommandPackets
|
||||
throw Exception{"Memory segment (\"" + segmentDescriptor.name + "\") not writable in programming mode"};
|
||||
}
|
||||
|
||||
Logger::debug("Erase segment key: `" + segmentDescriptor.key + "`");
|
||||
Logger::debug("Erase segment key: " + Services::StringService::formatKey(segmentDescriptor.key));
|
||||
|
||||
targetControllerService.enableProgrammingMode();
|
||||
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
#include "EdbgAvrIspInterface.hpp"
|
||||
|
||||
#include "src/TargetController/Exceptions/TargetOperationFailure.hpp"
|
||||
#include "src/Exceptions/InternalFatalErrorException.hpp"
|
||||
#include "src/Logger/Logger.hpp"
|
||||
|
||||
// Command frames
|
||||
#include "CommandFrames/AvrIsp/EnterProgrammingMode.hpp"
|
||||
#include "CommandFrames/AvrIsp/LeaveProgrammingMode.hpp"
|
||||
@@ -12,6 +8,11 @@
|
||||
#include "CommandFrames/AvrIsp/ReadLock.hpp"
|
||||
#include "CommandFrames/AvrIsp/ProgramFuse.hpp"
|
||||
|
||||
#include "src/Services/StringService.hpp"
|
||||
|
||||
#include "src/TargetController/Exceptions/TargetOperationFailure.hpp"
|
||||
#include "src/Exceptions/InternalFatalErrorException.hpp"
|
||||
|
||||
namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr
|
||||
{
|
||||
using namespace Targets::Microchip::Avr8;
|
||||
@@ -155,7 +156,8 @@ namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr
|
||||
}
|
||||
|
||||
throw Exceptions::InternalFatalErrorException{
|
||||
"Could not resolve fuse type from register descriptor (key: \"" + fuseRegisterDescriptor.key + "\")"
|
||||
"Could not resolve fuse type from register descriptor (key: "
|
||||
+ Services::StringService::formatKey(fuseRegisterDescriptor.key) + ")"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <utility>
|
||||
|
||||
#include "src/Services/PathService.hpp"
|
||||
#include "src/Services/StringService.hpp"
|
||||
#include "src/Logger/Logger.hpp"
|
||||
|
||||
#include "src/Exceptions/Exception.hpp"
|
||||
@@ -49,6 +50,8 @@ void RetrieveMemorySnapshots::run(TargetControllerService& targetControllerServi
|
||||
}
|
||||
|
||||
std::vector<MemorySnapshot> RetrieveMemorySnapshots::getSnapshots() {
|
||||
using Services::StringService;
|
||||
|
||||
constexpr auto MAX_SNAPSHOTS = 30;
|
||||
|
||||
const auto snapshotDir = QDir{QString::fromStdString(Services::PathService::memorySnapshotsPath())};
|
||||
@@ -68,8 +71,8 @@ std::vector<MemorySnapshot> RetrieveMemorySnapshots::getSnapshots() {
|
||||
|
||||
if (snapshots.size() >= MAX_SNAPSHOTS) {
|
||||
Logger::warning(
|
||||
"The total number of \"" + this->memorySegmentDescriptor.key
|
||||
+ "\" snapshots exceeds the hard limit of " + std::to_string(MAX_SNAPSHOTS)
|
||||
"The total number of `" +this->memorySegmentDescriptor.key
|
||||
+ "` snapshots exceeds the hard limit of " + std::to_string(MAX_SNAPSHOTS)
|
||||
+ ". Only the most recent " + std::to_string(MAX_SNAPSHOTS) + " snapshots will be loaded."
|
||||
);
|
||||
break;
|
||||
|
||||
@@ -397,8 +397,8 @@ void InsightWindow::selectDefaultVariant() {
|
||||
|
||||
} else {
|
||||
Logger::error(
|
||||
"Invalid target variant key \"" + *(this->insightConfig.defaultVariantKey)
|
||||
+ "\" - no such variant with the given key was found"
|
||||
"Invalid target variant key `" + *(this->insightConfig.defaultVariantKey)
|
||||
+ "` - no such variant with the given key was found"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,76 +176,65 @@ namespace Services
|
||||
return {std::ranges::begin(range), std::ranges::end(range)};
|
||||
}
|
||||
|
||||
std::string StringService::applyTerminalColor(const std::string& string, TerminalColor color) {
|
||||
auto colorCode = std::string{};
|
||||
|
||||
std::string_view StringService::colorCode(const TerminalColor color) {
|
||||
switch (color) {
|
||||
case TerminalColor::BLACK: {
|
||||
colorCode = "\033[30m";
|
||||
break;
|
||||
return "\033[30m";
|
||||
}
|
||||
case TerminalColor::DARK_RED: {
|
||||
colorCode = "\033[31m";
|
||||
break;
|
||||
return "\033[31m";
|
||||
}
|
||||
case TerminalColor::DARK_GREEN: {
|
||||
colorCode = "\033[32m";
|
||||
break;
|
||||
return "\033[32m";
|
||||
}
|
||||
case TerminalColor::DARK_YELLOW: {
|
||||
colorCode = "\033[33m";
|
||||
break;
|
||||
return "\033[33m";
|
||||
}
|
||||
case TerminalColor::DARK_BLUE: {
|
||||
colorCode = "\033[34m";
|
||||
break;
|
||||
return "\033[34m";
|
||||
}
|
||||
case TerminalColor::DARK_MAGENTA: {
|
||||
colorCode = "\033[35m";
|
||||
break;
|
||||
return "\033[35m";
|
||||
}
|
||||
case TerminalColor::DARK_CYAN: {
|
||||
colorCode = "\033[36m";
|
||||
break;
|
||||
return "\033[36m";
|
||||
}
|
||||
case TerminalColor::LIGHT_GRAY: {
|
||||
colorCode = "\033[37m";
|
||||
break;
|
||||
return "\033[37m";
|
||||
}
|
||||
case TerminalColor::DARK_GRAY: {
|
||||
colorCode = "\033[90m";
|
||||
break;
|
||||
return "\033[90m";
|
||||
}
|
||||
case TerminalColor::RED: {
|
||||
colorCode = "\033[91m";
|
||||
break;
|
||||
return "\033[91m";
|
||||
}
|
||||
case TerminalColor::GREEN: {
|
||||
colorCode = "\033[92m";
|
||||
break;
|
||||
return "\033[92m";
|
||||
}
|
||||
case TerminalColor::ORANGE: {
|
||||
colorCode = "\033[93m";
|
||||
break;
|
||||
return "\033[93m";
|
||||
}
|
||||
case TerminalColor::BLUE: {
|
||||
colorCode = "\033[94m";
|
||||
break;
|
||||
return "\033[94m";
|
||||
}
|
||||
case TerminalColor::MAGENTA: {
|
||||
colorCode = "\033[95m";
|
||||
break;
|
||||
return "\033[95m";
|
||||
}
|
||||
case TerminalColor::CYAN: {
|
||||
colorCode = "\033[96m";
|
||||
break;
|
||||
return "\033[96m";
|
||||
}
|
||||
case TerminalColor::WHITE: {
|
||||
colorCode = "\033[97m";
|
||||
break;
|
||||
case TerminalColor::WHITE:
|
||||
default: {
|
||||
return "\033[97m";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return colorCode + string + "\033[0m";
|
||||
std::string StringService::applyTerminalColor(const std::string& string, TerminalColor color) {
|
||||
return std::string{StringService::colorCode(color)} + string + "\033[0m";
|
||||
}
|
||||
|
||||
std::string StringService::formatKey(const std::string_view key) {
|
||||
return "`" + StringService::applyTerminalColor(std::string{key}, StringService::TerminalColor::BLUE) + "`";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,6 +91,8 @@ namespace Services
|
||||
WHITE,
|
||||
};
|
||||
|
||||
static std::string_view colorCode(TerminalColor color);
|
||||
static std::string applyTerminalColor(const std::string& string, TerminalColor color);
|
||||
static std::string formatKey(std::string_view key);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1151,8 +1151,8 @@ namespace TargetController
|
||||
auto& segmentCache = this->getProgramMemoryCache(operation.memorySegmentDescriptor);
|
||||
|
||||
Logger::info(
|
||||
std::to_string(operation.deltaSegments.size()) + " delta segment(s) to be flushed to `"
|
||||
+ operation.memorySegmentDescriptor.key + "`"
|
||||
std::to_string(operation.deltaSegments.size()) + " delta segment(s) to be flushed to "
|
||||
+ StringService::formatKey(operation.memorySegmentDescriptor.key)
|
||||
);
|
||||
for (const auto& deltaSegment : operation.deltaSegments) {
|
||||
Logger::info(
|
||||
|
||||
@@ -81,6 +81,8 @@ namespace Targets::RiscV
|
||||
}
|
||||
|
||||
TargetRegisterDescriptorAndValuePairs RiscV::readRegisters(const TargetRegisterDescriptors& descriptors) {
|
||||
using Services::StringService;
|
||||
|
||||
auto output = TargetRegisterDescriptorAndValuePairs{};
|
||||
|
||||
/*
|
||||
@@ -101,7 +103,7 @@ namespace Targets::RiscV
|
||||
&& !this->csrMemorySegmentDescriptor.addressRange.contains(descriptor->startAddress)
|
||||
) {
|
||||
throw Exceptions::Exception{
|
||||
"Cannot access CPU CSR `" + descriptor->key + "` - unknown memory segment"
|
||||
"Cannot access CPU CSR " + StringService::formatKey(descriptor->key) + " - unknown memory segment"
|
||||
};
|
||||
}
|
||||
|
||||
@@ -110,7 +112,7 @@ namespace Targets::RiscV
|
||||
&& !this->gprMemorySegmentDescriptor.addressRange.contains(descriptor->startAddress)
|
||||
) {
|
||||
throw Exceptions::Exception{
|
||||
"Cannot access CPU GPR `" + descriptor->key + "` - unknown memory segment"
|
||||
"Cannot access CPU GPR " + StringService::formatKey(descriptor->key) + " - unknown memory segment"
|
||||
};
|
||||
}
|
||||
|
||||
@@ -120,7 +122,7 @@ namespace Targets::RiscV
|
||||
|
||||
if (descriptor->addressSpaceId != this->sysAddressSpaceDescriptor.id) {
|
||||
throw Exceptions::Exception{
|
||||
"Cannot access register `" + descriptor->key + "` - unknown address space"
|
||||
"Cannot access register " + StringService::formatKey(descriptor->key) + " - unknown address space"
|
||||
};
|
||||
}
|
||||
|
||||
@@ -148,6 +150,8 @@ namespace Targets::RiscV
|
||||
}
|
||||
|
||||
void RiscV::writeRegisters(const TargetRegisterDescriptorAndValuePairs& registers) {
|
||||
using Services::StringService;
|
||||
|
||||
for (const auto& pair : registers) {
|
||||
const auto& descriptor = pair.first;
|
||||
|
||||
@@ -160,7 +164,7 @@ namespace Targets::RiscV
|
||||
&& !this->csrMemorySegmentDescriptor.addressRange.contains(descriptor.startAddress)
|
||||
) {
|
||||
throw Exceptions::Exception{
|
||||
"Cannot access CPU CSR `" + descriptor.key + "` - unknown memory segment"
|
||||
"Cannot access CPU CSR " + StringService::formatKey(descriptor.key) + " - unknown memory segment"
|
||||
};
|
||||
}
|
||||
|
||||
@@ -169,7 +173,8 @@ namespace Targets::RiscV
|
||||
&& !this->gprMemorySegmentDescriptor.addressRange.contains(descriptor.startAddress)
|
||||
) {
|
||||
throw Exceptions::Exception{
|
||||
"Cannot access CPU GPR `" + descriptor.key + "` - unknown memory segment"
|
||||
"Cannot access CPU GPR " + StringService::formatKey(descriptor.key)
|
||||
+ " - unknown memory segment"
|
||||
};
|
||||
}
|
||||
|
||||
@@ -178,7 +183,10 @@ namespace Targets::RiscV
|
||||
}
|
||||
|
||||
if (descriptor.addressSpaceId != this->sysAddressSpaceDescriptor.id) {
|
||||
throw Exceptions::Exception{"Cannot access register `" + descriptor.key + "` - unknown address space"};
|
||||
throw Exceptions::Exception{
|
||||
"Cannot access register " + StringService::formatKey(descriptor.key)
|
||||
+ " - unknown address space"
|
||||
};
|
||||
}
|
||||
|
||||
auto value = pair.second;
|
||||
@@ -385,6 +393,8 @@ namespace Targets::RiscV
|
||||
const TargetRegisterDescriptor& regDescriptor,
|
||||
const TargetAddressSpaceDescriptor& addressSpaceDescriptor
|
||||
) {
|
||||
using Services::StringService;
|
||||
|
||||
const auto segmentDescriptors = addressSpaceDescriptor.getIntersectingMemorySegmentDescriptors(
|
||||
TargetMemoryAddressRange{
|
||||
regDescriptor.startAddress,
|
||||
@@ -394,13 +404,15 @@ namespace Targets::RiscV
|
||||
|
||||
if (segmentDescriptors.empty()) {
|
||||
throw Exceptions::Exception{
|
||||
"Cannot access system register `" + regDescriptor.key + "` - unknown memory segment"
|
||||
"Cannot access system register " + StringService::formatKey(regDescriptor.key)
|
||||
+ " - unknown memory segment"
|
||||
};
|
||||
}
|
||||
|
||||
if (segmentDescriptors.size() != 1) {
|
||||
throw Exceptions::Exception{
|
||||
"Cannot access system register `" + regDescriptor.key + "` - register spans multiple memory segments"
|
||||
"Cannot access system register " + StringService::formatKey(regDescriptor.key)
|
||||
+ " - register spans multiple memory segments"
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -87,8 +87,8 @@ namespace Targets::RiscV::Wch
|
||||
}
|
||||
|
||||
Logger::info(
|
||||
"Selected program memory segment: \"" + this->selectedProgramSegmentDescriptor.name + "\" (`"
|
||||
+ this->selectedProgramSegmentDescriptor.key + "`)"
|
||||
"Selected program memory segment: \"" + this->selectedProgramSegmentDescriptor.name + "\" ("
|
||||
+ Services::StringService::formatKey(this->selectedProgramSegmentDescriptor.key) + ")"
|
||||
);
|
||||
|
||||
if (
|
||||
@@ -198,8 +198,9 @@ namespace Targets::RiscV::Wch
|
||||
) {
|
||||
if (!this->selectedProgramSegmentDescriptor.programmingModeAccess.writeable) {
|
||||
throw Exceptions::Exception{
|
||||
"The selected program memory segment (`" + this->selectedProgramSegmentDescriptor.key
|
||||
+ "`) is not writable - cannot insert software breakpoint"
|
||||
"The selected program memory segment ("
|
||||
+ Services::StringService::formatKey(this->selectedProgramSegmentDescriptor.key)
|
||||
+ ") is not writable - cannot insert software breakpoint"
|
||||
};
|
||||
}
|
||||
|
||||
@@ -225,8 +226,9 @@ namespace Targets::RiscV::Wch
|
||||
) {
|
||||
if (!this->selectedProgramSegmentDescriptor.programmingModeAccess.writeable) {
|
||||
throw Exceptions::Exception{
|
||||
"The selected program memory segment (`" + this->selectedProgramSegmentDescriptor.key
|
||||
+ "`) is not writable - cannot remove software breakpoint"
|
||||
"The selected program memory segment ("
|
||||
+ Services::StringService::formatKey(this->selectedProgramSegmentDescriptor.key)
|
||||
+ ") is not writable - cannot remove software breakpoint"
|
||||
};
|
||||
}
|
||||
|
||||
@@ -267,8 +269,9 @@ namespace Targets::RiscV::Wch
|
||||
throw Exceptions::Exception{
|
||||
"Read access range (0x" + StringService::toHex(addressRange.startAddress) + " -> 0x"
|
||||
+ StringService::toHex(addressRange.endAddress) + ", " + std::to_string(addressRange.size())
|
||||
+ " bytes) exceeds the boundary of the selected program segment `" + aliasedSegment.key
|
||||
+ "` (0x" + StringService::toHex(aliasedSegment.addressRange.startAddress) + " -> 0x"
|
||||
+ " bytes) exceeds the boundary of the selected program segment "
|
||||
+ StringService::formatKey(aliasedSegment.key) + " (0x"
|
||||
+ StringService::toHex(aliasedSegment.addressRange.startAddress) + " -> 0x"
|
||||
+ StringService::toHex(aliasedSegment.addressRange.endAddress) + ", "
|
||||
+ std::to_string(aliasedSegment.addressRange.size()) + " bytes)"
|
||||
};
|
||||
@@ -308,7 +311,8 @@ namespace Targets::RiscV::Wch
|
||||
&& (!this->programmingMode || !aliasedSegment.programmingModeAccess.writeable)
|
||||
) {
|
||||
throw Exceptions::Exception{
|
||||
"The selected program memory segment (`" + aliasedSegment.key + "`) is not writable"
|
||||
"The selected program memory segment (" + StringService::formatKey(aliasedSegment.key)
|
||||
+ ") is not writable"
|
||||
};
|
||||
}
|
||||
|
||||
@@ -323,8 +327,9 @@ namespace Targets::RiscV::Wch
|
||||
throw Exceptions::Exception{
|
||||
"Write access range (0x" + StringService::toHex(addressRange.startAddress) + " -> 0x"
|
||||
+ StringService::toHex(addressRange.endAddress) + ", " + std::to_string(addressRange.size())
|
||||
+ " bytes) exceeds the boundary of the selected program segment `" + aliasedSegment.key
|
||||
+ "` (0x" + StringService::toHex(aliasedSegment.addressRange.startAddress) + " -> 0x"
|
||||
+ " bytes) exceeds the boundary of the selected program segment "
|
||||
+ StringService::formatKey(aliasedSegment.key) + " (0x"
|
||||
+ StringService::toHex(aliasedSegment.addressRange.startAddress) + " -> 0x"
|
||||
+ StringService::toHex(aliasedSegment.addressRange.endAddress) + ", "
|
||||
+ std::to_string(aliasedSegment.addressRange.size()) + " bytes)"
|
||||
};
|
||||
@@ -350,7 +355,10 @@ namespace Targets::RiscV::Wch
|
||||
return this->eraseMainFlashSegment();
|
||||
}
|
||||
|
||||
Logger::debug("Ignoring erase operation on `" + memorySegmentDescriptor.key + "` segment - not supported");
|
||||
Logger::debug(
|
||||
"Ignoring erase operation on " + Services::StringService::formatKey(memorySegmentDescriptor.key)
|
||||
+ " segment - not supported"
|
||||
);
|
||||
}
|
||||
|
||||
TargetMemoryAddress WchRiscV::getProgramCounter() {
|
||||
@@ -385,8 +393,8 @@ namespace Targets::RiscV::Wch
|
||||
*/
|
||||
const auto deAliasedAddress = this->deAliasMappedAddress(programCounter, actualAliasedSegment);
|
||||
Logger::warning(
|
||||
"The mapped program memory segment is currently aliasing the `" + actualAliasedSegment.key
|
||||
+ "` segment - the program counter (0x" + StringService::toHex(programCounter)
|
||||
"The mapped program memory segment is currently aliasing the " + actualAliasedSegment.key
|
||||
+ " segment - the program counter (0x" + StringService::toHex(programCounter)
|
||||
+ ") has been de-aliased to 0x" + StringService::toHex(deAliasedAddress)
|
||||
);
|
||||
return deAliasedAddress;
|
||||
@@ -518,11 +526,11 @@ namespace Targets::RiscV::Wch
|
||||
output += leftPadding + "mon " + StringService::applyTerminalColor("program_mode", CMD_COLOR) + " "
|
||||
+ StringService::applyTerminalColor("boot", PARAM_COLOR) + "\n";
|
||||
output += leftPadding + " To switch to boot mode, where the mapped program memory segment aliases the boot"
|
||||
" segment (`" + this->bootProgramSegmentDescriptor.key + "`).\n\n";
|
||||
" segment (" + StringService::formatKey(this->bootProgramSegmentDescriptor.key) + ").\n\n";
|
||||
output += leftPadding + "mon " + StringService::applyTerminalColor("program_mode", CMD_COLOR) + " "
|
||||
+ StringService::applyTerminalColor("user", PARAM_COLOR) + "\n";
|
||||
output += leftPadding + " To switch to user mode, where the mapped program memory segment aliases the main"
|
||||
" program segment (`" + this->mainProgramSegmentDescriptor.key + "`).\n";
|
||||
" program segment (" + StringService::formatKey(this->mainProgramSegmentDescriptor.key) + ").\n";
|
||||
|
||||
return output;
|
||||
}
|
||||
@@ -546,25 +554,15 @@ namespace Targets::RiscV::Wch
|
||||
actualAliasedSegment == this->bootProgramSegmentDescriptor ? "boot mode" : "user mode",
|
||||
StringService::TerminalColor::DARK_YELLOW
|
||||
) + "\"\n";
|
||||
response.output += "Aliased memory segment key: `"
|
||||
+ StringService::applyTerminalColor(
|
||||
actualAliasedSegment.key,
|
||||
StringService::TerminalColor::DARK_YELLOW
|
||||
) + "`\n";
|
||||
response.output += "Mapped address -> aliased address: " + StringService::applyTerminalColor(
|
||||
"0x" + StringService::asciiToUpper(
|
||||
StringService::toHex(this->mappedSegmentDescriptor.addressRange.startAddress)
|
||||
),
|
||||
StringService::TerminalColor::BLUE
|
||||
) + " -> " + StringService::applyTerminalColor(
|
||||
"0x" + StringService::asciiToUpper(
|
||||
StringService::toHex(actualAliasedSegment.addressRange.startAddress)
|
||||
),
|
||||
StringService::TerminalColor::BLUE
|
||||
response.output += "Aliased memory segment key: "
|
||||
+ StringService::formatKey(actualAliasedSegment.key) + "\n";
|
||||
response.output += "Mapped address -> aliased address: 0x" + StringService::asciiToUpper(
|
||||
StringService::toHex(this->mappedSegmentDescriptor.addressRange.startAddress)
|
||||
) + " -> 0x" + StringService::asciiToUpper(
|
||||
StringService::toHex(actualAliasedSegment.addressRange.startAddress)
|
||||
) + "\n";
|
||||
response.output += "Program counter: " + StringService::applyTerminalColor(
|
||||
"0x" + StringService::asciiToUpper(StringService::toHex(this->getProgramCounter())),
|
||||
StringService::TerminalColor::BLUE
|
||||
response.output += "Program counter: 0x" + StringService::asciiToUpper(
|
||||
StringService::toHex(this->getProgramCounter())
|
||||
) + "\n";
|
||||
|
||||
return response;
|
||||
@@ -580,9 +578,8 @@ namespace Targets::RiscV::Wch
|
||||
EventManager::triggerEvent(std::make_shared<Events::TargetReset>());
|
||||
|
||||
response.output += "Boot mode has been enabled\n";
|
||||
response.output += "Program counter: " + StringService::applyTerminalColor(
|
||||
"0x" + StringService::asciiToUpper(StringService::toHex(this->getProgramCounter())),
|
||||
StringService::TerminalColor::BLUE
|
||||
response.output += "Program counter: 0x" + StringService::asciiToUpper(
|
||||
StringService::toHex(this->getProgramCounter())
|
||||
) + "\n";
|
||||
|
||||
return response;
|
||||
@@ -598,9 +595,8 @@ namespace Targets::RiscV::Wch
|
||||
EventManager::triggerEvent(std::make_shared<Events::TargetReset>());
|
||||
|
||||
response.output += "User mode has been enabled\n";
|
||||
response.output += "Program counter: " + StringService::applyTerminalColor(
|
||||
"0x" + StringService::asciiToUpper(StringService::toHex(this->getProgramCounter())),
|
||||
StringService::TerminalColor::BLUE
|
||||
response.output += "Program counter: 0x" + StringService::asciiToUpper(
|
||||
StringService::toHex(this->getProgramCounter())
|
||||
) + "\n";
|
||||
|
||||
return response;
|
||||
@@ -687,7 +683,7 @@ namespace Targets::RiscV::Wch
|
||||
probeAddress
|
||||
) ? this->mainProgramSegmentDescriptor : this->bootProgramSegmentDescriptor;
|
||||
|
||||
Logger::debug("Aliased program memory segment: `" + segment.key + "`");
|
||||
Logger::debug("Aliased program memory segment: " + Services::StringService::formatKey(segment.key));
|
||||
return segment;
|
||||
}
|
||||
|
||||
@@ -702,7 +698,8 @@ namespace Targets::RiscV::Wch
|
||||
|
||||
Logger::debug(
|
||||
"De-aliased mapped program memory address 0x" + StringService::toHex(address) + " to 0x"
|
||||
+ StringService::toHex(deAliasedAddress) + " (segment: `" + aliasedSegmentDescriptor.key + "`)"
|
||||
+ StringService::toHex(deAliasedAddress) + " (segment: "
|
||||
+ StringService::formatKey(aliasedSegmentDescriptor.key) + ")"
|
||||
);
|
||||
|
||||
return deAliasedAddress;
|
||||
|
||||
@@ -65,8 +65,8 @@ namespace Targets
|
||||
const auto segment = this->tryGetMemorySegmentDescriptor(key);
|
||||
if (!segment.has_value()) {
|
||||
throw Exceptions::InternalFatalErrorException{
|
||||
"Failed to get memory segment descriptor \"" + key + "\" from address space \"" + this->key
|
||||
+ "\" - segment not found"
|
||||
"Failed to get memory segment descriptor `" + key + "` from address space `" + this->key
|
||||
+ "` - segment not found"
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -99,8 +99,8 @@ namespace Targets
|
||||
}
|
||||
|
||||
throw Exceptions::InternalFatalErrorException{
|
||||
"Failed to get address space descriptor from target descriptor - descriptor containing memory segment \""
|
||||
+ memorySegmentKey + "\" not found"
|
||||
"Failed to get address space descriptor from target descriptor - descriptor containing memory segment `"
|
||||
+ memorySegmentKey + "` not found"
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace Targets
|
||||
if (!descriptor.has_value()) {
|
||||
throw Exceptions::InternalFatalErrorException{
|
||||
"Failed to get register group descriptor \"" + std::string{key}
|
||||
+ "\" from peripheral \"" + this->key + "\" - register group descriptor not found"
|
||||
+ "\" from peripheral `" + this->key + "` - register group descriptor not found"
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user