2020-01-13 09:50:47 +03:00
|
|
|
#!/bin/sh
|
|
|
|
|
2021-09-07 02:14:32 +03:00
|
|
|
SCRIPT_DIR="$(dirname "${0}")"
|
|
|
|
|
2021-09-17 12:06:56 +03:00
|
|
|
if [ -z "$SERENITY_ARCH" ]; then
|
2022-10-02 20:55:22 +03:00
|
|
|
SERENITY_ARCH="x86_64"
|
2021-09-17 12:06:56 +03:00
|
|
|
fi
|
|
|
|
|
2020-01-13 09:50:47 +03:00
|
|
|
# Set this environment variable to override the default debugger.
|
|
|
|
#
|
2021-09-07 02:14:32 +03:00
|
|
|
if [ -z "$SERENITY_KERNEL_DEBUGGER" ]; then
|
|
|
|
if [ "$SERENITY_ARCH" = "aarch64" ]; then
|
|
|
|
# Prepend the toolchain aarch64 bin directory so we pick up GDB from there
|
|
|
|
PATH="$SCRIPT_DIR/../Toolchain/Local/aarch64/bin:$PATH"
|
|
|
|
SERENITY_KERNEL_DEBUGGER="aarch64-pc-serenity-gdb"
|
|
|
|
else
|
|
|
|
SERENITY_KERNEL_DEBUGGER="gdb"
|
|
|
|
fi
|
|
|
|
fi
|
2020-01-13 09:50:47 +03:00
|
|
|
|
2022-02-19 02:39:02 +03:00
|
|
|
toolchain_suffix=
|
|
|
|
if [ "$SERENITY_TOOLCHAIN" = "Clang" ]; then
|
|
|
|
toolchain_suffix="clang"
|
|
|
|
fi
|
|
|
|
|
2020-01-13 09:50:47 +03:00
|
|
|
# The QEMU -s option (enabled by default in ./run) sets up a debugger
|
|
|
|
# remote on localhost:1234. So point our debugger there, and inform
|
|
|
|
# the debugger which binary to load symbols, etc from.
|
|
|
|
#
|
2021-06-24 14:08:19 +03:00
|
|
|
if [ "$SERENITY_ARCH" = "x86_64" ]; then
|
|
|
|
gdb_arch=i386:x86-64
|
2021-07-26 16:10:51 +03:00
|
|
|
prekernel_image=Prekernel64
|
|
|
|
kernel_base=0x2000200000
|
2021-09-07 02:14:32 +03:00
|
|
|
elif [ "$SERENITY_ARCH" = "aarch64" ]; then
|
|
|
|
gdb_arch=aarch64:armv8-r
|
|
|
|
prekernel_image=Prekernel
|
|
|
|
kernel_base=0xc0000000 # FIXME
|
2021-06-24 14:08:19 +03:00
|
|
|
fi
|
|
|
|
|
2021-08-08 02:33:33 +03:00
|
|
|
# FIXME: This doesn't work when running QEMU inside the WSL2 VM
|
|
|
|
if command -v wslpath >/dev/null; then
|
|
|
|
gdb_host=$(powershell.exe "(Test-Connection -ComputerName (hostname) -Count 1).IPV4Address.IPAddressToString" | tr -d '\r\n')
|
|
|
|
else
|
2022-04-19 15:39:57 +03:00
|
|
|
gdb_host=${SERENITY_HOST_IP:-127.0.0.1}
|
2021-08-08 02:33:33 +03:00
|
|
|
fi
|
|
|
|
|
2021-09-07 02:14:32 +03:00
|
|
|
|
2021-04-20 19:37:33 +03:00
|
|
|
exec $SERENITY_KERNEL_DEBUGGER \
|
2022-10-02 20:55:22 +03:00
|
|
|
-ex "file $SCRIPT_DIR/../Build/${SERENITY_ARCH:-x86_64}$toolchain_suffix/Kernel/Prekernel/$prekernel_image" \
|
2021-07-26 16:10:51 +03:00
|
|
|
-ex "set confirm off" \
|
2022-10-02 20:55:22 +03:00
|
|
|
-ex "directory $SCRIPT_DIR/../Build/${SERENITY_ARCH:-x86_64}$toolchain_suffix/" \
|
|
|
|
-ex "add-symbol-file $SCRIPT_DIR/../Build/${SERENITY_ARCH:-x86_64}$toolchain_suffix/Kernel/Kernel -o $kernel_base" \
|
2021-07-26 16:10:51 +03:00
|
|
|
-ex "set confirm on" \
|
2021-06-24 14:08:19 +03:00
|
|
|
-ex "set arch $gdb_arch" \
|
2021-08-14 21:42:54 +03:00
|
|
|
-ex "set print frame-arguments none" \
|
2021-08-08 02:33:33 +03:00
|
|
|
-ex "target remote ${gdb_host}:1234" \
|
2021-09-07 02:14:32 +03:00
|
|
|
-ex "source $SCRIPT_DIR/serenity_gdb.py" \
|
2021-06-29 11:48:01 +03:00
|
|
|
-ex "layout asm" \
|
|
|
|
-ex "fs next" \
|
2021-04-20 19:37:33 +03:00
|
|
|
"$@"
|