Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1nJSHd-0008Ea-Jw for mharc-grub-devel@gnu.org; Sun, 13 Feb 2022 22:44:13 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57758) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nJSHb-00086H-CI for grub-devel@gnu.org; Sun, 13 Feb 2022 22:44:11 -0500 Received: from [2607:f8b0:4864:20::736] (port=40695 helo=mail-qk1-x736.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nJSHZ-0005aR-7p for grub-devel@gnu.org; Sun, 13 Feb 2022 22:44:11 -0500 Received: by mail-qk1-x736.google.com with SMTP id o25so13390820qkj.7 for ; Sun, 13 Feb 2022 19:44:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficientek-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Hv5quGpbl+7cdupHsc2iuZrpfAC/SrtGFY14dF38q68=; b=4Rd8M6km5ykOsVWggEjwXfvAdu/63XASLxDb6/XgtynqV0oU8v1ScDqTvuVVDNqmD5 EnuGNnUvsVx0Lk677KkwwckIN1hJpyiHDnS1SZQLdwbe7OPbcgy5Hw5CRsbPtj+oPqlQ 4A1cUIkcu7GWw5UbrmXTmVWMvl7n/Ec03OYvMK01f8JcRL/S8yl//vNktSK5cqAQJ5ch AMSIpbqkZbV2QlH4nw8eagB59GzCKE0o/FPPKWz/xt0T7zPTa9OUd1qzNXpkvUjqzdUV nUmrd4eamACaX2E8FaESb79oHRU19NH/ICddzOh3VTl125NMjYU0FdOr1MXyjJ1hrhPM h6VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Hv5quGpbl+7cdupHsc2iuZrpfAC/SrtGFY14dF38q68=; b=ldwUUwK5bv1wq6Puo10GaUxN44Le9B+/B8fChj+yHOf7tYbH/AoZz4NA5Y+flbxEeV +i9IcH+HNhRhY4sgLGLovlhM4aPUA7Ks3KZ4rVsbM/5Z9j9jnvMJKPdwaykncMAzBr8e tvEooT1dozHBzkQrQ+kIUEoYxdzeVobcL1pDi+bGxJ9HcAV9TQFEeONDGEg0U6MZPC60 Xu6IU/bcGiwpM7oozBY0q0+dEcuIIKnm4N2e/NzdWGzrBUQxngmLddG/KGway7AxxBil GqYMc+z2SNZ7nvE1p1nWddxl1PHmpHlIp3uRBBCCUXvojI6AUnMK/qlQ8NNk5KJpWhTJ SHtw== X-Gm-Message-State: AOAM5328bzoW+iYcEhQ0Y6Ry4qdyUG/VUgMuzak4XmzkMeEhJWj7GGpi 4ZoRCu/H4/JLVr2hVYdnXnqSxA== X-Google-Smtp-Source: ABdhPJxTqrGOKMSrlT8NvGeuIPUgZmyjAhZEwDoeZ49wVz+Z5VLrY8D60lIGYqLvYpuMg6TY+TJaHA== X-Received: by 2002:a05:620a:d93:: with SMTP id q19mr6084031qkl.437.1644810248394; Sun, 13 Feb 2022 19:44:08 -0800 (PST) Received: from localhost.localdomain (garza.riseup.net. [198.252.153.109]) by smtp.gmail.com with ESMTPSA id z19sm17755800qtj.77.2022.02.13.19.44.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Feb 2022 19:44:07 -0800 (PST) From: Glenn Washburn To: Daniel Kiper , grub-devel@gnu.org Cc: Peter Jones , Robbie Harwood , Glenn Washburn Subject: [PATCH 6/8] gdb: If enabled, print line used to load EFI kernel symbols when using gdb_grub script Date: Sun, 13 Feb 2022 21:42:43 -0600 Message-Id: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::736 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::736; envelope-from=development@efficientek.com; helo=mail-qk1-x736.google.com X-Spam_score_int: -2 X-Spam_score: -0.3 X-Spam_bar: / X-Spam_report: (-0.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.785, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Feb 2022 03:44:11 -0000 If the macro PRINT_GDB_SYM_LOAD_CMD is non-zero, compile code which will print the command needed to load symbols for the GRUB EFI kernel. This is needed because EFI firmware determines where to load the GRUB EFI at runtime, and so the relevant addresses are not known ahead of time. The command is a custom command defined in the gdb_grub GDB script. So GDB should be started with the script as an argument to the -x option or sourced into an active GDB session before running the outputted command. Co-developed-by: Peter Jones Signed-off-by: Glenn Washburn --- config.h.in | 3 +++ grub-core/kern/efi/efi.c | 4 ++-- grub-core/kern/efi/init.c | 25 ++++++++++++++++++++++++- include/grub/efi/efi.h | 2 +- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/config.h.in b/config.h.in index 9e8f9911b..6d0743a78 100644 --- a/config.h.in +++ b/config.h.in @@ -9,6 +9,9 @@ #define GCRYPT_NO_DEPRECATED 1 #define HAVE_MEMMOVE 1 +/* Define to 1 to enable printing of gdb command to load module symbols. */ +#define PRINT_GDB_SYM_LOAD_CMD 0 + /* Define to 1 to enable disk cache statistics. */ #define DISK_CACHE_STATS @DISK_CACHE_STATS@ #define BOOT_TIME_STATS @BOOT_TIME_STATS@ diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c index 18858c327..f492cdd99 100644 --- a/grub-core/kern/efi/efi.c +++ b/grub-core/kern/efi/efi.c @@ -299,7 +299,7 @@ grub_efi_get_variable (const char *var, const grub_efi_guid_t *guid, /* Search the mods section from the PE32/PE32+ image. This code uses a PE32 header, but should work with PE32+ as well. */ grub_addr_t -grub_efi_modules_addr (void) +grub_efi_section_addr (const char *section_name) { grub_efi_loaded_image_t *image; struct grub_pe32_header *header; @@ -324,7 +324,7 @@ grub_efi_modules_addr (void) i < coff_header->num_sections; i++, section++) { - if (grub_strcmp (section->name, "mods") == 0) + if (grub_strcmp (section->name, section_name) == 0) break; } diff --git a/grub-core/kern/efi/init.c b/grub-core/kern/efi/init.c index 7facacf09..f640b8192 100644 --- a/grub-core/kern/efi/init.c +++ b/grub-core/kern/efi/init.c @@ -82,10 +82,30 @@ stack_protector_init (void) grub_addr_t grub_modbase; +#if PRINT_GDB_SYM_LOAD_CMD +static void +grub_efi_print_gdb_info (void) +{ + grub_addr_t text; + grub_addr_t data; + + text = grub_efi_section_addr (".text"); + if (!text) + return; + + data = grub_efi_section_addr (".data"); + if (data) + grub_printf ("dynamic_load_symbols %p -s .data %p\n", + (void *)text, (void *)data); + else + grub_printf ("dynamic_load_symbols %p\n", (void *)text); +} +#endif + void grub_efi_init (void) { - grub_modbase = grub_efi_modules_addr (); + grub_modbase = grub_efi_section_addr ("mods"); /* First of all, initialize the console so that GRUB can display messages. */ grub_console_init (); @@ -108,6 +128,9 @@ grub_efi_init (void) efi_call_4 (grub_efi_system_table->boot_services->set_watchdog_timer, 0, 0, 0, NULL); +#if PRINT_GDB_SYM_LOAD_CMD + grub_efi_print_gdb_info (); +#endif grub_efidisk_init (); } diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h index fc723962d..f3ed52dda 100644 --- a/include/grub/efi/efi.h +++ b/include/grub/efi/efi.h @@ -107,7 +107,7 @@ grub_err_t grub_arch_efi_linux_boot_image(grub_addr_t addr, grub_size_t size, char *args); #endif -grub_addr_t grub_efi_modules_addr (void); +grub_addr_t grub_efi_section_addr (const char *section); void grub_efi_mm_init (void); void grub_efi_mm_fini (void); -- 2.27.0