Skip to content

Commit ebffc37

Browse files
committed
Initial version
1 parent 0ff1f24 commit ebffc37

File tree

4 files changed

+222
-0
lines changed

4 files changed

+222
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build/

Dockerfile

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
FROM ubuntu:22.04
2+
3+
ARG DEBIAN_FRONTEND=noninteractive
4+
ARG GCC_VERSION=12
5+
6+
#
7+
# Install utils
8+
#
9+
10+
RUN apt-get update -qq && \
11+
apt-get clean && \
12+
apt-get -qq -y upgrade && \
13+
apt-get -y install git \
14+
gpg \
15+
curl \
16+
cmake \
17+
make \
18+
file \
19+
zip \
20+
unzip \
21+
wget \
22+
xxd \
23+
xz-utils \
24+
software-properties-common && \
25+
rm -rf /var/lib/apt/lists/* && \
26+
update-alternatives --install /usr/bin/python python /usr/bin/python3 2
27+
28+
#
29+
# Install cross compilers
30+
#
31+
32+
RUN apt-get update -qq && \
33+
apt-get clean && \
34+
apt-get -y install build-essential \
35+
binutils \
36+
binutils-i686-gnu \
37+
binutils-i686-linux-gnu \
38+
binutils-x86-64-linux-gnu \
39+
binutils-aarch64-linux-gnu \
40+
binutils-arm-linux-gnueabi \
41+
binutils-arm-linux-gnueabihf \
42+
cpp-${GCC_VERSION} \
43+
cpp-${GCC_VERSION}-aarch64-linux-gnu \
44+
cpp-${GCC_VERSION}-arm-linux-gnueabi \
45+
cpp-${GCC_VERSION}-arm-linux-gnueabihf \
46+
cpp-${GCC_VERSION}-i686-linux-gnu \
47+
gcc-${GCC_VERSION} \
48+
gcc-${GCC_VERSION}-aarch64-linux-gnu \
49+
gcc-${GCC_VERSION}-arm-linux-gnueabi \
50+
gcc-${GCC_VERSION}-arm-linux-gnueabihf \
51+
gcc-${GCC_VERSION}-i686-linux-gnu \
52+
gcc-${GCC_VERSION}-multilib \
53+
gcc-${GCC_VERSION}-multilib-i686-linux-gnu \
54+
g++-${GCC_VERSION} \
55+
g++-${GCC_VERSION}-aarch64-linux-gnu \
56+
g++-${GCC_VERSION}-arm-linux-gnueabi \
57+
g++-${GCC_VERSION}-arm-linux-gnueabihf \
58+
g++-${GCC_VERSION}-i686-linux-gnu \
59+
g++-${GCC_VERSION}-multilib \
60+
g++-${GCC_VERSION}-multilib-i686-linux-gnu && \
61+
rm -rf /var/lib/apt/lists/*
62+
63+
#
64+
# Install gdb dependencies
65+
#
66+
67+
RUN apt-get update -qq && \
68+
apt-get clean && \
69+
apt-get -y install texinfo \
70+
libncurses5-dev \
71+
libmpfr-dev \
72+
libgmp-dev \
73+
libexpat1-dev \
74+
libunwind-dev \
75+
libpython3.10-dev \
76+
python3.10-distutils && \
77+
rm -rf /var/lib/apt/lists/*
78+
79+
RUN mkdir -p /gdb/
80+
81+
ADD ./build.sh /gdb/build.sh
82+
83+
#
84+
# Add docker user
85+
#
86+
87+
RUN adduser --disabled-password --gecos "" gdb && \
88+
adduser gdb sudo && \
89+
echo "%sudo ALL=(ALL) NOPASSWD:ALL" >>/etc/sudoers
90+
91+
USER gdb
92+
93+
WORKDIR /gdb/
94+
95+
ENTRYPOINT ["bash", "build.sh"]

build-docker.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
DOCKERFILE_PATH=$(realpath Dockerfile)
6+
DOCKER_IMAGE_NAME="gdb-compiler-image"
7+
DOCKER_CONTAINER_NAME="gdb-compiler-builder"
8+
9+
echo "[+] Building docker image: ${DOCKER_IMAGE_NAME}"
10+
docker build --tag ${DOCKER_IMAGE_NAME} -f "${DOCKERFILE_PATH}" .
11+
12+
echo
13+
echo "[+] Running gdb container: ${DOCKER_CONTAINER_NAME}"
14+
docker run -it --rm -v "$PWD:/gdb" --name ${DOCKER_CONTAINER_NAME} ${DOCKER_IMAGE_NAME}
15+
echo

build.sh

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
PROJECT_DIR=$(dirname "$(realpath -s "$0")")
6+
7+
GCC_VERSION=12
8+
GDB_VERSION=12.1
9+
PYTHON_VERSION=3.10
10+
GDB_ARCHS=("x86_64-linux-gnu")
11+
GDBSERVER_ARCHS=("i686-linux-gnu" "x86_64-linux-gnu" "arm-linux-gnueabi" "aarch64-linux-gnu")
12+
BUILD_PATH="${PROJECT_DIR}/build"
13+
SOURCE_DIR="${BUILD_PATH}/gdb-${GDB_VERSION}"
14+
15+
function buildGDB() {
16+
local isGDBServer="$1"
17+
local eabi="$2"
18+
local buildPath
19+
local prefix
20+
21+
echo ""
22+
23+
if [ "${isGDBServer}" = true ]; then
24+
echo "[+] Building GDB server for abi: ${eabi}"
25+
prefix=gdbserver
26+
else
27+
echo "[+] Building GDB for abi: ${eabi}"
28+
prefix=gdb
29+
fi
30+
31+
local buildPath="${BUILD_PATH}/${prefix}/${eabi}"
32+
33+
if [[ ! -d "${buildPath}" ]]; then
34+
mkdir -p "${buildPath}"
35+
cd "${buildPath}" || exit
36+
37+
if [ "${isGDBServer}" = true ]; then
38+
${SOURCE_DIR}/configure \
39+
--host="${eabi}" \
40+
--disable-gdb \
41+
--disable-docs \
42+
--disable-binutils \
43+
--disable-gas \
44+
--disable-sim \
45+
--disable-gprof \
46+
--disable-inprocess-agent \
47+
--enable-gdbserver \
48+
--prefix="${buildPath}/binaries" \
49+
CC="${eabi}-gcc-${GCC_VERSION}" \
50+
CXX="${eabi}-g++-${GCC_VERSION}" \
51+
LDFLAGS="-static -static-libstdc++"
52+
else
53+
${SOURCE_DIR}/configure \
54+
--host="${eabi}" \
55+
--enable-targets=all \
56+
--with-python=/usr/bin/python${PYTHON_VERSION} \
57+
--disable-docs \
58+
--disable-gdbserver \
59+
--disable-binutils \
60+
--disable-gas \
61+
--disable-sim \
62+
--disable-gprof \
63+
--disable-inprocess-agent \
64+
--prefix="${buildPath}/binaries" \
65+
CC="${eabi}-gcc-${GCC_VERSION}" \
66+
CXX="${eabi}-g++-${GCC_VERSION}"
67+
fi
68+
else
69+
cd "${buildPath}" || exit
70+
fi
71+
72+
echo -e "\t[*] Path: ${buildPath}"
73+
74+
make
75+
make install
76+
77+
find ./* -maxdepth 0 -name "binaries" -prune -o -exec rm -rf {} \;
78+
mv binaries/* .
79+
rm -rf binaries
80+
81+
echo ""
82+
83+
cd "${PROJECT_DIR}" || exit
84+
}
85+
86+
function downloadGDB() {
87+
local url="https://ftp.gnu.org/gnu/gdb/gdb-${GDB_VERSION}.tar.gz"
88+
local sourceDir="$1"
89+
90+
if [[ ! -d "${sourceDir}" ]]; then
91+
mkdir -p "${sourceDir}"
92+
echo "[+] Downloading: ${url} in ${sourceDir}"
93+
wget -qO- "${url}" | tar -xz --strip-components=1 -C "${sourceDir}"
94+
fi
95+
}
96+
97+
mkdir -p "${BUILD_PATH}"
98+
99+
downloadGDB "${SOURCE_DIR}"
100+
101+
#
102+
# Build gdb and gdbserver
103+
#
104+
105+
for ABI in "${GDB_ARCHS[@]}"; do
106+
buildGDB false "${ABI}"
107+
done
108+
109+
for ABI in "${GDBSERVER_ARCHS[@]}"; do
110+
buildGDB true "${ABI}"
111+
done

0 commit comments

Comments
 (0)