From fef725de4d25fcb8516935e8acb7f48369eb531e Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Mon, 29 Jun 2015 14:41:21 -0400 Subject: Add a conditional point for a debugger to attach. Signed-off-by: Peter Jones --- fallback.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'fallback.c') diff --git a/fallback.c b/fallback.c index 8489b2e8..cf578d69 100644 --- a/fallback.c +++ b/fallback.c @@ -11,6 +11,7 @@ #include #include "ucs2.h" +#include "variables.h" EFI_LOADED_IMAGE *this_image = NULL; @@ -791,6 +792,35 @@ try_start_first_option(EFI_HANDLE parent_image_handle) return rc; } +EFI_GUID SHIM_LOCK_GUID = { 0x605dab50, 0xe046, 0x4300, {0xab, 0xb6, 0x3d, 0xd8, 0x10, 0xdd, 0x8b, 0x23} }; +extern EFI_STATUS +efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *systab); + +static void +__attribute__((__optimize__("0"))) +debug_hook(void) +{ + EFI_GUID guid = SHIM_LOCK_GUID; + UINT8 *data = NULL; + UINTN dataSize = 0; + EFI_STATUS efi_status; + volatile register int x = 0; + extern char _etext, _edata; + + efi_status = get_variable(L"SHIM_DEBUG", &data, &dataSize, guid); + if (EFI_ERROR(efi_status)) { + return; + } + + if (x) + return; + + x = 1; + Print(L"add-symbol-file /usr/lib/debug/usr/share/shim/" + EFI_ARCH"/fallback.debug %p -s .data %p\n", &_etext, + &_edata); +} + EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *systab) { @@ -798,6 +828,11 @@ efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *systab) InitializeLib(image, systab); + /* + * if SHIM_DEBUG is set, wait for a debugger to attach. + */ + debug_hook(); + rc = uefi_call_wrapper(BS->HandleProtocol, 3, image, &LoadedImageProtocol, (void *)&this_image); if (EFI_ERROR(rc)) { Print(L"Error: could not find loaded image: %d\n", rc); -- cgit v1.2.3