Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1npeTT-0007Km-4B for mharc-grub-devel@gnu.org; Fri, 13 May 2022 19:13:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56172) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1npeTR-0007E0-5H for grub-devel@gnu.org; Fri, 13 May 2022 19:13:29 -0400 Received: from mail-vs1-xe2e.google.com ([2607:f8b0:4864:20::e2e]:44576) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1npeTP-0007R4-DA for grub-devel@gnu.org; Fri, 13 May 2022 19:13:28 -0400 Received: by mail-vs1-xe2e.google.com with SMTP id x8so9870099vsg.11 for ; Fri, 13 May 2022 16:13:27 -0700 (PDT) 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=Q/tGMZX2OZr+ACr7OUqAAAjZ1x5j79VrSsErs/z+c38=; b=Et3FHUK7MLgcV2Fd8fPgjgeJfDAfka+BXGgFlLrh7BboxU/wqhOgEvHSHXltx8GxfR cOrU3Ktr1gN8eAuRqCbDF5h2X12cqa2DJ25QAjgnMhidUaSpOdScYffKOb3bAXpvhjfd LN2xTZiOUwrZgfBHU7xkNsye5cMKDV5gaklumDkUbqOTX1Y/x1/Q71arQh8MMjWRNM6C bTDDktQazbH2U0XVt5h1jt/ZB8YJo34K2kM1jada2Cysk/PNFeNrJx9lUwTUfQ/31kXS JkzqzJ1p4w5v+pNOczM/glIyQzjyOX1pqgODHXn1+TlBZYOdz2sO4IU3wtKAvAxtIYUw XD7A== 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=Q/tGMZX2OZr+ACr7OUqAAAjZ1x5j79VrSsErs/z+c38=; b=PhahTV3G4OwHMwfdAZ+nclIjY2d02IeSpCi9J/VfttzZmY8D7+/lo9CWN8BKa/dGUA rl2CHR5dNHeJmPCuzfSqPr62UcTt88DfI8AtaoLeVyHkOeIOCKF6gAgX1jWwDybnI8r3 QVmmtpB1szskqo+5fCKwBWkizZ/+0b2vM0q0vcED0gbjGFt9F8BhJaVBgSIlAhqDGEhO 7o01vkSHfpEWZWJtfPvotKKrjF10FNBd46y1i3NBObjIB508UoVSsLgSKH3uYWNzsmIn p+PGX2MPTEKepieHqCLQP76IKkpydBCjOFsScfr3P5TI0vW2XJkbxt+qd1VxtMGl7zAq CpFQ== X-Gm-Message-State: AOAM533eMz1qyYkPDjiAS9sRXxAD415LwJUrbPnuKjzQacSOr+0spWX6 fQYgMNTjI/WLdbm60Vp2zIkV7AWmTC3PQd3g X-Google-Smtp-Source: ABdhPJyldHKPX9/4G3JZxghl32cFXWSYqAihQsJ/TgBNqNfoyCb9uT7w/YVhyW8tGWG8qqY4ZUI4iQ== X-Received: by 2002:a67:ae07:0:b0:32d:6ae0:a966 with SMTP id x7-20020a67ae07000000b0032d6ae0a966mr3157250vse.65.1652483606578; Fri, 13 May 2022 16:13:26 -0700 (PDT) Received: from localhost.localdomain ([37.218.244.249]) by smtp.gmail.com with ESMTPSA id 129-20020a1f1387000000b0034e6f1fd067sm423865vkt.49.2022.05.13.16.13.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 16:13:25 -0700 (PDT) From: Glenn Washburn To: grub-devel@gnu.org, Daniel Kiper Cc: Peter Jones , Robbie Harwood , Glenn Washburn Subject: [PATCH v2 09/15] gdb: If enabled, print line used to load EFI kernel symbols when using gdb_grub script Date: Fri, 13 May 2022 18:12:42 -0500 Message-Id: <5043a2afae36621ad4315bbad6663ff7c67ce15a.1652482822.git.development@efficientek.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::e2e; envelope-from=development@efficientek.com; helo=mail-vs1-xe2e.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham 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: Fri, 13 May 2022 23:13:29 -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 01dcbbfc8..6796ed6f0 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 e8a976a22..5c72a2774 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 b67bc73a1..ed3d463c8 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 eb2dfdfce..d771d2018 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.34.1