* [PATCH] gdb: Add gdbinfo command for printing the load address of the EFI application
@ 2023-05-14 2:25 Glenn Washburn
2023-05-30 14:29 ` Daniel Kiper
0 siblings, 1 reply; 3+ messages in thread
From: Glenn Washburn @ 2023-05-14 2:25 UTC (permalink / raw)
To: grub-devel, Daniel Kiper; +Cc: Glenn Washburn, Peter Jones
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 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>
---
docs/grub.texi | 13 ++++++++++++
grub-core/Makefile.core.def | 1 +
grub-core/kern/efi/debug.c | 38 ++++++++++++++++++++++++++++++++++
grub-core/kern/efi/efi.c | 4 ++--
grub-core/kern/efi/init.c | 5 ++++-
include/grub/efi/debug.h | 41 +++++++++++++++++++++++++++++++++++++
include/grub/efi/efi.h | 2 +-
7 files changed, 100 insertions(+), 4 deletions(-)
create mode 100644 grub-core/kern/efi/debug.c
create mode 100644 include/grub/efi/debug.h
diff --git a/docs/grub.texi b/docs/grub.texi
index 9d4adf0b8ab6..8669f76d176e 100644
--- a/docs/grub.texi
+++ b/docs/grub.texi
@@ -4319,6 +4319,7 @@ you forget a command, you can run the command @command{help}
* export:: Export an environment variable
* false:: Do nothing, unsuccessfully
* fwsetup:: Reboot into the firmware setup menu
+* gdbinfo:: Provide info for debugging with GDB
* gettext:: Translate a string
* gptsync:: Fill an MBR based on GPT entries
* halt:: Shut down your computer
@@ -4851,6 +4852,18 @@ exit successfully if so.
@end deffn
+@node gdbinfo
+@subsection gdbinfo
+
+@deffn Command gdbinfo
+Output text to be used as a GDB command for a GDB session using the gdb_grub
+script and attached to a running GRUB instance. The GDB command that is
+output will tell GDB how to load debugging symbols to their proper runtime
+address. Currently this is only available for EFI platforms. See the Debugging
+in the developer documentation for more information.
+@end deffn
+
+
@node gettext
@subsection gettext
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index fb4cc066c526..3344f15bd5d1 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -206,6 +206,7 @@ kernel = {
efi = disk/efi/efidisk.c;
efi = kern/efi/efi.c;
+ efi = kern/efi/debug.c;
efi = kern/efi/init.c;
efi = kern/efi/mm.c;
efi = term/efi/console.c;
diff --git a/grub-core/kern/efi/debug.c b/grub-core/kern/efi/debug.c
new file mode 100644
index 000000000000..506ad90dca06
--- /dev/null
+++ b/grub-core/kern/efi/debug.c
@@ -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_lockdown ("gdbinfo", grub_cmd_gdbinfo, 0,
+ N_("Print infomation useful for GDB debugging"));
+}
diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c
index 33b95bd7fb67..37ec5bac40be 100644
--- a/grub-core/kern/efi/efi.c
+++ b/grub-core/kern/efi/efi.c
@@ -301,7 +301,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;
@@ -330,7 +330,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 b67bc73a1b01..3645b2bfdcbe 100644
--- a/grub-core/kern/efi/init.c
+++ b/grub-core/kern/efi/init.c
@@ -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 ();
@@ -128,6 +129,8 @@ grub_efi_init (void)
0, 0, 0, NULL);
grub_efidisk_init ();
+
+ grub_efi_register_debug_commands ();
}
void (*grub_efi_net_config) (grub_efi_handle_t hnd,
diff --git a/include/grub/efi/debug.h b/include/grub/efi/debug.h
new file mode 100644
index 000000000000..c2d2a03b06f1
--- /dev/null
+++ b/include/grub/efi/debug.h
@@ -0,0 +1,41 @@
+/*
+ * 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.h - declare variables and functions for EFI debugging support */
+
+#ifndef GRUB_EFI_DEBUG_HEADER
+#define GRUB_EFI_DEBUG_HEADER 1
+
+#include <grub/efi/efi.h>
+#include <grub/misc.h>
+
+
+void grub_efi_register_debug_commands (void);
+
+static inline 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 /* ! GRUB_EFI_DEBUG_HEADER */
diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h
index 1971e1a94865..fcfcd40aaae9 100644
--- a/include/grub/efi/efi.h
+++ b/include/grub/efi/efi.h
@@ -127,7 +127,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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] gdb: Add gdbinfo command for printing the load address of the EFI application
2023-05-14 2:25 [PATCH] gdb: Add gdbinfo command for printing the load address of the EFI application Glenn Washburn
@ 2023-05-30 14:29 ` Daniel Kiper
2023-05-30 14:57 ` Daniel Kiper
0 siblings, 1 reply; 3+ messages in thread
From: Daniel Kiper @ 2023-05-30 14:29 UTC (permalink / raw)
To: Glenn Washburn; +Cc: grub-devel, Peter Jones
On Sat, May 13, 2023 at 09:25:38PM -0500, Glenn Washburn wrote:
> 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 given the application load address for GRUB.
s/given given/given/
> 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>
> ---
> docs/grub.texi | 13 ++++++++++++
> grub-core/Makefile.core.def | 1 +
> grub-core/kern/efi/debug.c | 38 ++++++++++++++++++++++++++++++++++
> grub-core/kern/efi/efi.c | 4 ++--
> grub-core/kern/efi/init.c | 5 ++++-
> include/grub/efi/debug.h | 41 +++++++++++++++++++++++++++++++++++++
> include/grub/efi/efi.h | 2 +-
> 7 files changed, 100 insertions(+), 4 deletions(-)
> create mode 100644 grub-core/kern/efi/debug.c
> create mode 100644 include/grub/efi/debug.h
>
> diff --git a/docs/grub.texi b/docs/grub.texi
> index 9d4adf0b8ab6..8669f76d176e 100644
> --- a/docs/grub.texi
> +++ b/docs/grub.texi
> @@ -4319,6 +4319,7 @@ you forget a command, you can run the command @command{help}
> * export:: Export an environment variable
> * false:: Do nothing, unsuccessfully
> * fwsetup:: Reboot into the firmware setup menu
> +* gdbinfo:: Provide info for debugging with GDB
> * gettext:: Translate a string
> * gptsync:: Fill an MBR based on GPT entries
> * halt:: Shut down your computer
> @@ -4851,6 +4852,18 @@ exit successfully if so.
> @end deffn
>
>
> +@node gdbinfo
> +@subsection gdbinfo
> +
> +@deffn Command gdbinfo
> +Output text to be used as a GDB command for a GDB session using the gdb_grub
> +script and attached to a running GRUB instance. The GDB command that is
> +output will tell GDB how to load debugging symbols to their proper runtime
> +address. Currently this is only available for EFI platforms. See the Debugging
> +in the developer documentation for more information.
> +@end deffn
> +
> +
> @node gettext
> @subsection gettext
>
> diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
> index fb4cc066c526..3344f15bd5d1 100644
> --- a/grub-core/Makefile.core.def
> +++ b/grub-core/Makefile.core.def
> @@ -206,6 +206,7 @@ kernel = {
>
> efi = disk/efi/efidisk.c;
> efi = kern/efi/efi.c;
> + efi = kern/efi/debug.c;
> efi = kern/efi/init.c;
> efi = kern/efi/mm.c;
> efi = term/efi/console.c;
> diff --git a/grub-core/kern/efi/debug.c b/grub-core/kern/efi/debug.c
> new file mode 100644
> index 000000000000..506ad90dca06
> --- /dev/null
> +++ b/grub-core/kern/efi/debug.c
> @@ -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_lockdown ("gdbinfo", grub_cmd_gdbinfo, 0,
> + N_("Print infomation useful for GDB debugging"));
I think we agreed after some discussion we can enable gdbinfo command
even on UEFI platforms with Secure Boot enabled. So, I would do
s/grub_register_command_lockdown/grub_register_command/
Otherwise Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>...
I can make above mentioned fixes for you before push...
Daniel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] gdb: Add gdbinfo command for printing the load address of the EFI application
2023-05-30 14:29 ` Daniel Kiper
@ 2023-05-30 14:57 ` Daniel Kiper
0 siblings, 0 replies; 3+ messages in thread
From: Daniel Kiper @ 2023-05-30 14:57 UTC (permalink / raw)
To: Glenn Washburn; +Cc: grub-devel, Peter Jones
On Tue, May 30, 2023 at 04:29:08PM +0200, Daniel Kiper wrote:
> On Sat, May 13, 2023 at 09:25:38PM -0500, Glenn Washburn wrote:
> > 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 given the application load address for GRUB.
>
> s/given given/given/
>
> > 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>
> > ---
> > docs/grub.texi | 13 ++++++++++++
> > grub-core/Makefile.core.def | 1 +
> > grub-core/kern/efi/debug.c | 38 ++++++++++++++++++++++++++++++++++
> > grub-core/kern/efi/efi.c | 4 ++--
> > grub-core/kern/efi/init.c | 5 ++++-
> > include/grub/efi/debug.h | 41 +++++++++++++++++++++++++++++++++++++
> > include/grub/efi/efi.h | 2 +-
> > 7 files changed, 100 insertions(+), 4 deletions(-)
> > create mode 100644 grub-core/kern/efi/debug.c
> > create mode 100644 include/grub/efi/debug.h
> >
> > diff --git a/docs/grub.texi b/docs/grub.texi
> > index 9d4adf0b8ab6..8669f76d176e 100644
> > --- a/docs/grub.texi
> > +++ b/docs/grub.texi
> > @@ -4319,6 +4319,7 @@ you forget a command, you can run the command @command{help}
> > * export:: Export an environment variable
> > * false:: Do nothing, unsuccessfully
> > * fwsetup:: Reboot into the firmware setup menu
> > +* gdbinfo:: Provide info for debugging with GDB
> > * gettext:: Translate a string
> > * gptsync:: Fill an MBR based on GPT entries
> > * halt:: Shut down your computer
> > @@ -4851,6 +4852,18 @@ exit successfully if so.
> > @end deffn
> >
> >
> > +@node gdbinfo
> > +@subsection gdbinfo
> > +
> > +@deffn Command gdbinfo
> > +Output text to be used as a GDB command for a GDB session using the gdb_grub
> > +script and attached to a running GRUB instance. The GDB command that is
> > +output will tell GDB how to load debugging symbols to their proper runtime
> > +address. Currently this is only available for EFI platforms. See the Debugging
> > +in the developer documentation for more information.
> > +@end deffn
> > +
> > +
> > @node gettext
> > @subsection gettext
> >
> > diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
> > index fb4cc066c526..3344f15bd5d1 100644
> > --- a/grub-core/Makefile.core.def
> > +++ b/grub-core/Makefile.core.def
> > @@ -206,6 +206,7 @@ kernel = {
> >
> > efi = disk/efi/efidisk.c;
> > efi = kern/efi/efi.c;
> > + efi = kern/efi/debug.c;
> > efi = kern/efi/init.c;
> > efi = kern/efi/mm.c;
> > efi = term/efi/console.c;
> > diff --git a/grub-core/kern/efi/debug.c b/grub-core/kern/efi/debug.c
> > new file mode 100644
> > index 000000000000..506ad90dca06
> > --- /dev/null
> > +++ b/grub-core/kern/efi/debug.c
> > @@ -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_lockdown ("gdbinfo", grub_cmd_gdbinfo, 0,
> > + N_("Print infomation useful for GDB debugging"));
>
> I think we agreed after some discussion we can enable gdbinfo command
> even on UEFI platforms with Secure Boot enabled. So, I would do
> s/grub_register_command_lockdown/grub_register_command/
>
> Otherwise Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>...
>
> I can make above mentioned fixes for you before push...
Nah! This patch does not apply due to significant changes in the EFI
code. Could you rebase it on top of [1].
Daniel
[1] https://lists.gnu.org/archive/html/grub-devel/2023-05/msg00147.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-05-30 14:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-14 2:25 [PATCH] gdb: Add gdbinfo command for printing the load address of the EFI application Glenn Washburn
2023-05-30 14:29 ` Daniel Kiper
2023-05-30 14:57 ` Daniel Kiper
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.