diff --git a/Userland/Libraries/LibTLS/TLSv12.h b/Userland/Libraries/LibTLS/TLSv12.h index 628453d3ef..b91d362b94 100644 --- a/Userland/Libraries/LibTLS/TLSv12.h +++ b/Userland/Libraries/LibTLS/TLSv12.h @@ -24,10 +24,7 @@ namespace TLS { inline void print_buffer(ReadonlyBytes buffer) { - StringBuilder builder(buffer.size() * 2); - for (auto b : buffer) - builder.appendff("{:02x} ", b); - dbgln("{}", builder.string_view()); + dbgln("{:hex-dump}", buffer); } inline void print_buffer(const ByteBuffer& buffer) diff --git a/Userland/Utilities/test-crypto.cpp b/Userland/Utilities/test-crypto.cpp index 00255b721f..83cd25a0ad 100644 --- a/Userland/Utilities/test-crypto.cpp +++ b/Userland/Utilities/test-crypto.cpp @@ -91,20 +91,10 @@ static int crc32_tests(); static void print_buffer(ReadonlyBytes buffer, int split) { - for (size_t i = 0; i < buffer.size(); ++i) { - if (split > 0) { - if (i % split == 0 && i) { - out(" "); - for (size_t j = i - split; j < i; ++j) { - auto ch = buffer[j]; - out("{}", ch >= 32 && ch <= 127 ? ch : '.'); // silly hack - } - outln(); - } - } - out("{:02x} ", buffer[i]); - } - puts(""); + if (split > 0) + out("{:>{}hex-dump}", buffer, split); + else + out("{:hex-dump}", buffer); } static Core::EventLoop g_loop; diff --git a/Userland/Utilities/wasm.cpp b/Userland/Utilities/wasm.cpp index d8179ee0eb..bccbd5db66 100644 --- a/Userland/Utilities/wasm.cpp +++ b/Userland/Utilities/wasm.cpp @@ -22,24 +22,6 @@ static bool g_continue { false }; static void (*old_signal)(int); static Wasm::DebuggerBytecodeInterpreter g_interpreter; -static void print_buffer(ReadonlyBytes buffer, int split) -{ - for (size_t i = 0; i < buffer.size(); ++i) { - if (split > 0) { - if (i % split == 0 && i) { - out(" "); - for (size_t j = i - split; j < i; ++j) { - auto ch = buffer[j]; - out("{:c}", ch >= 32 && ch <= 127 ? ch : '.'); // silly hack - } - outln(); - } - } - out("{:02x} ", buffer[i]); - } - puts(""); -} - static void sigint_handler(int) { if (!g_continue) { @@ -143,7 +125,7 @@ static bool pre_interpret_hook(Wasm::Configuration& config, Wasm::InstructionPoi warnln("invalid memory index {} (not found)", args[2]); continue; } - print_buffer(mem->data(), 32); + warnln("{:>32hex-dump}", mem->data().bytes()); continue; } if (what.is_one_of("i", "instr", "instruction")) {