diff --git a/.github/workflows/pr-pipeline.yaml b/.github/workflows/pr-pipeline.yaml
index 6dbc0f8..af83822 100644
--- a/.github/workflows/pr-pipeline.yaml
+++ b/.github/workflows/pr-pipeline.yaml
@@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
- build_type: ["build", "build-with-python"]
+ build_type: ["slim", "full"]
architecture: ["x86_64", "arm", "aarch64", "powerpc", "mips", "mipsel"]
runs-on: ubuntu-latest
@@ -25,4 +25,4 @@ jobs:
run: sudo apt-get install -y wget
- name: Build
- run: make ${{ matrix.build_type }}-${{ matrix.architecture }} -j$((`nproc`+1))
+ run: make build-${{ matrix.architecture }}-${{ matrix.build_type }} -j$((`nproc`+1))
diff --git a/Makefile b/Makefile
index 4efc9e1..e269416 100644
--- a/Makefile
+++ b/Makefile
@@ -1,12 +1,17 @@
ARCHS := x86_64 arm aarch64 powerpc mips mipsel
+GDB_BFD_ARCHS := $(shell echo $(ARCHS) | awk '{for(i=1;i<=NF;i++) $$i=$$i"-linux"; print}' OFS=,)
-TARGETS := $(addprefix build-, $(ARCHS))
-PYTHON_TARGETS := $(addprefix build-with-python-, $(ARCHS))
-ALL_TARGETS := $(TARGETS) $(PYTHON_TARGETS)
+BASE_BUILD_TARGETS := $(addprefix build-, $(ARCHS))
-PACK_TARGETS := $(addprefix pack-, $(ARCHS))
-PYTHON_PACK_TARGETS := $(addprefix pack-with-python-, $(ARCHS))
-ALL_PACK_TARGETS := $(PACK_TARGETS) $(PYTHON_PACK_TARGETS)
+SLIM_BUILD_TARGETS := $(addsuffix -slim, $(BASE_BUILD_TARGETS))
+FULL_BUILD_TARGETS := $(addsuffix -full, $(BASE_BUILD_TARGETS))
+ALL_BUILD_TARGETS := $(SLIM_BUILD_TARGETS) $(FULL_BUILD_TARGETS)
+
+BASE_PACK_TARGETS := $(addprefix pack-, $(ARCHS))
+
+FULL_PACK_TARGETS := $(addsuffix -full, $(BASE_PACK_TARGETS))
+SLIM_PACK_TARGETS := $(addsuffix -slim, $(BASE_PACK_TARGETS))
+ALL_PACK_TARGETS := $(SLIM_PACK_TARGETS) $(FULL_PACK_TARGETS)
SUBMODULE_PACKAGES := $(wildcard src/submodule_packages/*)
BUILD_PACKAGES_DIR := "build/packages"
@@ -15,7 +20,7 @@ BUILD_PACKAGES_DIR := "build/packages"
# This is disabled by the ci automation manually.
TTY_ARG ?= -it
-.PHONY: clean help download_packages build build-docker-image $(ALL_TARGETS) $(ALL_PACK_TARGETS)
+.PHONY: clean help download_packages build build-docker-image $(ALL_BUILD_TARGETS) $(ALL_PACK_TARGETS)
.NOTPARALLEL: build pack
@@ -24,7 +29,7 @@ help:
@echo " make build"
@echo ""
- @for target in $(ALL_TARGETS); do \
+ @for target in $(ALL_BUILD_TARGETS); do \
echo " $$target"; \
done
@@ -53,31 +58,31 @@ symlink-git-packages: build/symlink-git-packages.stamp
download-packages: build/download-packages.stamp
-build: $(ALL_TARGETS)
+build: $(ALL_BUILD_TARGETS)
-$(TARGETS): build-%:
- @$(MAKE) _build-$*
+$(SLIM_BUILD_TARGETS): build-%-slim:
+ @BUILD_TYPE="slim" $(MAKE) _build-$*
-$(PYTHON_TARGETS): build-with-python-%:
- @WITH_PYTHON="--with-python" $(MAKE) _build-$*
+$(FULL_BUILD_TARGETS): build-%-full:
+ @BUILD_TYPE="full" GDB_BFD_ARCHS=$(GDB_BFD_ARCHS) $(MAKE) _build-$*
_build-%: symlink-git-packages download-packages build-docker-image
mkdir -p build
docker run $(TTY_ARG) --user $(shell id -u):$(shell id -g) \
--rm --volume .:/app/gdb gdb-static env TERM=xterm-256color \
- /app/gdb/src/compilation/build.sh $* /app/gdb/build/ /app/gdb/src $(WITH_PYTHON)
+ /app/gdb/src/compilation/build.sh $* /app/gdb/build/ /app/gdb/src $(BUILD_TYPE) $(GDB_BFD_ARCHS)
pack: $(ALL_PACK_TARGETS)
-$(PACK_TARGETS): pack-%:
- @$(MAKE) _pack-$*
+$(SLIM_PACK_TARGETS): pack-%-slim:
+ @BUILD_TYPE="slim" $(MAKE) _pack-$*
-$(PYTHON_PACK_TARGETS): pack-with-python-%:
- @TAR_EXT="with-python-" ARTIFACT_EXT="_with_python" $(MAKE) _pack-$*
+$(FULL_PACK_TARGETS): pack-%-full:
+ @BUILD_TYPE="full" $(MAKE) _pack-$*
-_pack-%: build-%
- if [ ! -f "build/artifacts/gdb-static-$(TAR_EXT)$*.tar.gz" ]; then \
- tar -czf "build/artifacts/gdb-static-$(TAR_EXT)$*.tar.gz" -C "build/artifacts/$*$(ARTIFACT_EXT)" .; \
+_pack-%: build-%-$(BUILD_TYPE)
+ if [ ! -f "build/artifacts/gdb-static-$(BUILD_TYPE)-$*.tar.gz" ]; then \
+ tar -czf "build/artifacts/gdb-static-$(BUILD_TYPE)-$*.tar.gz" -C "build/artifacts/$*_$(BUILD_TYPE)" .; \
fi
clean-git-packages:
diff --git a/README.md b/README.md
index bdd63cd..9490760 100644
--- a/README.md
+++ b/README.md
@@ -60,15 +60,22 @@ This is where `gdb-static` comes in! We provide static builds of `gdb` (and `gdb
## Usage
-To get started with `gdb-static`, simply download the build for your architecture from the [releases page](https://github.com/guyush1/gdb-static/releases/latest), extract the archive, and copy the binary to your desired platform.
-
-> [!NOTE]
-> We provide two types of builds:
-> 1. Builds with Python support, which are approximately ~30 MB in size.
-> 2. Slimmer builds without Python support, which are approximately ~7 MB in size.
+To get started with `gdb-static`, simply download the build for your architecture from the [releases page](https://github.com/guyush1/gdb-static/releases/latest), extract the archive, and copy the binary to your desired platform.
You may choose to copy the `gdb` binary to the platform, or use `gdbserver` to debug remotely.
+## Build types
+
+We provide two types of builds:
+1. Slim builds, that contains most of the features, beside the ones mentioned below.
+2. Full builds that contains all of the slim build features, and also contains:
+ * Python support
+ * Cross-architecture debugging.
+ Note that in order to enable cross-architecture debugging, we have to disable the simulator feature, since not all targets have a simulator.
+
+Slim builds are approximately ~10MB. Full builds are approximately ~70MB.
+You can edit the full_build_conf.sh file to disable full build exclusive features.
+
## Development
> [!NOTE]
@@ -97,10 +104,10 @@ Building for a specific architecture
To build `gdb-static` for a specific architecture, run the following command:
```bash
-make build[-with-python]-
+make build--[slim/full]
```
-Where `` is the architecture you want to build for, and `-with-python` may be added in order to compile gdb with Python support.
+Where `` is the architecture you want to build for, and `slim/full` determines the build type (see [here](#build-types)).
The resulting binary will be placed in the `build/artifacts/` directory:
diff --git a/src/compilation/build.sh b/src/compilation/build.sh
index 1ec932a..4f1a3ec 100755
--- a/src/compilation/build.sh
+++ b/src/compilation/build.sh
@@ -3,6 +3,7 @@
# Include utils library
script_dir=$(dirname "$0")
source "$script_dir/utils.sh"
+source "$script_dir/full_build_conf.sh"
# Don't want random unknown things to fail in the build procecss!
set -e
@@ -50,14 +51,34 @@ function set_compliation_variables() {
export CC="${CROSS}gcc"
export CXX="${CROSS}g++"
- export CFLAGS="-O2"
- export CXXFLAGS="-O2"
+ export CFLAGS="-Os"
+ export CXXFLAGS="-Os"
# Strip the binary to reduce it's size.
export LDFLAGS="-s"
}
-function set_up_lib_search_paths() {
+function set_up_lib_search_path() {
+ # Set up library-related linker search paths.
+ #
+ # Parameters:
+ # $1: library install dir
+ # $2: whether to add linker search path or not (include path is always added).
+ local lib_install_dir="$1"
+ local add_linker_include_path="$2"
+
+ if [[ $add_linker_include_path == 1 ]]; then
+ # Add library to the linker's include path.
+ export LDFLAGS="-L$lib_install_dir/lib $LDFLAGS"
+ fi
+
+ # Add library standard headers to the CC / CXX flags.
+ local include_paths="-I$lib_install_dir/include"
+ export CC="$CC $include_paths"
+ export CXX="$CXX $include_paths"
+}
+
+function set_up_base_lib_search_paths() {
# Set up library-related linker search paths.
#
# Parameters:
@@ -65,21 +86,18 @@ function set_up_lib_search_paths() {
# $2: gmp build dir
# $3: mpfr build dir
# $4: ncursesw build dir
- # $5: libexpat build dir
+ # $5: expat build dir
local iconv_build_dir="$1"
local gmp_build_dir="$2"
local mpfr_build_dir="$3"
local ncursesw_build_dir="$4"
- local libexpat_build_dir="$5"
+ local expat_build_dir="$5"
- # I) Allow tui mode by adding our custom built static ncursesw library to the linker search path.
- # II) Allow parsing xml files by adding libexpat library to the linker search path.
- export LDFLAGS="-L$ncursesw_build_dir/lib -L$libexpat_build_dir/lib/ $LDFLAGS"
-
- # Add library standard headers to the CC / CXX flags.
- export INCLUDE_PATHS="-I$iconv_build_dir/include -I$gmp_build_dir/include -I$mpfr_build_dir/include -I$ncursesw_build_dir/include -I$libexpat_build_dir/include"
- export CC="$CC $INCLUDE_PATHS"
- export CXX="$CXX $INCLUDE_PATHS"
+ set_up_lib_search_path $iconv_build_dir 0
+ set_up_lib_search_path $gmp_build_dir 0
+ set_up_lib_search_path $mpfr_build_dir 0
+ set_up_lib_search_path $ncursesw_build_dir 1
+ set_up_lib_search_path $expat_build_dir 1
}
function build_iconv() {
@@ -489,10 +507,11 @@ function build_gdb() {
# $1: gdb directory
# $2: target architecture
# $3: libiconv prefix
- # $4: liblzma prefix
- # $5: libgmp prefix
- # $6: libmpfr prefix
- # $7: whether to build with python or not
+ # $4: libgmp prefix
+ # $5: libmpfr prefix
+ # $6: liblzma prefix
+ # $7: build mode: slim / full.
+ # $8: gdb cross-architecture binary format support formats (relevant for full builds only).
#
# Echoes:
# The gdb build directory
@@ -504,17 +523,28 @@ function build_gdb() {
local gdb_dir="$1"
local target_arch="$2"
local libiconv_prefix="$3"
- local liblzma_prefix="$4"
- local libgmp_prefix="$5"
- local libmpfr_prefix="$6"
- local with_python="$7"
-
- if [[ "$with_python" == "yes" ]]; then
- local python_flag="--with-python=/app/gdb/build/packages/cpython-static/build-$target_arch/bin/python3-config"
- local gdb_build_dir="$(realpath "$gdb_dir/build-${target_arch}_with_python")"
+ local libgmp_prefix="$4"
+ local libmpfr_prefix="$5"
+ local liblzma_prefix="$6"
+ local full_build="$7"
+ local gdb_bfd_archs="$8"
+
+ local extra_flags=()
+ if [[ "$full_build" == "yes" ]]; then
+ if [[ $full_build_cross_arch_debugging -eq 1 ]]; then
+ extra_flags+=("--enable-targets=$gdb_bfd_archs" "--enable-64-bit-bfd" "--disable-sim")
+ fi
+
+ if [[ $full_build_python_support -eq 1 ]]; then
+ extra_flags+=("--with-python=/app/gdb/build/packages/cpython-static/build-$target_arch/bin/python3-config")
+ else
+ extra_flags+=("--without-python")
+ fi
+
+ local gdb_build_dir="$(realpath "$gdb_dir/build-${target_arch}-full")"
else
- local python_flag="--without-python"
- local gdb_build_dir="$(realpath "$gdb_dir/build-${target_arch}")"
+ extra_flags+=("--without-python")
+ local gdb_build_dir="$(realpath "$gdb_dir/build-${target_arch}-slim")"
fi
echo "$gdb_build_dir"
@@ -530,16 +560,16 @@ function build_gdb() {
>&2 fancy_title "Building gdb for $target_arch"
../configure --enable-static --with-static-standard-libraries --disable-inprocess-agent \
- --enable-targets=all --enable-64-bit-bfd \
- --enable-tui "$python_flag" \
- --with-expat --with-libexpat-type="static" \
--with-gdb-datadir="/usr/share/gdb" --with-separate-debug-dir="/usr/lib/debug" \
--with-system-gdbinit="/etc/gdb/gdbinit" --with-system-gdbinit-dir="/etc/gdb/gdbinit.d" \
--with-jit-reader-dir="/usr/lib/gdb" \
- "--with-libiconv-prefix=$libiconv_prefix" --with-libiconv-type=static \
- "--with-liblzma-prefix=$liblzma_prefix" --with-liblzma-type=static --with-lzma=yes \
- "--with-gmp=$libgmp_prefix" \
- "--with-mpfr=$libmpfr_prefix" \
+ --with-libiconv-prefix="$libiconv_prefix" --with-libiconv-type=static \
+ --with-gmp="$libgmp_prefix" \
+ --with-mpfr="$libmpfr_prefix" \
+ --enable-tui \
+ --with-expat --with-libexpat-type=static \
+ --with-lzma=yes --with-liblzma-prefix="$liblzma_prefix" --with-liblzma-type="static" \
+ "${extra_flags[@]}" \
"CC=$CC" "CXX=$CXX" "LDFLAGS=$LDFLAGS" "--host=$HOST" \
"CFLAGS=$CFLAGS" "CXXFLAGS=$CXXFLAGS" 1>&2
if [[ $? -ne 0 ]]; then
@@ -563,7 +593,7 @@ function install_gdb() {
# $1: gdb build directory
# $2: artifacts directory
# $3: target architecture
- # $4: whether gdb was built with or without python
+ # $4: build mode: slim / full.
#
# Returns:
# 0: success
@@ -572,12 +602,12 @@ function install_gdb() {
local gdb_build_dir="$1"
local artifacts_dir="$2"
local target_arch="$3"
- local with_python="$4"
+ local full_build="$4"
- if [[ "$with_python" == "yes" ]]; then
- local artifacts_location="$artifacts_dir/${target_arch}_with_python"
+ if [[ "$full_build" == "yes" ]]; then
+ local artifacts_location="$artifacts_dir/${target_arch}_full"
else
- local artifacts_location="$artifacts_dir/${target_arch}"
+ local artifacts_location="$artifacts_dir/${target_arch}_slim"
fi
if [[ -d "$artifacts_location" && -n "$(ls -A "$artifacts_location")" ]]; then
@@ -608,12 +638,13 @@ function build_and_install_gdb() {
# Parameters:
# $1: gdb package directory
# $2: libiconv prefix
- # $3: liblzma prefix
- # $4: libgmp prefix
- # $5: libmpfr prefix
- # $6: whether to build with python or not
- # $7: install directory
- # $8: target architecture
+ # $3: libgmp prefix
+ # $4: libmpfr prefix
+ # $5: liblzma prefix.
+ # $6: build mode: slim / full.
+ # $7: gdb cross-architecture binary format support formats (relevant for full builds only).
+ # $8: install directory
+ # $9: target architecture
#
# Returns:
# 0: success
@@ -621,19 +652,20 @@ function build_and_install_gdb() {
local gdb_dir="$1"
local libiconv_prefix="$2"
- local liblzma_prefix="$3"
- local libgmp_prefix="$4"
- local libmpfr_prefix="$5"
- local with_python="$6"
- local artifacts_dir="$7"
- local target_arch="$8"
+ local libgmp_prefix="$3"
+ local libmpfr_prefix="$4"
+ local liblzma_prefix="$5"
+ local full_build="$6"
+ local gdb_bfd_archs="$7"
+ local artifacts_dir="$8"
+ local target_arch="$9"
- gdb_build_dir="$(build_gdb "$gdb_dir" "$target_arch" "$libiconv_prefix" "$liblzma_prefix" "$libgmp_prefix" "$libmpfr_prefix" "$with_python")"
+ gdb_build_dir="$(build_gdb "$gdb_dir" "$target_arch" "$libiconv_prefix" "$libgmp_prefix" "$libmpfr_prefix" "$liblzma_prefix" "$full_build" "$gdb_bfd_archs")"
if [[ $? -ne 0 ]]; then
return 1
fi
- install_gdb "$gdb_build_dir" "$artifacts_dir" "$target_arch" "$with_python"
+ install_gdb "$gdb_build_dir" "$artifacts_dir" "$target_arch" "$full_build"
if [[ $? -ne 0 ]]; then
return 1
fi
@@ -646,12 +678,14 @@ function build_gdb_with_dependencies() {
# $1: target architecture
# $2: build directory
# $3: src directory
- # $4: whether to build gdb with python or not
+ # $4: build mode: slim / full.
+ # $5: gdb cross-architecture binary format support formats (relevant for full builds only).
local target_arch="$1"
local build_dir="$2"
local source_dir="$3"
- local with_python="$4"
+ local full_build="$4"
+ local gdb_bfd_archs="$5"
local packages_dir="$build_dir/packages"
local artifacts_dir="$build_dir/artifacts"
@@ -667,11 +701,6 @@ function build_gdb_with_dependencies() {
return 1
fi
- lzma_build_dir="$(build_lzma "$packages_dir/xz" "$target_arch")"
- if [[ $? -ne 0 ]]; then
- return 1
- fi
-
gmp_build_dir="$(build_libgmp "$packages_dir/gmp" "$target_arch")"
if [[ $? -ne 0 ]]; then
return 1
@@ -692,13 +721,19 @@ function build_gdb_with_dependencies() {
return 1
fi
- set_up_lib_search_paths "$iconv_build_dir" \
- "$gmp_build_dir" \
- "$mpfr_build_dir" \
- "$ncursesw_build_dir" \
- "$libexpat_build_dir"
+ lzma_build_dir="$(build_lzma "$packages_dir/xz" "$target_arch")"
+ if [[ $? -ne 0 ]]; then
+ return 1
+ fi
+
+ set_up_base_lib_search_paths "$iconv_build_dir" \
+ "$gmp_build_dir" \
+ "$mpfr_build_dir" \
+ "$ncursesw_build_dir" \
+ "$libexpat_build_dir"
- if [[ "$with_python" == "yes" ]]; then
+ # Optional build components
+ if [[ $full_build == "yes" && $full_build_python_support -eq 1 ]]; then
local gdb_python_dir="$packages_dir/binutils-gdb/gdb/python/lib/"
local pygments_source_dir="$packages_dir/pygments/"
local python_build_dir="$(build_python "$packages_dir/cpython-static" "$target_arch" "$gdb_python_dir" "$pygments_source_dir")"
@@ -709,10 +744,11 @@ function build_gdb_with_dependencies() {
build_and_install_gdb "$packages_dir/binutils-gdb" \
"$iconv_build_dir" \
- "$lzma_build_dir" \
"$gmp_build_dir" \
"$mpfr_build_dir" \
- "$with_python" \
+ "$lzma_build_dir" \
+ "$full_build" \
+ "$gdb_bfd_archs" \
"$artifacts_dir" \
"$target_arch"
if [[ $? -ne 0 ]]; then
@@ -721,17 +757,19 @@ function build_gdb_with_dependencies() {
}
function main() {
- if [[ $# -lt 3 ]]; then
- >&2 echo "Usage: $0 [--with-python]"
+ if [[ $# -lt 4 ]]; then
+ >&2 echo "Usage: $0 [gdb-bfd-archs]"
exit 1
fi
- local with_python="no"
- if [[ "$4" == "--with-python" ]]; then
- with_python="yes"
+ local full_build="no"
+ if [[ "$4" == "full" ]]; then
+ full_build="yes"
+ else
+ full_build="no"
fi
- build_gdb_with_dependencies "$1" "$2" "$3" "$with_python"
+ build_gdb_with_dependencies "$1" "$2" "$3" "$full_build" "$5"
if [[ $? -ne 0 ]]; then
>&2 echo "Error: failed to build gdb with dependencies"
exit 1
diff --git a/src/compilation/full_build_conf.sh b/src/compilation/full_build_conf.sh
new file mode 100644
index 0000000..462c0bd
--- /dev/null
+++ b/src/compilation/full_build_conf.sh
@@ -0,0 +1,8 @@
+#!/usr/bin/env bash
+
+# This file contains the build configuration for a full build.
+# In order to disable a component, simply change the it to 0.
+# This allows us to fully control the binary extensions.
+
+full_build_cross_arch_debugging=1
+full_build_python_support=1