Files
Ciro Santilli 036225b268 run: use getopt
2018-08-23 08:54:47 +01:00

102 lines
2.1 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
parsed=$(getopt \
-o "A:a:b:CgkL:n:X${common_getopt_flags}" \
-l "\
after:,
before:,
kgdb:,
${common_getopt_flags_long}\
" \
-- "$@")
eval set -- "$parsed"
while true; do
case "$1" in
-A|--after)
after="$2"
shift 2
;;
-b|--before)
before="$2"
shift 2
;;
-C)
# No Continue.
docontinue=false
shift
;;
-k|--kgdb)
kgdb=true
shift
;;
-X)
lx_symbols=
shift
;;
*)
common_getopt_case "$@"
;;
esac
done
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"