Skip to content

Commit fa04d3a

Browse files
guyush1roddyrap
authored andcommitted
gdb with python support integration
This commits enables gdb's python support. In order to make it work, we had to create a python fork with some patches to the buildsystem, and also had to patch gdb as well.
1 parent dc882d9 commit fa04d3a

File tree

6 files changed

+97
-154
lines changed

6 files changed

+97
-154
lines changed

Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ FROM ubuntu:24.04
22

33
# Install dependencies
44
RUN apt update && apt install -y \
5+
bison \
6+
file \
7+
flex \
58
g++ \
69
g++-aarch64-linux-gnu \
710
g++-arm-linux-gnueabi \
@@ -14,10 +17,14 @@ RUN apt update && apt install -y \
1417
gcc-mips-linux-gnu \
1518
gcc-mipsel-linux-gnu \
1619
gcc-powerpc-linux-gnu \
20+
git \
1721
libncurses-dev \
1822
m4 \
1923
make \
2024
patch \
25+
pkg-config \
26+
python3.12 \
27+
libpython3-dev \
2128
texinfo \
2229
wget \
2330
xz-utils

Makefile

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ ARCHS := x86_64 arm aarch64 powerpc mips mipsel
22
TARGETS := $(addprefix build-, $(ARCHS))
33
PACK_TARGETS := $(addprefix pack-, $(ARCHS))
44

5-
.PHONY: clean help download_packages build patch-gdb build-docker-image $(TARGETS) $(PACK_TARGETS)
5+
.PHONY: clean help download_packages build build-docker-image $(TARGETS) $(PACK_TARGETS)
66

77
help:
88
@echo "Usage:"
@@ -32,21 +32,13 @@ build/download-packages.stamp: build/build-docker-image.stamp src/download_packa
3232

3333
download-packages: build/download-packages.stamp
3434

35-
build/patch-gdb.stamp: build/build-docker-image.stamp src/gdb_static.patch build/download-packages.stamp
36-
docker run --user $(shell id -u):$(shell id -g) \
37-
--rm --volume .:/app/gdb gdb-static env TERM=xterm-256color \
38-
/app/gdb/src/patch_gdb.sh /app/gdb/build/packages/gdb /app/gdb/src/gdb_static.patch
39-
touch build/patch-gdb.stamp
40-
41-
patch-gdb: build/patch-gdb.stamp
42-
4335
build: $(TARGETS)
4436

45-
$(TARGETS): build-%: download-packages patch-gdb build-docker-image
37+
$(TARGETS): build-%: download-packages build-docker-image
4638
mkdir -p build
4739
docker run --user $(shell id -u):$(shell id -g) \
4840
--rm --volume .:/app/gdb gdb-static env TERM=xterm-256color \
49-
/app/gdb/src/build.sh $* /app/gdb/build/ /app/gdb/src/gdb_static.patch
41+
/app/gdb/src/build.sh $* /app/gdb/build/ /app/gdb/src
5042

5143
pack: $(PACK_TARGETS)
5244

src/build.sh

Lines changed: 76 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Include utils library
44
script_dir=$(dirname "$0")
5-
. "$script_dir/utils.sh"
5+
source "$script_dir/utils.sh"
66

