DEFINE_PARSE_NUMBER(char, parse_number8);
DEFINE_PARSE_NUMBER(char16_t, parse_number16);
+char16_t *hexdump(const void *data, size_t size) {
+ static const char hex[16] = "0123456789abcdef";
+ const uint8_t *d = data;
+
+ assert(data || size == 0);
+
+ char16_t *buf = xnew(char16_t, size * 2 + 1);
+
+ for (size_t i = 0; i < size; i++) {
+ buf[i * 2] = hex[d[i] >> 4];
+ buf[i * 2 + 1] = hex[d[i] & 0x0F];
+ }
+
+ buf[size * 2] = 0;
+ return buf;
+}
+
static const char * const warn_table[] = {
[EFI_SUCCESS] = "Success",
[EFI_WARN_UNKNOWN_GLYPH] = "Unknown glyph",
bool parse_number8(const char *s, uint64_t *ret_u, const char **ret_tail);
bool parse_number16(const char16_t *s, uint64_t *ret_u, const char16_t **ret_tail);
+char16_t *hexdump(const void *data, size_t size);
+
#ifdef __clang__
# define _gnu_printf_(a, b) _printf_(a, b)
#else
#include "log.h"
#include "proto/rng.h"
#include "proto/simple-text-io.h"
+#include "util.h"
static unsigned log_count = 0;
return status;
}
+#ifdef EFI_DEBUG
+void log_hexdump(const char16_t *prefix, const void *data, size_t size) {
+ /* Debugging helper — please keep this around, even if not used */
+
+ _cleanup_free_ char16_t *hex = hexdump(data, size);
+ log_internal(EFI_SUCCESS, "%ls[%zu]: %ls", prefix, size, hex);
+}
+#endif
+
void log_wait(void) {
if (log_count == 0)
return;
#define log_error(...) log_internal(EFI_INVALID_PARAMETER, __VA_ARGS__)
#define log_oom() log_internal(EFI_OUT_OF_RESOURCES, "Out of memory.")
#define log_trace() log_internal(EFI_SUCCESS, "%s:%i@%s", __FILE__, __LINE__, __func__)
+
+#ifdef EFI_DEBUG
+void log_hexdump(const char16_t *prefix, const void *data, size_t size);
+#endif
assert_se(streq16(tail, u"rest"));
}
+TEST(test_hexdump) {
+ char16_t *hex;
+
+ hex = hexdump(NULL, 0);
+ assert(streq16(hex, u""));
+ free(hex);
+
+ hex = hexdump("1", 2);
+ assert(streq16(hex, u"3100"));
+ free(hex);
+
+ hex = hexdump("abc", 4);
+ assert(streq16(hex, u"61626300"));
+ free(hex);
+
+ hex = hexdump((uint8_t[]){ 0x0, 0x42, 0xFF, 0xF1, 0x1F }, 5);
+ assert(streq16(hex, u"0042fff11f"));
+ free(hex);
+}
+
_printf_(1, 2) static void test_printf_one(const char *format, ...) {
va_list ap, ap_efi;
va_start(ap, format);
#endif
}
-#ifdef EFI_DEBUG
-void hexdump(const char16_t *prefix, const void *data, size_t size) {
- static const char hex[16] = "0123456789abcdef";
- _cleanup_free_ char16_t *buf = NULL;
- const uint8_t *d = data;
-
- assert(prefix);
- assert(data || size == 0);
-
- /* Debugging helper — please keep this around, even if not used */
-
- buf = xnew(char16_t, size*2+1);
-
- for (size_t i = 0; i < size; i++) {
- buf[i*2] = hex[d[i] >> 4];
- buf[i*2+1] = hex[d[i] & 0x0F];
- }
-
- buf[size*2] = 0;
-
- log_error("%ls[%zu]: %ls", prefix, size, buf);
-}
-#endif
-
#if defined(__i386__) || defined(__x86_64__)
static inline uint8_t inb(uint16_t port) {
uint8_t value;
* be attached. See debug-sd-boot.sh for how this can be done. */
void notify_debugger(const char *identity, bool wait);
-#ifdef EFI_DEBUG
-void hexdump(const char16_t *prefix, const void *data, size_t size);
-#endif
-
/* On x86 the compiler assumes a different incoming stack alignment than what we get.
* This will cause long long variables to be misaligned when building with
* '-mlong-double' (for correct struct layouts). Normally, the compiler realigns the