gdb: Add gdbinfo command for printing the load address of the EFI application

EFI firmware determines where to load the GRUB EFI at runtime, and so the
addresses of debug symbols are not known ahead of time. There is a command
defined in the gdb_grub script which will load the debug symbols at the
appropriate addresses, if given the application load address for GRUB.
So add a command named "gdbinfo" to allow the user to print this GDB command
string with the application load address on-demand. For the outputted GDB
command to have any effect when entered into a GDB session, GDB should have
been started with the script as an argument to the -x option or sourced into
an active GDB session before running the outputted command.

Documentation for the gdbinfo command is also added.

Co-developed-by: Peter Jones <pjones@redhat.com>
Signed-off-by: Peter Jones <pjones@redhat.com>
Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
This commit is contained in:
Glenn Washburn authored and Daniel Kiper committed 2023-06-01 12:10:04 +02:00
1 parent db1d70f2f3
commit c016a969d1
7 files changed
+100 -4

No files matched your search

+38
View File
@@ -0,0 +1,38 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2022 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
/* debug.c - aides for debugging the EFI application */
#include <grub/efi/debug.h>
#include <grub/command.h>
#include <grub/i18n.h>
static grub_err_t
grub_cmd_gdbinfo (struct grub_command *cmd __attribute__ ((unused)),
int argc __attribute__ ((unused)),
char **args __attribute__ ((unused)))
{
grub_efi_print_gdb_info ();
return 0;
}
void
grub_efi_register_debug_commands (void)
{
grub_register_command ("gdbinfo", grub_cmd_gdbinfo, 0,
N_("Print infomation useful for GDB debugging"));
}
+2 -2
View File
@@ -320,7 +320,7 @@ grub_efi_get_variable (const char *var, const grub_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;
@@ -349,7 +349,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;
}
+4 -1
View File
@@ -19,6 +19,7 @@
#include <grub/efi/efi.h>
#include <grub/efi/console.h>
#include <grub/efi/debug.h>
#include <grub/efi/disk.h>
#include <grub/efi/sb.h>
#include <grub/lockdown.h>
@@ -104,7 +105,7 @@ grub_addr_t grub_modbase;
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 +128,8 @@ grub_efi_init (void)
grub_efi_system_table->boot_services->set_watchdog_timer (0, 0, 0, NULL);
grub_efidisk_init ();
grub_efi_register_debug_commands ();
}
void (*grub_efi_net_config) (grub_efi_handle_t hnd,