mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 20:24:57 +00:00
Toolchain+Meta: Support kernel debugging with host AArch64 GDB
Previously, we would unconditionally build GDB from source for the AArch64 toolchain. This commit makes it possible to use the system's `gdb` binary if it supports the architecture, or `aarch64-elf-gdb` if such a package is installed. An `aarch64-elf-gdb` package will be available through Homebrew once this PR is merged: https://github.com/Homebrew/homebrew-core/pull/127323
This commit is contained in:
parent
66c12af45f
commit
924758c6f8
2 changed files with 32 additions and 14 deletions
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/sh
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
SCRIPT_DIR="$(dirname "${0}")"
|
SCRIPT_DIR="$(dirname "${0}")"
|
||||||
|
|
||||||
|
@ -9,16 +9,18 @@ fi
|
||||||
# Set this environment variable to override the default debugger.
|
# Set this environment variable to override the default debugger.
|
||||||
#
|
#
|
||||||
if [ -z "$SERENITY_KERNEL_DEBUGGER" ]; then
|
if [ -z "$SERENITY_KERNEL_DEBUGGER" ]; then
|
||||||
if [ "$SERENITY_ARCH" = "aarch64" ]; then
|
# Prepend the toolchain bin directory so we pick up GDB from there
|
||||||
# Prepend the toolchain aarch64 bin directory so we pick up GDB from there
|
PATH="$SCRIPT_DIR/../Toolchain/Local/$SERENITY_ARCH/bin:$PATH"
|
||||||
PATH="$SCRIPT_DIR/../Toolchain/Local/aarch64/bin:$PATH"
|
|
||||||
SERENITY_KERNEL_DEBUGGER="aarch64-pc-serenity-gdb"
|
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"
|
||||||
|
elif command -v gdb >/dev/null && gdb ex 'set architecture' -ex 'quit' | grep "${SERENITY_ARCH//_/-}"; then
|
||||||
|
SERENITY_KERNEL_DEBUGGER="gdb"
|
||||||
else
|
else
|
||||||
if command -v x86_64-elf-gdb >/dev/null 2>&1; then
|
echo "Error: No suitable GDB installation found." >&2
|
||||||
SERENITY_KERNEL_DEBUGGER="x86_64-elf-gdb"
|
exit 1
|
||||||
else
|
|
||||||
SERENITY_KERNEL_DEBUGGER=gdb
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -100,6 +100,21 @@ buildstep() {
|
||||||
"$@" 2>&1 | sed $'s|^|\x1b[34m['"${NAME}"$']\x1b[39m |'
|
"$@" 2>&1 | sed $'s|^|\x1b[34m['"${NAME}"$']\x1b[39m |'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
has_gdb() {
|
||||||
|
ARCH=$1
|
||||||
|
ARCH_DASH="${ARCH//_/-}"
|
||||||
|
if command -v gdb >/dev/null && gdb -ex 'set architecture' -ex 'quit' | grep "$ARCH_DASH"; then
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
command -v "$ARCH"-elf-gdb >/dev/null
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
NEEDS_GDB=1
|
||||||
|
if has_gdb "$ARCH"; then
|
||||||
|
NEEDS_GDB=0
|
||||||
|
fi
|
||||||
|
|
||||||
# === DEPENDENCIES ===
|
# === DEPENDENCIES ===
|
||||||
buildstep dependencies echo "Checking whether 'make' is available..."
|
buildstep dependencies echo "Checking whether 'make' is available..."
|
||||||
if ! command -v ${MAKE:-make} >/dev/null; then
|
if ! command -v ${MAKE:-make} >/dev/null; then
|
||||||
|
@ -182,8 +197,9 @@ popd
|
||||||
# === DOWNLOAD AND PATCH ===
|
# === DOWNLOAD AND PATCH ===
|
||||||
|
|
||||||
pushd "$DIR/Tarballs"
|
pushd "$DIR/Tarballs"
|
||||||
# Build aarch64-gdb for cross-debugging support on x86 systems
|
# Build gdb for cross-debugging support
|
||||||
if [ "$ARCH" = "aarch64" ]; then
|
if [ $NEEDS_GDB -eq 1 ]; then
|
||||||
|
echo "GDB not found for $ARCH. Will build it from source."
|
||||||
md5=""
|
md5=""
|
||||||
if [ -e "$GDB_PKG" ]; then
|
if [ -e "$GDB_PKG" ]; then
|
||||||
md5="$($MD5SUM $GDB_PKG | cut -f1 -d' ')"
|
md5="$($MD5SUM $GDB_PKG | cut -f1 -d' ')"
|
||||||
|
@ -221,7 +237,7 @@ pushd "$DIR/Tarballs"
|
||||||
echo "Skipped downloading gcc"
|
echo "Skipped downloading gcc"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$ARCH" = "aarch64" ]; then
|
if [ $NEEDS_GDB -eq 1 ]; then
|
||||||
if [ -d ${GDB_NAME} ]; then
|
if [ -d ${GDB_NAME} ]; then
|
||||||
rm -rf "${GDB_NAME}"
|
rm -rf "${GDB_NAME}"
|
||||||
rm -rf "$DIR/Build/$ARCH/$GDB_NAME"
|
rm -rf "$DIR/Build/$ARCH/$GDB_NAME"
|
||||||
|
@ -319,7 +335,7 @@ mkdir -p "$DIR/Build/$ARCH"
|
||||||
pushd "$DIR/Build/$ARCH"
|
pushd "$DIR/Build/$ARCH"
|
||||||
unset PKG_CONFIG_LIBDIR # Just in case
|
unset PKG_CONFIG_LIBDIR # Just in case
|
||||||
|
|
||||||
if [ "$ARCH" = "aarch64" ]; then
|
if [ $NEEDS_GDB -eq 1 ]; then
|
||||||
rm -rf gdb
|
rm -rf gdb
|
||||||
mkdir -p gdb
|
mkdir -p gdb
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue