summaryrefslogtreecommitdiff
path: root/Toolchain
diff options
context:
space:
mode:
authorDaniel Bertalan <dani@danielbertalan.dev>2023-04-02 10:15:08 +0200
committerAndrew Kaster <andrewdkaster@gmail.com>2023-04-03 19:56:09 -0600
commit924758c6f8bcf463b5e996e5168d3a01779da912 (patch)
tree6bb9134eec78dde25b43bed74fc78d1b8087baae /Toolchain
parent66c12af45fbd19a2bff2098cf8909b75b8ab784a (diff)
downloadserenity-924758c6f8bcf463b5e996e5168d3a01779da912.zip
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
Diffstat (limited to 'Toolchain')
-rwxr-xr-xToolchain/BuildIt.sh24
1 files changed, 20 insertions, 4 deletions
diff --git a/Toolchain/BuildIt.sh b/Toolchain/BuildIt.sh
index 3a0473c030..16ea39befe 100755
--- a/Toolchain/BuildIt.sh
+++ b/Toolchain/BuildIt.sh
@@ -100,6 +100,21 @@ buildstep() {
"$@" 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 ===
buildstep dependencies echo "Checking whether 'make' is available..."
if ! command -v ${MAKE:-make} >/dev/null; then
@@ -182,8 +197,9 @@ popd
# === DOWNLOAD AND PATCH ===
pushd "$DIR/Tarballs"
- # Build aarch64-gdb for cross-debugging support on x86 systems
- if [ "$ARCH" = "aarch64" ]; then
+ # Build gdb for cross-debugging support
+ if [ $NEEDS_GDB -eq 1 ]; then
+ echo "GDB not found for $ARCH. Will build it from source."
md5=""
if [ -e "$GDB_PKG" ]; then
md5="$($MD5SUM $GDB_PKG | cut -f1 -d' ')"
@@ -221,7 +237,7 @@ pushd "$DIR/Tarballs"
echo "Skipped downloading gcc"
fi
- if [ "$ARCH" = "aarch64" ]; then
+ if [ $NEEDS_GDB -eq 1 ]; then
if [ -d ${GDB_NAME} ]; then
rm -rf "${GDB_NAME}"
rm -rf "$DIR/Build/$ARCH/$GDB_NAME"
@@ -319,7 +335,7 @@ mkdir -p "$DIR/Build/$ARCH"
pushd "$DIR/Build/$ARCH"
unset PKG_CONFIG_LIBDIR # Just in case
- if [ "$ARCH" = "aarch64" ]; then
+ if [ $NEEDS_GDB -eq 1 ]; then
rm -rf gdb
mkdir -p gdb