From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1p5iNN-0007VM-Nd for mharc-grub-devel@gnu.org; Thu, 15 Dec 2022 02:09:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p5iNM-0007Uy-Gy for grub-devel@gnu.org; Thu, 15 Dec 2022 02:09:52 -0500 Received: from mail-qt1-x834.google.com ([2607:f8b0:4864:20::834]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p5iNK-000820-VH for grub-devel@gnu.org; Thu, 15 Dec 2022 02:09:52 -0500 Received: by mail-qt1-x834.google.com with SMTP id jr11so4484793qtb.7 for ; Wed, 14 Dec 2022 23:09:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficientek-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4nGDBs0+Ecom4lBhsXpRdlFr23dJDHH1MdC6mYsB7fs=; b=6fk+s/ZxUnujSNUDzg9l5C8sirj/jZSwq6v5dSu2qTR/x+PARw87rXFS/IKhjibvpJ 2h93QzO4EBfkYdEwD0YyQLq9DiySSETgk1PyyBTvjCFAODEIstpXFIculMVDRQRUrELs PEbW5WmsYDxrggApHj+LnUg9w8CpD9QxPNxU1k+ER6Wm+V0n1qgwQ99WWV8Ms0yYvihM rQKXCWhK55ivr5O32P1Ob2EWkKi9tSi0InUpfXuItE/ARYT2O3w4jDVYiiIuWUFfriSB fdjcQSXchZmuNEzHyKU3bOfRyOTZKsTrpGXsCWhioUujjAH9R42ZfOW/3odd/RVPVmJt wIMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4nGDBs0+Ecom4lBhsXpRdlFr23dJDHH1MdC6mYsB7fs=; b=b81CtW0KQ39A+WNQpHdofXKYFRnpHwpGb/jp8UVc9qDFfhUQ9KMeFUyATRP/4iaBh7 rcGEFTvm2fjFaIfmjOG/03GXlizuk1rdVV0XcJ25Dg/DFZAT0WPH9jvdEFEEYtjhB7JU ADexl6Fr0zFAwlEvdCP9MhRg6GqU9//rCOe5jIjTFG3X+zQiuZwvIbmVso9kERjzKDox ci1z06wqyyvkWCDe/cNCCpFVPLudN8JN5JDl/wW/G/qxKxe2HYEQZBnMW3E2MZ3v42/o WLm+03k64E8RTi1/0YYgfrBRqQXUKlK//pT/0IDCtkIwrPLWo8tEov0BKMOCmTugXElf b/BA== X-Gm-Message-State: ANoB5pkBeZZ89dyD9UFOrCOWHxH+2iGh+T05gRTTZLPTg6uLgr68wpHj OkbZu5aX1kO1/Qd8f50kZdS5ao0vKbpR+4FV X-Google-Smtp-Source: AA0mqf7eXZ36Wm7rEYqUntjXDNey76DpL2frSPz8Hd2vNg5i8P9YUuADyCLk7ahfXNLPx7mY1kDIJw== X-Received: by 2002:ac8:53d1:0:b0:3a7:f091:bfe with SMTP id c17-20020ac853d1000000b003a7f0910bfemr15509044qtq.7.1671088189911; Wed, 14 Dec 2022 23:09:49 -0800 (PST) Received: from crass-HP-ZBook-15-G2.lan ([37.218.244.251]) by smtp.gmail.com with ESMTPSA id fy16-20020a05622a5a1000b003a7ec97c882sm3125068qtb.6.2022.12.14.23.09.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Dec 2022 23:09:49 -0800 (PST) From: Glenn Washburn To: grub-devel@gnu.org, Daniel Kiper Cc: Glenn Washburn , Peter Jones Subject: [PATCH v3 09/15] gdb: If enabled, print line used to load EFI kernel symbols when using gdb_grub script Date: Thu, 15 Dec 2022 01:07:44 -0600 Message-Id: <20221215070750.102591-10-development@efficientek.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221215070750.102591-1-development@efficientek.com> References: <20221215070750.102591-1-development@efficientek.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::834; envelope-from=development@efficientek.com; helo=mail-qt1-x834.google.com X-Spam_score_int: 14 X-Spam_score: 1.4 X-Spam_bar: + X-Spam_report: (1.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: Thu, 15 Dec 2022 07:09:52 -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 | 19 ++++++++++++++++++- include/grub/efi/efi.h | 2 +- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/config.h.in b/config.h.in index 4d1e50eba7..c31eee1bca 100644 --- a/config.h.in +++ b/config.h.in @@ -13,6 +13,9 @@ #define MM_DEBUG @MM_DEBUG@ #endif +/* 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 cf49d6357e..17bd06f7e6 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_msdos_image_header *header; @@ -328,7 +328,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 b67bc73a1b..ed3d463c8f 100644 --- a/grub-core/kern/efi/init.c +++ b/grub-core/kern/efi/init.c @@ -101,10 +101,24 @@ 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; + + text = grub_efi_section_addr (".text"); + if (!text) + return; + + 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 (); @@ -127,6 +141,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 e61272de53..586ac856b5 100644 --- a/include/grub/efi/efi.h +++ b/include/grub/efi/efi.h @@ -109,7 +109,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.34.1