From 831b6a7fb023d86867d7e8e9a860ec41fad40efe Mon Sep 17 00:00:00 2001 From: Jan Janssen Date: Thu, 19 Jan 2023 15:46:43 +0100 Subject: [PATCH] boot: Simplify debug hook --- src/boot/efi/boot.c | 4 +--- src/boot/efi/stub.c | 4 +--- src/boot/efi/util.c | 9 ++++++--- src/boot/efi/util.h | 11 +++-------- 4 files changed, 11 insertions(+), 17 deletions(-) diff --git a/src/boot/efi/boot.c b/src/boot/efi/boot.c index 4ff6398149..e0a1ea7dd8 100644 --- a/src/boot/efi/boot.c +++ b/src/boot/efi/boot.c @@ -2750,9 +2750,7 @@ out: EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) { InitializeLib(image, sys_table); - debug_hook("systemd-boot"); - /* Uncomment the next line if you need to wait for debugger. */ - // debug_break(); + notify_debugger("systemd-boot", /*wait_for_debugger=*/false); EFI_STATUS err = real_main(image); log_wait(); diff --git a/src/boot/efi/stub.c b/src/boot/efi/stub.c index b8e54286de..5f480f14cd 100644 --- a/src/boot/efi/stub.c +++ b/src/boot/efi/stub.c @@ -420,9 +420,7 @@ static EFI_STATUS real_main(EFI_HANDLE image) { EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) { InitializeLib(image, sys_table); - debug_hook("systemd-stub"); - /* Uncomment the next line if you need to wait for debugger. */ - // debug_break(); + notify_debugger("systemd-stub", /*wait_for_debugger=*/false); EFI_STATUS err = real_main(image); log_wait(); diff --git a/src/boot/efi/util.c b/src/boot/efi/util.c index 8cca73a076..353fc03ef0 100644 --- a/src/boot/efi/util.c +++ b/src/boot/efi/util.c @@ -515,10 +515,14 @@ uint64_t get_os_indications_supported(void) { } #ifdef EFI_DEBUG -__attribute__((noinline)) void debug_break(void) { +extern uint8_t _text, _data; +__attribute__((noinline)) void notify_debugger(const char *identity, volatile bool wait) { + printf("%s@%p,%p\n", identity, &_text, &_data); + if (wait) + printf("Waiting for debugger to attach...\n"); + /* This is a poor programmer's breakpoint to wait until a debugger * has attached to us. Just "set variable wait = 0" or "return" to continue. */ - volatile bool wait = true; while (wait) /* Prefer asm based stalling so that gdb has a source location to present. */ #if defined(__i386__) || defined(__x86_64__) @@ -531,7 +535,6 @@ __attribute__((noinline)) void debug_break(void) { } #endif - #ifdef EFI_DEBUG void hexdump(const char16_t *prefix, const void *data, UINTN size) { static const char hex[16] = "0123456789abcdef"; diff --git a/src/boot/efi/util.h b/src/boot/efi/util.h index 2cd35c828f..6a78215b9d 100644 --- a/src/boot/efi/util.h +++ b/src/boot/efi/util.h @@ -171,17 +171,12 @@ static inline void *PHYSICAL_ADDRESS_TO_POINTER(EFI_PHYSICAL_ADDRESS addr) { uint64_t get_os_indications_supported(void); #ifdef EFI_DEBUG -void debug_break(void); -extern uint8_t _text, _data; /* Report the relocated position of text and data sections so that a debugger * can attach to us. See debug-sd-boot.sh for how this can be done. */ -# define debug_hook(identity) printf(identity "@%p,%p\n", &_text, &_data) +void notify_debugger(const char *identity, bool wait); +void hexdump(const char16_t *prefix, const void *data, size_t size); #else -# define debug_hook(identity) -#endif - -#ifdef EFI_DEBUG -void hexdump(const char16_t *prefix, const void *data, UINTN size); +# define notify_debugger(i, w) #endif #if defined(__i386__) || defined(__x86_64__) -- 2.25.1