debug-kernel.sh 1.9 KB

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