From 59713279a0b08dcef801819c29f2883cd24060c6 Mon Sep 17 00:00:00 2001 From: apio Date: Fri, 29 Mar 2024 12:12:56 +0100 Subject: [PATCH] kernel: Add a hexdump() method to log binary data for debugging --- kernel/src/Log.cpp | 21 +++++++++++++++++++++ kernel/src/Log.h | 2 ++ 2 files changed, 23 insertions(+) diff --git a/kernel/src/Log.cpp b/kernel/src/Log.cpp index 34007c6a..17c8bd59 100644 --- a/kernel/src/Log.cpp +++ b/kernel/src/Log.cpp @@ -6,6 +6,7 @@ #include #include #include +#include static bool g_debug_enabled = true; static bool g_serial_enabled = true; @@ -174,3 +175,23 @@ static bool g_check_already_failed = false; } CPU::efficient_halt(); } + +Result hexdump(void* data, usize size) +{ + StringBuilder sb; + + u8* ptr = (u8*)data; + + while (size) + { + TRY(sb.format("%#2x ", *ptr)); + ptr++; + size--; + } + + auto message = TRY(sb.string()); + + kdbgln("hexdump: %s", message.chars()); + + return {}; +} diff --git a/kernel/src/Log.h b/kernel/src/Log.h index ac92b64b..0118bf1b 100644 --- a/kernel/src/Log.h +++ b/kernel/src/Log.h @@ -26,6 +26,8 @@ void set_text_console_initialized(); #define kwarnln(...) log(LogLevel::Warn, __VA_ARGS__) #define kerrorln(...) log(LogLevel::Error, __VA_ARGS__) +Result hexdump(void* data, usize size); + [[noreturn]] extern void __critical_error_handler(SourceLocation location, const char* expr, const char* failmsg, const char* errmsg);