diff --git a/src/DebugServer/Gdb/Connection.cpp b/src/DebugServer/Gdb/Connection.cpp index d4594d3f..fd2cb44a 100644 --- a/src/DebugServer/Gdb/Connection.cpp +++ b/src/DebugServer/Gdb/Connection.cpp @@ -13,6 +13,7 @@ #include "src/Exceptions/Exception.hpp" #include "src/Logger/Logger.hpp" +#include "src/Services/StringService.hpp" namespace Bloom::DebugServer::Gdb { @@ -127,7 +128,12 @@ namespace Bloom::DebugServer::Gdb continue; } - Logger::debug("Read GDB packet: " + std::string(rawPacket.begin(), rawPacket.end())); + Logger::debug( + "Read GDB packet: " + + Services::StringService::replaceUnprintable( + std::string(rawPacket.begin(), rawPacket.end()) + ) + ); // Acknowledge receipt this->write({'+'}); diff --git a/src/Services/StringService.cpp b/src/Services/StringService.cpp index 242c925b..26c79910 100644 --- a/src/Services/StringService.cpp +++ b/src/Services/StringService.cpp @@ -29,6 +29,14 @@ namespace Bloom::Services }); } + std::string StringService::replaceUnprintable(std::string str) { + std::transform(str.begin(), str.end(), str.begin(), [] (unsigned char character) { + return character < 32 || character > 126 ? '?' : character; + }); + + return str; + } + std::string StringService::toHex(unsigned char value) { auto stream = std::stringstream(); stream << std::hex << std::setfill('0') << std::setw(2) << static_cast(value); diff --git a/src/Services/StringService.hpp b/src/Services/StringService.hpp index ee805a0f..32660a2d 100644 --- a/src/Services/StringService.hpp +++ b/src/Services/StringService.hpp @@ -13,6 +13,7 @@ namespace Bloom::Services static std::string asciiToUpper(std::string str); static bool isAscii(const std::string& str); + static std::string replaceUnprintable(std::string str); static std::string toHex(unsigned char value); static std::string toHex(const std::vector& data);