77
function set_compliation_variables() {
88
# Set compilation variables such as which compiler to use.
@@ -208,6 +208,64 @@ function build_ncurses() {
208208
popd > /dev/null
209209
}
210210

211+
function build_python() {
212+
# Build python.
213+
#
214+
# Parameters:
215+
# $1: python package directory
216+
# $2: target architecture
217+
#
218+
# Echoes:
219+
# The python build directory
220+
#
221+
# Returns:
222+
# 0: success
223+
# 1: failure
224+
local python_dir="$1"
225+
local target_arch="$2"
226+
local python_lib_dir="$(realpath "$python_dir/build-$target_arch")"
227+
228+
echo "$python_lib_dir"
229+
mkdir -p "$python_lib_dir"
230+
231+
# Having a python-config file is an indication that we successfully built python.
232+
if [[ -f "$python_lib_dir/python-config" ]]; then
233+
>&2 echo "Skipping build: libpython already built for $target_arch"
234+
return 0
235+
fi
236+
237+
pushd "$python_lib_dir" > /dev/null
238+
>&2 fancy_title "Building python for $target_arch"
239+
240+
export LINKFORSHARED=" "
241+
export MODULE_BUILDTYPE="static"
242+
export CONFIG_SITE="$python_dir/config.site-static"
243+
>&2 CFLAGS="-static" LDFLAGS="-static" ../configure \
244+
--prefix=$(realpath .) \
245+
--disable-test-modules \
246+
--with-ensurepip=no \
247+
--without-decimal-contextvar \
248+
--build=x86_64-pc-linux-gnu \
249+
--host=$HOST \
250+
--with-build-python=/usr/bin/python3.12 \
251+
--disable-ipv6 \
252+
--disable-shared
253+
254+
>&2 make -j $(nproc)
255+
if [[ $? -ne 0 ]]; then
256+
return 1
257+
fi
258+
259+
# Install python (in build dir using the prefix set above), in order to have a bash (for cross-compilation) python3-config that works.
260+
>&2 make install
261+
if [[ $? -ne 0 ]]; then
262+
return 1
263+
fi
264+
265+
>&2 fancy_title "Finished building python for $target_arch"
266+
popd > /dev/null
267+
}
268+
211269
function build_libmpfr() {
212270
# Build libmpfr.
213271
#
@@ -298,7 +356,8 @@ function build_gdb() {
298356

299357
>&2 fancy_title "Building gdb for $target_arch"
300358

301-
../configure --enable-static --enable-tui --with-static-standard-libraries --disable-inprocess-agent \
359+
../configure -C --enable-static --with-static-standard-libraries --disable-inprocess-agent \
360+
--enable-tui --with-python=/app/gdb/build/packages/cpython-static/build-$target_arch/bin/python3-config \
302361
"--with-libiconv-prefix=$libiconv_prefix" --with-libiconv-type=static \
303362
"--with-gmp=$libgmp_prefix" \
304363
"--with-mpfr=$libmpfr_prefix" \
@@ -395,9 +454,11 @@ function build_gdb_with_dependencies() {
395454
# Parameters:
396455
# $1: target architecture
397456
# $2: build directory
457+
# $3: src directory
398458

399459
local target_arch="$1"
400460
local build_dir="$2"
461+
local source_dir="$3"
401462
local packages_dir="$build_dir/packages"
402463
local artifacts_dir="$build_dir/artifacts"
403464

@@ -427,27 +488,31 @@ function build_gdb_with_dependencies() {
427488
if [[ $? -ne 0 ]]; then
428489
return 1
429490
fi
430-
431491
set_ncurses_link_variables "$ncursesw_build_dir"
432492

433-
build_and_install_gdb "$packages_dir/gdb" \
434-
"$iconv_build_dir/lib/.libs/" \
435-
"$gmp_build_dir/.libs/" \
436-
"$mpfr_build_dir/src/.libs/" \
437-
"$artifacts_dir" \
438-
"$target_arch"
493+
python_build_dir="$(build_python "$packages_dir/cpython-static" "$target_arch")"
494+
if [[ $? -ne 0 ]]; then
495+
return 1
496+
fi
497+
498+
build_and_install_gdb "$packages_dir/binutils-gdb" \
499+
"$iconv_build_dir/lib/.libs/" \
500+
"$gmp_build_dir/.libs/" \
501+
"$mpfr_build_dir/src/.libs/" \
502+
"$artifacts_dir" \
503+
"$target_arch"
439504
if [[ $? -ne 0 ]]; then
440505
return 1
441506
fi
442507
}
443508

444509
function main() {
445510
if [[ $# -ne 3 ]]; then
446-
>&2 echo "Usage: $0 <target_arch> <build_dir>"
511+
>&2 echo "Usage: $0 <target_arch> <build_dir> <src_dir>"
447512
exit 1
448513
fi
449514

450-
build_gdb_with_dependencies "$1" "$2"
515+
build_gdb_with_dependencies "$1" "$2" "$3"
451516
if [[ $? -ne 0 ]]; then
452517
>&2 echo "Error: failed to build gdb with dependencies"
453518
exit 1

src/download_packages.sh

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22

33
# Include utils library
44
script_dir=$(dirname "$0")
5-
. "$script_dir/utils.sh"
5+
source "$script_dir/utils.sh"
66

77
# List of package URLs to download
8-
PACKAGE_URLS=(
8+
SOURCE_URLS=(
99
"https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.17.tar.gz"
1010
"https://ftp.gnu.org/pub/gnu/gmp/gmp-6.3.0.tar.xz"
1111
"https://ftp.gnu.org/pub/gnu/mpfr/mpfr-4.2.1.tar.xz"
12-
"https://ftp.gnu.org/gnu/gdb/gdb-15.2.tar.xz"
1312
"https://ftp.gnu.org/pub/gnu/ncurses/ncurses-6.5.tar.gz"
1413
)
1514

@@ -188,7 +187,7 @@ function download_gdb_packages() {
188187

189188
fancy_title "Starting download of GDB packages"
190189

191-
for url in "${PACKAGE_URLS[@]}"; do
190+
for url in "${SOURCE_URLS[@]}"; do
192191
package_dir=$(package_url_to_dir "$url")
193192
download_and_extract_package "$url" "$package_dir" &
194193
download_pids+=($!)
@@ -202,8 +201,15 @@ function download_gdb_packages() {
202201
fi
203202
done
204203

205-
fancy_title "Finished downloading GDB packages"
204+
if [[ ! -d gdb-static ]]; then
205+
git clone https://github.com/guyush1/binutils-gdb.git --single-branch --branch gdb-static
206+
fi
206207

208+
if [[ ! -d python3.12-static ]]; then
209+
git clone https://github.com/guyush1/cpython-static.git --single-branch --branch python3.12-static
210+
fi
211+
212+
fancy_title "Finished downloading GDB packages"
207213
popd
208214
}
209215

src/gdb_static.patch

Lines changed: 0 additions & 70 deletions
This file was deleted.

src/patch_gdb.sh

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)