]>
git.ipfire.org Git - thirdparty/systemd.git/blob - tools/debug-sd-boot.sh
2 # SPDX-License-Identifier: LGPL-2.1-or-later
6 if [[ $# -lt 2 ]]; then
7 echo "Usage: ${0} TARGET INPUT [GDBSCRIPT]"
8 echo "Debug systemd-boot/stub in QEMU."
10 echo "TARGET should point to the EFI binary to be examined inside the"
11 echo "build directory (systemd-boot\$ARCH.efi or linux\$arch.efi.stub)."
13 echo "INPUT should point to the QEMU serial output pipe. This is used to"
14 echo "extract the location of the symbols. For this to work, QEMU must"
15 echo "be run with '-s -serial pipe:PATH'. Note that QEMU will append"
16 echo ".in/.out to the path, while this script expects the out pipe directly."
18 echo "If GDBSCRIPT is empty, gdb is run directly attached to the boot"
19 echo "loader, otherwise a script is generated in the given path that allows"
20 echo "attaching manually like this:"
21 echo " (gdb) source GDBSCRIPT"
22 echo " (gdb) target remote :1234"
25 echo " mkfifo /tmp/sdboot.{in,out}"
26 echo " qemu-system-x86_64 [...] -s -serial pipe:/tmp/sdboot"
27 echo " ./tools/debug-sd-boot.sh ./build/src/boot/efi/systemd-bootx64.efi \\"
28 echo " /tmp/sdboot.out"
32 binary
=$
(realpath
"${1}")
33 if [[ "${1}" =~ systemd-boot
([[:alnum
:]]+).efi
]]; then
35 symbols
=$
(realpath
"${1%efi}elf")
36 elif [[ "${1}" =~ linux
([[:alnum
:]]+).efi.stub
]]; then
38 symbols
=$
(realpath
"${1%efi.stub}elf.stub")
40 echo "Cannot detect EFI binary '${1}'."
44 case "${BASH_REMATCH[1]}" in
46 x64
) arch
="i386:x86-64";;
47 aa64
) arch
="aarch64";;
48 arm|riscv64
) arch
="${BASH_REMATCH[1]}";;
50 echo "Unknown EFI arch '${BASH_REMATCH[1]}'."
54 # system-boot will print out a line like this to inform us where gdb is supposed to
55 # look for .text and .data section:
56 # systemd-boot@0x0,0x0
57 while read -r line
; do
58 if [[ "${line}" =~
${target}@
(0x
[[:xdigit
:]]+),(0x
[[:xdigit
:]]+) ]]; then
59 text
="${BASH_REMATCH[1]}"
60 data
="${BASH_REMATCH[2]}"
65 if [[ -z "${text}" ||
-z "${data}" ]]; then
66 echo "Could not determine text and data location."
70 if [[ -z "${3}" ]]; then
71 gdb_script
=$
(mktemp
/tmp
/debug-sd-boot.XXXXXX.gdb
)
72 trap 'rm -f "${gdb_script}"' EXIT
78 add-symbol-file ${symbols} ${text} -s .data ${data}
79 set architecture ${arch}" > "${gdb_script}"
81 if [[ -z "${3}" ]]; then
82 gdb
-x "${gdb_script}" -ex "target remote :1234"
84 echo "GDB script written to '${gdb_script}'."