Files
serenity/Meta/debug-kernel.sh
T
Lucas Chollet cc0939a666 Everywhere: Stop using pc in our target triples
While `pc` is not particularly wrong on x86_64, it's nonsensical on
other supported platforms, namely aarch64 and riscv64.

For consistency, we now don't use this vendor anymore, regardless of the
platform.

Within the LLVM project, we now build as `$arch-serenity`. This is
enough in most cases, the only place where we have to specify a vendor
is the target .cfg file where we use `$arch-unknown-serenity`.

When building GCC and friends, again we simply identify as
`$arch-serenity` and this is enough.

As a result, the tools in Toolchain/Local/$arch/bin are now named after
this pattern: `$arch-serenity-$tool`.

These changes affect the toolchain build scripts, serenity's build
scripts and the Ports.

The last place where we should see `x86_64-pc-serenity` is the output of
`config.sub`, which assume the vendor is `pc` on vendor-less `x86*`
triples. So `x86_64-serenity` is expanded to `x86_64-pc-serenity`,
luckily enough and AFAICT, the whole GNU ecosystem considers `pc`,
`unknown` and vendor-less target triples the same. So `configure`
shouldn't have an issue finding the right tools anyway.

The gn files were edited with sed and are not tested.

This commit also includes a check in `Meta/serenity.sh` to give a nicer
error message when trying to build the system with an old toolchain.

----

To test this patch, on a clean tree I:
 - Ran `./Meta/serenity.sh x86_64 GNU`
 - Ran `./Toolchain/BuildJakt.sh`
 - Tested these ports: python3(configure based), libjxl(cmake based) and
   rizin(meson based)
 - Also booted on aarch64 and risv64

I also repeated the steps above with a Clang toolchain.

On a working tree I tested all the affected ports, the results are:
 - tinycc build fine but can't compile programs, I observed the same on
   master.
 - gdb and epsilon don't build but report the same errors as on master.
 - I manually edited the libgpg-error, and it builds fine.
 - The gcc port works fine.
2026-03-13 20:59:49 +01:00

80 lines
2.9 KiB
Bash
Executable File

#!/usr/bin/env bash
SCRIPT_DIR="$(dirname "${0}")"
if [ -z "$SERENITY_ARCH" ]; then
SERENITY_ARCH="x86_64"
fi
# Set this environment variable to override the default debugger.
#
if [ -z "$SERENITY_KERNEL_DEBUGGER" ]; then
# 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
PATH="$SCRIPT_DIR/../Toolchain/Local/$SERENITY_ARCH/bin:$PATH"
if command -v "$SERENITY_ARCH-serenity-gdb" >/dev/null; then
SERENITY_KERNEL_DEBUGGER="$SERENITY_ARCH-serenity-gdb"
elif command -v "$SERENITY_ARCH-elf-gdb" >/dev/null; then
SERENITY_KERNEL_DEBUGGER="$SERENITY_ARCH-elf-gdb"
elif command -v gdb >/dev/null && gdb -ex 'set architecture' -ex 'quit' 2>&1 | grep "${SERENITY_ARCH//_/-}"; then
SERENITY_KERNEL_DEBUGGER="gdb"
else
echo "Error: No suitable GDB installation found." >&2
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"
exit 1
fi
fi
toolchain_suffix=
if [ "$SERENITY_TOOLCHAIN" = "Clang" ]; then
toolchain_suffix="clang"
fi
# 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.
#
if [ "$SERENITY_ARCH" = "x86_64" ]; then
gdb_arch=i386:x86-64
prekernel_image=Prekernel64
kernel_image=Kernel_shared_object
kernel_base=0x2000200000
elif [ "$SERENITY_ARCH" = "aarch64" ]; then
gdb_arch=aarch64:armv8-r
prekernel_image=Prekernel
kernel_image=Kernel
kernel_base=0x0
elif [ "$SERENITY_ARCH" = "riscv64" ]; then
gdb_arch=riscv:rv64
prekernel_image=Prekernel
kernel_image=Kernel
kernel_base=0x0
fi
# 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
gdb_host=${SERENITY_HOST_IP:-127.0.0.1}
fi
exec $SERENITY_KERNEL_DEBUGGER \
-ex "file $SCRIPT_DIR/../Build/${SERENITY_ARCH:-x86_64}$toolchain_suffix/Kernel/Prekernel/$prekernel_image" \
-ex "set confirm off" \
-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_image -o $kernel_base" \
-ex "set confirm on" \
-ex "set arch $gdb_arch" \
-ex "set print frame-arguments none" \
-ex "set print asm-demangle on" \
-ex "target remote ${gdb_host}:1234" \
-ex "source $SCRIPT_DIR/serenity_gdb.py" \
-ex "layout asm" \
-ex "fs next" \
"$@"