Stop printing non-ASCII characters from GDB in debug logs
This commit is contained in:
@@ -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({'+'});
|
||||
|
||||
@@ -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<unsigned int>(value);
|
||||
|
||||
@@ -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<unsigned char>& data);
|
||||
|
||||
Reference in New Issue
Block a user