diff options
author | Jan Janssen <medhefgo@web.de> | 2023-02-28 17:44:05 +0100 |
---|---|---|
committer | Jan Janssen <medhefgo@web.de> | 2023-03-10 11:41:08 +0100 |
commit | c4ad9b23cafd67e87abbcdcb186db470a5a487e4 (patch) | |
tree | 4c67c539749c8dfe1653173793644a6181b015e0 | |
parent | 2afeaf1675a6a68636be493a9461e72ce067db19 (diff) | |
download | systemd-c4ad9b23cafd67e87abbcdcb186db470a5a487e4.tar.gz |
boot: Fix debug experience
-rw-r--r-- | src/boot/efi/meson.build | 7 | ||||
-rw-r--r-- | src/boot/efi/util.c | 4 | ||||
-rwxr-xr-x | tools/debug-sd-boot.sh | 18 | ||||
-rw-r--r-- | tools/elf2efi.lds | 2 |
4 files changed, 19 insertions, 12 deletions
diff --git a/src/boot/efi/meson.build b/src/boot/efi/meson.build index 297eb0f5ee..6b04cfb495 100644 --- a/src/boot/efi/meson.build +++ b/src/boot/efi/meson.build @@ -92,6 +92,13 @@ efi_c_args += cc.get_supported_arguments( '-maccumulate-outgoing-args', ) +# Debug information has little value in release builds as no normal human being knows +# how to attach a debugger to EFI binaries running on real hardware. Anyone who does +# certainly has the means to do their own dev build. +if get_option('mode') == 'developer' and get_option('debug') + efi_c_args += '-DEFI_DEBUG' +endif + efi_c_ld_args = [ # We only support bfd. gold is going away, lld has issues with LTO on x86 # and mold does not support linker scripts. diff --git a/src/boot/efi/util.c b/src/boot/efi/util.c index 588d60dd06..c8bbe75277 100644 --- a/src/boot/efi/util.c +++ b/src/boot/efi/util.c @@ -508,9 +508,9 @@ uint64_t get_os_indications_supported(void) { } #ifdef EFI_DEBUG -extern uint8_t _text, _data; +extern uint8_t __ImageBase; __attribute__((noinline)) void notify_debugger(const char *identity, volatile bool wait) { - printf("%s@%p,%p\n", identity, &_text, &_data); + printf("%s@%p\n", identity, &__ImageBase); if (wait) printf("Waiting for debugger to attach...\n"); diff --git a/tools/debug-sd-boot.sh b/tools/debug-sd-boot.sh index b087c1d4d5..0420dbdab7 100755 --- a/tools/debug-sd-boot.sh +++ b/tools/debug-sd-boot.sh @@ -51,19 +51,17 @@ case "${BASH_REMATCH[1]}" in exit 1 esac -# system-boot will print out a line like this to inform us where gdb is supposed to -# look for .text and .data section: -# systemd-boot@0x0,0x0 +# system-boot/stub will print out a line like this to inform us where it was loaded: +# systemd-boot@0xC0DE while read -r line; do - if [[ "${line}" =~ ${target}@(0x[[:xdigit:]]+),(0x[[:xdigit:]]+) ]]; then - text="${BASH_REMATCH[1]}" - data="${BASH_REMATCH[2]}" + if [[ "${line}" =~ ${target}@(0x[[:xdigit:]]+) ]]; then + loaded_base="${BASH_REMATCH[1]}" break fi done <"${2}" -if [[ -z "${text}" || -z "${data}" ]]; then - echo "Could not determine text and data location." +if [[ -z "${loaded_base}" ]]; then + echo "Could not determine loaded image base." exit 1 fi @@ -76,8 +74,8 @@ fi cat >"${gdb_script}" <<EOF file ${binary} -add-symbol-file ${symbols} ${text} -s .data ${data} -set architecture ${arch}" +symbol-file ${symbols} -o ${loaded_base} +set architecture ${arch} EOF if [[ -z "${3}" ]]; then diff --git a/tools/elf2efi.lds b/tools/elf2efi.lds index eed9e279e9..805efc156d 100644 --- a/tools/elf2efi.lds +++ b/tools/elf2efi.lds @@ -1,4 +1,6 @@ SECTIONS { + __ImageBase = .; + /* We skip the first page because the space will be occupied by the PE headers after conversion. */ . = CONSTANT(MAXPAGESIZE); .text ALIGN(CONSTANT(MAXPAGESIZE)) : { |