From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1p63J3-0003tI-3M for mharc-grub-devel@gnu.org; Fri, 16 Dec 2022 00:30:49 -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 1p63J0-0003qW-ME for grub-devel@gnu.org; Fri, 16 Dec 2022 00:30:46 -0500 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p63Ix-00047r-W0 for grub-devel@gnu.org; Fri, 16 Dec 2022 00:30:45 -0500 Received: by mail-pj1-x1034.google.com with SMTP id v13-20020a17090a6b0d00b00219c3be9830so1321167pjj.4 for ; Thu, 15 Dec 2022 21:30:43 -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=iUYDEY+8n97ccbcSCoIVjSYjDtAerDnxlswqrKWDIkQ2sIPAuY+YMVF0THwFE0xbXJ S7VrMRV3ZczxkybyH58WWlRB08sNyRTzDivIBiJ/OnEeURyaSWi27sGT5PLlyt/pVrdA +aeeg95EyziFIISGwlAtiXJo/ymB4cWOcOFGDSjj3RKoh74QWp+L4ZVrzMvq1zkryspY mSChlp3WWz88n2xUvoEfg7eIm4yJt921HUBSayhQhQTSvHd7wNkjGvqB+6APo5N6fpSP gmVV/CyTNobUfG74srMDTdrPDnvyKHBreFca41RQTQUm6AJQRqPlcqN7KHVA2884vmZj VarQ== 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=oYCjs91K8W6yL+vkQOV0RD85lxOoI7oKrKlifKDjXyCIJKE6SnxVIhI2U0HrqCNPDZ 1VXGzN5b3N+gib6ZmCtzlgYDBPvKxLxLWQwpBXoBBku6Nab+63K6mAMaic93r3yLsFqn HwgSym9XruOuUPgqrBL1ju78GCdiEQumEu1MIB6CBDcoO+O4vmynLFnbvvMmnWBfSey0 KbbXZO9wsczxs3qPGA4CDKy7jVG8Q2h1+TxqJLQ5Grq2BFOxRVh3zRVN6Plf/NqQ9sOK f2ihmrVdIs7P2O2CuUERWv4VY7evh/8ljXRlLlUJC6U2wNOa8NfA4RXaI7M76WODvbma qhOQ== X-Gm-Message-State: AFqh2koxTnuiHS4j/8Dco7qZ/TFaiAEIB6ZyJ/hLJcnabhTcBRMgsmol ga7TL6pdS1Dc6Da53Sxk1a1w5zuDY3whr0a5 X-Google-Smtp-Source: AMrXdXuPNyLi+vn3Vc74XcAGZOtZ2/WYHr97kWyNCxrgGUTvWWFm7/qVM6RxgDZiwBBuZf2sFr3fbQ== X-Received: by 2002:a17:902:a615:b0:190:eb38:f097 with SMTP id u21-20020a170902a61500b00190eb38f097mr8997846plq.45.1671168641986; Thu, 15 Dec 2022 21:30:41 -0800 (PST) Received: from crass-HP-ZBook-15-G2.lan ([37.218.244.251]) by smtp.gmail.com with ESMTPSA id u4-20020a17090341c400b00187033cac81sm577714ple.145.2022.12.15.21.30.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Dec 2022 21:30:41 -0800 (PST) From: Glenn Washburn To: "grub-devel @ gnu . org" , Daniel Kiper Cc: Glenn Washburn , Peter Jones Subject: [PATCH v4 08/15] gdb: If enabled, print line used to load EFI kernel symbols when using gdb_grub script Date: Thu, 15 Dec 2022 23:29:31 -0600 Message-Id: <20221216052938.224564-9-development@efficientek.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221216052938.224564-1-development@efficientek.com> References: <20221216052938.224564-1-development@efficientek.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::1034; envelope-from=development@efficientek.com; helo=mail-pj1-x1034.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: Fri, 16 Dec 2022 05:30:47 -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