[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v2 2/2] Make a "gdb" dprintf that tells us load addresses
From: |
Daniel Kiper |
Subject: |
Re: [PATCH v2 2/2] Make a "gdb" dprintf that tells us load addresses |
Date: |
Thu, 25 Nov 2021 18:19:02 +0100 |
User-agent: |
NeoMutt/20170113 (1.7.2) |
On Wed, Nov 03, 2021 at 02:22:07PM -0400, Robbie Harwood wrote:
> From: Peter Jones <pjones@redhat.com>
>
> Add a grub_dprintf() call during platform init and during module loading
> that tells us the virtual addresses of the .text and .data sections of
> grub-core/kernel.exec and any modules it loads.
>
> Specifically, it displays them in the gdb "add-symbol-file" syntax, with
> the presumption that there's a variable $grubdir that reflects the path
> to any such binaries.
Could you tell us why this thing has to be displayed as a part of debug
messages? Could you create a separate command which would do the same?
Additionally, I think this kind of information should not be printed if
the lockdown/UEFI Secure Boot is enforced.
> Signed-off-by: Peter Jones <pjones@redhat.com>
> [rharwood@redhat.com: remove custom function, adjust commit message]
> Signed-off-by: Robbie Harwood <rharwood@redhat.com>
> ---
> grub-core/kern/dl.c | 50 +++++++++++++++++++++++++++++++++++++++
> grub-core/kern/efi/efi.c | 4 ++--
> grub-core/kern/efi/init.c | 26 +++++++++++++++++++-
> include/grub/efi/efi.h | 2 +-
> 4 files changed, 78 insertions(+), 4 deletions(-)
>
> diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c
> index 6a52de168..a5def4ea3 100644
> --- a/grub-core/kern/dl.c
> +++ b/grub-core/kern/dl.c
> @@ -447,6 +447,23 @@ grub_dl_find_section (Elf_Ehdr *e, const char *name)
> return s;
> return NULL;
> }
> +static long
> +grub_dl_find_section_index (Elf_Ehdr *e, const char *name)
> +{
> + Elf_Shdr *s;
> + const char *str;
> + unsigned i;
> +
> + s = (Elf_Shdr *) ((char *) e + e->e_shoff + e->e_shstrndx *
> e->e_shentsize);
> + str = (char *) e + s->sh_offset;
> +
> + for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff);
> + i < e->e_shnum;
> + i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize))
> + if (grub_strcmp (str + s->sh_name, name) == 0)
> + return (long)i;
> + return -1;
> +}
>
> /* Me, Vladimir Serbinenko, hereby I add this module check as per new
> GNU module policy. Note that this license check is informative only.
> @@ -607,6 +624,37 @@ grub_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
>
> return GRUB_ERR_NONE;
> }
> +static void
> +grub_dl_print_gdb_info (grub_dl_t mod, Elf_Ehdr *e)
> +{
> + void *text, *data = NULL;
> + long idx;
> +
> + idx = grub_dl_find_section_index (e, ".text");
> + if (idx < 0)
> + return;
> +
> + text = grub_dl_get_section_addr (mod, idx);
> + if (!text)
> + return;
> +
> + idx = grub_dl_find_section_index (e, ".data");
> + if (idx >= 0)
> + data = grub_dl_get_section_addr (mod, idx);
> +
> + if (data)
> + grub_dprintf ("gdb", "add-symbol-file \\\n"
> + "/usr/lib/debug/usr/lib/grub/%s-%s/%s.debug "
> + "\\\n %p -s .data %p\n",
> + GRUB_TARGET_CPU, GRUB_PLATFORM,
> + mod->name, text, data);
> + else
> + grub_dprintf ("gdb", "add-symbol-file \\\n"
> + "/usr/lib/debug/usr/lib/grub/%s-%s/%s.debug "
No, paths cannot be hard coded like here. At least part of them should be
taken from the configure.
Daniel