2023-04-02 08:15:08 +00:00
|
|
|
#!/usr/bin/env bash
|
2020-01-13 06:50:47 +00:00
|
|
|
|
2021-09-06 23:14:32 +00:00
|
|
|
SCRIPT_DIR="$(dirname "${0}")"
|
|
|
|
|
2021-09-17 09:06:56 +00:00
|
|
|
if [ -z "$SERENITY_ARCH" ]; then
|
2022-10-02 17:55:22 +00:00
|
|
|
SERENITY_ARCH="x86_64"
|
2021-09-17 09:06:56 +00:00
|
|
|
fi
|
|
|
|
|
2020-01-13 06:50:47 +00:00
|
|
|
# Set this environment variable to override the default debugger.
|
|
|
|
#
|
2021-09-06 23:14:32 +00:00
|
|
|
if [ -z "$SERENITY_KERNEL_DEBUGGER" ]; then
|
2023-04-07 15:01:29 +00:00
|
|
|
# Prepend the toolchain's GDB bin directory so we pick up GDB from there
|
|
|
|
PATH="$SCRIPT_DIR/../Toolchain/Local/$SERENITY_ARCH-gdb/bin:$PATH"
|
|
|
|
# GDB used to be installed directly inside the toolchain bin directory
|
2023-04-02 08:15:08 +00:00
|
|
|
PATH="$SCRIPT_DIR/../Toolchain/Local/$SERENITY_ARCH/bin:$PATH"
|
|
|
|
|
|
|
|
if command -v "$SERENITY_ARCH-pc-serenity-gdb" >/dev/null; then
|
|
|
|
SERENITY_KERNEL_DEBUGGER="$SERENITY_ARCH-pc-serenity-gdb"
|
|
|
|
elif command -v "$SERENITY_ARCH-elf-gdb" >/dev/null; then
|
|
|
|
SERENITY_KERNEL_DEBUGGER="$SERENITY_ARCH-elf-gdb"
|
2023-04-09 11:23:24 +00:00
|
|
|
elif command -v gdb >/dev/null && gdb -ex 'set architecture' -ex 'quit' 2>&1 | grep "${SERENITY_ARCH//_/-}"; then
|
2023-04-02 08:15:08 +00:00
|
|
|
SERENITY_KERNEL_DEBUGGER="gdb"
|
2021-09-06 23:14:32 +00:00
|
|
|
else
|
2023-04-02 08:15:08 +00:00
|
|
|
echo "Error: No suitable GDB installation found." >&2
|
2023-04-07 15:01:29 +00:00
|
|
|
echo "Please install $SERENITY_ARCH-elf-gdb or build it with Toolchain/BuildGDB.sh $SERENITY_ARCH" >&2
|
|
|
|
# Prevent tmux from dying instantly by waiting for user input
|
|
|
|
read -rp "Press Enter to exit"
|
2023-04-02 08:15:08 +00:00
|
|
|
exit 1
|
2021-09-06 23:14:32 +00:00
|
|
|
fi
|
|
|
|
fi
|
2020-01-13 06:50:47 +00:00
|
|
|
|
2022-02-18 23:39:02 +00:00
|
|
|
toolchain_suffix=
|
|
|
|
if [ "$SERENITY_TOOLCHAIN" = "Clang" ]; then
|
|
|
|
toolchain_suffix="clang"
|
|
|
|
fi
|
|
|
|
|
2020-01-13 06:50:47 +00: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 11:08:19 +00:00
|
|
|
if [ "$SERENITY_ARCH" = "x86_64" ]; then
|
|
|
|
gdb_arch=i386:x86-64
|
2021-07-26 13:10:51 +00:00
|
|
|
prekernel_image=Prekernel64
|
|
|
|
kernel_base=0x2000200000
|
2021-09-06 23:14:32 +00:00
|
|
|
elif [ "$SERENITY_ARCH" = "aarch64" ]; then
|
|
|
|
gdb_arch=aarch64:armv8-r
|
|
|
|
prekernel_image=Prekernel
|
2023-04-01 19:30:47 +00:00
|
|
|
kernel_base=0x0
|
2024-04-22 13:22:40 +00:00
|
|
|
elif [ "$SERENITY_ARCH" = "riscv64" ]; then
|
|
|
|
gdb_arch=riscv:rv64
|
|
|
|
prekernel_image=Prekernel
|
|
|
|
kernel_base=0x0
|
2021-06-24 11:08:19 +00:00
|
|
|
fi
|
|
|
|
|
2021-08-07 23:33:33 +00: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 12:39:57 +00:00
|
|
|
gdb_host=${SERENITY_HOST_IP:-127.0.0.1}
|
2021-08-07 23:33:33 +00:00
|
|
|
fi
|
|
|
|
|
2021-09-06 23:14:32 +00:00
|
|
|
|
2021-04-20 16:37:33 +00:00
|
|
|
exec $SERENITY_KERNEL_DEBUGGER \
|
2022-10-02 17:55:22 +00:00
|
|
|
-ex "file $SCRIPT_DIR/../Build/${SERENITY_ARCH:-x86_64}$toolchain_suffix/Kernel/Prekernel/$prekernel_image" \
|
2021-07-26 13:10:51 +00:00
|
|
|
-ex "set confirm off" \
|
2022-10-02 17:55:22 +00:00
|
|
|
-ex "directory $SCRIPT_DIR/../Build/${SERENITY_ARCH:-x86_64}$toolchain_suffix/" \
|
2023-03-24 17:31:53 +00:00
|
|
|
-ex "add-symbol-file $SCRIPT_DIR/../Build/${SERENITY_ARCH:-x86_64}$toolchain_suffix/Kernel/Kernel_shared_object -o $kernel_base" \
|
2021-07-26 13:10:51 +00:00
|
|
|
-ex "set confirm on" \
|
2021-06-24 11:08:19 +00:00
|
|
|
-ex "set arch $gdb_arch" \
|
2021-08-14 18:42:54 +00:00
|
|
|
-ex "set print frame-arguments none" \
|
2023-04-01 19:37:52 +00:00
|
|
|
-ex "set print asm-demangle on" \
|
2021-08-07 23:33:33 +00:00
|
|
|
-ex "target remote ${gdb_host}:1234" \
|
2021-09-06 23:14:32 +00:00
|
|
|
-ex "source $SCRIPT_DIR/serenity_gdb.py" \
|
2021-06-29 08:48:01 +00:00
|
|
|
-ex "layout asm" \
|
|
|
|
-ex "fs next" \
|
2021-04-20 16:37:33 +00:00
|
|
|
"$@"
|