Files
linux-kernel-module-cheat/rungdb
2018-08-14 00:27:55 +01:00

88 lines
1.9 KiB
Bash
Executable File

#!/usr/bin/env bash
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common"
after=
before=
lx_symbols="-ex 'lx-symbols ../kernel_module-1.0/' \\
"
kgdb=false
docontinue=true
while getopts "A:a:b:CgkL:n:X${common_getopts_flags}" OPT; do
case "$OPT" in
A)
after="$OPTARG"
;;
b)
before="$OPTARG"
;;
C)
# No Continue.
docontinue=false
;;
k)
kgdb=true
;;
X)
lx_symbols=
;;
?)
common_getopts_case "$OPT"
;;
esac
done
shift "$(($OPTIND - 1))"
if [ "$#" -gt 0 ]; then
brk="-ex 'break ${1}' \\
"
shift
else
brk=
fi
common_setup
gdb="${common_host_dir}/usr/bin/${common_arch}-linux-gdb \\
${before}"
if "$kgdb"; then
cmd="\
${gdb}\
-q \\
-ex 'add-auto-load-safe-path $(pwd)' \\
-ex 'file vmlinux' \\
-ex 'target remote localhost:${common_gdb_port}' \\
"
else
# ## lx-symbols
#
# ### lx-symbols after continue
#
# lx symbols must be run after continue.
#
# running it immediately after the connect on the bootloader leads to failure,
# likely because kernel structure on which it depends are not yet available.
#
# With this setup, continue runs, and lx-symbols only runs when a break happens,
# either by hitting the breakpoint, or by entering Ctrl + C.
#
# Sure, if the user sets a break on a raw address of the bootloader,
# problems will still arise, but let's think about that some other time.
#
# ### lx-symbols autoload
#
# The lx-symbols commands gets loaded through the file vmlinux-gdb.py
# which gets put on the kernel build root when python debugging scripts are enabled.
cmd="\
${gdb}\
-q \\
-ex 'add-auto-load-safe-path $(pwd)' \\
-ex 'file vmlinux' \\
-ex 'target remote localhost:${common_gdb_port}' \\
${brk}\
"
fi
if "$docontinue"; then
cmd="${cmd}\
-ex continue \\
${lx_symbols}\
"
fi
"${common_root_dir}/eeval" "cd '${common_linux_variant_dir}' && \\
$cmd $after" "${common_run_dir}/rungdb.sh"