[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 5/8] gdb: Add functions to make loading from dynamically position
From: |
Glenn Washburn |
Subject: |
[PATCH 5/8] gdb: Add functions to make loading from dynamically positioned targets easier |
Date: |
Sun, 13 Feb 2022 21:42:42 -0600 |
Many targets, such as EFI, load GRUB at addresses that are determined at
runtime. So the load addresses in kernel.exec will almost certainly be
wrong. Given the address of the start of the text and data segments, these
functions will tell GDB to load the symbols at the proper locations.
It is left up to the user to determine how to get the test and data
addresses.
Signed-off-by: Glenn Washburn <development@efficientek.com>
---
grub-core/gdb_grub.in | 54 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 54 insertions(+)
diff --git a/grub-core/gdb_grub.in b/grub-core/gdb_grub.in
index dd1e86bf2..f3c6faf94 100644
--- a/grub-core/gdb_grub.in
+++ b/grub-core/gdb_grub.in
@@ -9,6 +9,60 @@
### Lubomir Kundrak <lkudrak@skosi.org>
###
+define dynamic_load_kernel_exec_symbols
+ shell rm -f .remove-kernel.exec.symfile.gdb
+
+ # Loading symbols is complicated by the fact that kernel.exec is an ELF
+ # ELF binary, but the UEFI runtime is PE32+. All the data sections of
+ # the ELF binary are concatenated (accounting for ELF section alignment)
+ # and put into one .data section in the PE32+ runtime image. So given
+ # the load address of the .data PE32+ section we can determine the
+ # addresses each ELF data section maps to.
+ shell bash -c ' \
+ ( \
+ export PE_TEXT=$1 PE_DATA=$2; \
+ alignup() { \
+ PAD=1; \
+ if [ "$(($1%$2))" -eq 0 ]; then \
+ PAD=0; \
+ fi; \
+ printf "0x%x\n" $(((($1/$2)+$PAD)*$2)); \
+ }; \
+ printf "add-symbol-file kernel.exec ${PE_TEXT}"; \
+ objdump -h kernel.exec | tail -n +6 | \
+ while read IDX NAME SIZE _ _ OFFSET ALIGN; do \
+ read FLAGS; \
+ if [ -n "$FLAGS" ] && [ -z "${FLAGS%%*DATA*}" -o "$NAME" = .bss
]; then \
+ OFF=$(alignup ${OFF:-0} $ALIGN); \
+ echo -n " -s $NAME (${PE_DATA}+$(printf "0x%x" $OFF))"; \
+ OFF=$((${OFF} + 0x${SIZE})); \
+ fi; \
+ done \
+ )' script $arg0 $arg1 >.kernel.exec.loadsym.gdb
+ source .kernel.exec.loadsym.gdb
+end
+document dynamic_load_kernel_exec_symbols
+ Load debugging symbols from kernel.exec given the address of the
+ .text and .data segments of the UEFI binary.
+end
+
+define dynamic_load_symbols
+ dynamic_load_kernel_exec_symbols $arg0 $arg1
+
+ # We may have been very late to loading the kernel.exec symbols and
+ # and modules may already be loaded. So load symbols for any already
+ # loaded.
+ load_all_modules
+
+ runtime_load_module
+end
+document dynamic_load_symbols
+ Load debugging symbols from kernel.exec and any loaded modules given
+ the address of the .text and .data segments of the UEFI binary. Also
+ setup session to automatically load module symbols for modules loaded
+ in the future.
+end
+
# Add section numbers and addresses to .segments.tmp
define dump_module_sections
set $mod = $arg0
--
2.27.0
- [PATCH 0/8] GDB script fixes and improvements, Glenn Washburn, 2022/02/13
- [PATCH 1/8] gdb: Move runtime module loading into runtime_load_module, Glenn Washburn, 2022/02/13
- [PATCH 2/8] gdb: If no modules have been loaded, do not try to load module symbols, Glenn Washburn, 2022/02/13
- [PATCH 3/8] gdb: Do not lazy load module symbols, Glenn Washburn, 2022/02/13
- [PATCH 4/8] gdb: Prevent wrapping when writing to .segments.tmp, Glenn Washburn, 2022/02/13
- [PATCH 5/8] gdb: Add functions to make loading from dynamically positioned targets easier,
Glenn Washburn <=
- [PATCH 6/8] gdb: If enabled, print line used to load EFI kernel symbols when using gdb_grub script, Glenn Washburn, 2022/02/13
- [PATCH 7/8] gdb: Conditionally run GDB script logic for dynamically or statically positioned GRUB, Glenn Washburn, 2022/02/13
- [PATCH 8/8] gdb: Get correct mod variable value, Glenn Washburn, 2022/02/13