Serenity Operating System
at master 64 lines 2.1 kB view raw
1#!/bin/sh 2 3SCRIPT_DIR="$(dirname "${0}")" 4 5if [ -z "$SERENITY_ARCH" ]; then 6 SERENITY_ARCH="x86_64" 7fi 8 9# Set this environment variable to override the default debugger. 10# 11if [ -z "$SERENITY_KERNEL_DEBUGGER" ]; then 12 if [ "$SERENITY_ARCH" = "aarch64" ]; then 13 # Prepend the toolchain aarch64 bin directory so we pick up GDB from there 14 PATH="$SCRIPT_DIR/../Toolchain/Local/aarch64/bin:$PATH" 15 SERENITY_KERNEL_DEBUGGER="aarch64-pc-serenity-gdb" 16 else 17 if command -v x86_64-elf-gdb >/dev/null 2>&1; then 18 SERENITY_KERNEL_DEBUGGER="x86_64-elf-gdb" 19 else 20 SERENITY_KERNEL_DEBUGGER=gdb 21 fi 22 fi 23fi 24 25toolchain_suffix= 26if [ "$SERENITY_TOOLCHAIN" = "Clang" ]; then 27 toolchain_suffix="clang" 28fi 29 30# The QEMU -s option (enabled by default in ./run) sets up a debugger 31# remote on localhost:1234. So point our debugger there, and inform 32# the debugger which binary to load symbols, etc from. 33# 34if [ "$SERENITY_ARCH" = "x86_64" ]; then 35 gdb_arch=i386:x86-64 36 prekernel_image=Prekernel64 37 kernel_base=0x2000200000 38elif [ "$SERENITY_ARCH" = "aarch64" ]; then 39 gdb_arch=aarch64:armv8-r 40 prekernel_image=Prekernel 41 kernel_base=0xc0000000 # FIXME 42fi 43 44# FIXME: This doesn't work when running QEMU inside the WSL2 VM 45if command -v wslpath >/dev/null; then 46 gdb_host=$(powershell.exe "(Test-Connection -ComputerName (hostname) -Count 1).IPV4Address.IPAddressToString" | tr -d '\r\n') 47else 48 gdb_host=${SERENITY_HOST_IP:-127.0.0.1} 49fi 50 51 52exec $SERENITY_KERNEL_DEBUGGER \ 53 -ex "file $SCRIPT_DIR/../Build/${SERENITY_ARCH:-x86_64}$toolchain_suffix/Kernel/Prekernel/$prekernel_image" \ 54 -ex "set confirm off" \ 55 -ex "directory $SCRIPT_DIR/../Build/${SERENITY_ARCH:-x86_64}$toolchain_suffix/" \ 56 -ex "add-symbol-file $SCRIPT_DIR/../Build/${SERENITY_ARCH:-x86_64}$toolchain_suffix/Kernel/Kernel -o $kernel_base" \ 57 -ex "set confirm on" \ 58 -ex "set arch $gdb_arch" \ 59 -ex "set print frame-arguments none" \ 60 -ex "target remote ${gdb_host}:1234" \ 61 -ex "source $SCRIPT_DIR/serenity_gdb.py" \ 62 -ex "layout asm" \ 63 -ex "fs next" \ 64 "$@"