1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:18:11 +00:00

Everywhere: Replace the multiple impls of print_buffer() with :hex-dump

This commit is contained in:
Ali Mohammad Pur 2021-06-17 13:12:58 +04:30 committed by Ali Mohammad Pur
parent 7eda164c25
commit 2fe9c81b30
3 changed files with 6 additions and 37 deletions

View file

@ -24,10 +24,7 @@ namespace TLS {
inline void print_buffer(ReadonlyBytes buffer) inline void print_buffer(ReadonlyBytes buffer)
{ {
StringBuilder builder(buffer.size() * 2); dbgln("{:hex-dump}", buffer);
for (auto b : buffer)
builder.appendff("{:02x} ", b);
dbgln("{}", builder.string_view());
} }
inline void print_buffer(const ByteBuffer& buffer) inline void print_buffer(const ByteBuffer& buffer)

View file

@ -91,20 +91,10 @@ static int crc32_tests();
static void print_buffer(ReadonlyBytes buffer, int split) static void print_buffer(ReadonlyBytes buffer, int split)
{ {
for (size_t i = 0; i < buffer.size(); ++i) { if (split > 0)
if (split > 0) { out("{:>{}hex-dump}", buffer, split);
if (i % split == 0 && i) { else
out(" "); out("{:hex-dump}", buffer);
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("");
} }
static Core::EventLoop g_loop; static Core::EventLoop g_loop;

View file

@ -22,24 +22,6 @@ static bool g_continue { false };
static void (*old_signal)(int); static void (*old_signal)(int);
static Wasm::DebuggerBytecodeInterpreter g_interpreter; 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) static void sigint_handler(int)
{ {
if (!g_continue) { 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]); warnln("invalid memory index {} (not found)", args[2]);
continue; continue;
} }
print_buffer(mem->data(), 32); warnln("{:>32hex-dump}", mem->data().bytes());
continue; continue;
} }
if (what.is_one_of("i", "instr", "instruction")) { if (what.is_one_of("i", "instr", "instruction")) {