]>
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/stub will print out a line like this to inform us where it was loaded:
56 while read -r line
; do
57 if [[ "${line}" =~
${target}@
(0x
[[:xdigit
:]]+) ]]; then
58 loaded_base
="${BASH_REMATCH[1]}"
63 if [[ -z "${loaded_base}" ]]; then
64 echo "Could not determine loaded image base."
68 if [[ -z "${3}" ]]; then
69 gdb_script
=$
(mktemp
/tmp
/debug-sd-boot.XXXXXX.gdb
)
70 trap 'rm -f "${gdb_script}"' EXIT
75 cat >"${gdb_script}" <<EOF
77 symbol-file ${symbols} -o ${loaded_base}
78 set architecture ${arch}
81 if [[ -z "${3}" ]]; then
82 gdb
-x "${gdb_script}" -ex "target remote :1234"
84 echo "GDB script written to '${gdb_script}'."