-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0ff1f24
commit ebffc37
Showing
4 changed files
with
222 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
FROM ubuntu:22.04 | ||
|
||
ARG DEBIAN_FRONTEND=noninteractive | ||
ARG GCC_VERSION=12 | ||
|
||
# | ||
# Install utils | ||
# | ||
|
||
RUN apt-get update -qq && \ | ||
apt-get clean && \ | ||
apt-get -qq -y upgrade && \ | ||
apt-get -y install git \ | ||
gpg \ | ||
curl \ | ||
cmake \ | ||
make \ | ||
file \ | ||
zip \ | ||
unzip \ | ||
wget \ | ||
xxd \ | ||
xz-utils \ | ||
software-properties-common && \ | ||
rm -rf /var/lib/apt/lists/* && \ | ||
update-alternatives --install /usr/bin/python python /usr/bin/python3 2 | ||
|
||
# | ||
# Install cross compilers | ||
# | ||
|
||
RUN apt-get update -qq && \ | ||
apt-get clean && \ | ||
apt-get -y install build-essential \ | ||
binutils \ | ||
binutils-i686-gnu \ | ||
binutils-i686-linux-gnu \ | ||
binutils-x86-64-linux-gnu \ | ||
binutils-aarch64-linux-gnu \ | ||
binutils-arm-linux-gnueabi \ | ||
binutils-arm-linux-gnueabihf \ | ||
cpp-${GCC_VERSION} \ | ||
cpp-${GCC_VERSION}-aarch64-linux-gnu \ | ||
cpp-${GCC_VERSION}-arm-linux-gnueabi \ | ||
cpp-${GCC_VERSION}-arm-linux-gnueabihf \ | ||
cpp-${GCC_VERSION}-i686-linux-gnu \ | ||
gcc-${GCC_VERSION} \ | ||
gcc-${GCC_VERSION}-aarch64-linux-gnu \ | ||
gcc-${GCC_VERSION}-arm-linux-gnueabi \ | ||
gcc-${GCC_VERSION}-arm-linux-gnueabihf \ | ||
gcc-${GCC_VERSION}-i686-linux-gnu \ | ||
gcc-${GCC_VERSION}-multilib \ | ||
gcc-${GCC_VERSION}-multilib-i686-linux-gnu \ | ||
g++-${GCC_VERSION} \ | ||
g++-${GCC_VERSION}-aarch64-linux-gnu \ | ||
g++-${GCC_VERSION}-arm-linux-gnueabi \ | ||
g++-${GCC_VERSION}-arm-linux-gnueabihf \ | ||
g++-${GCC_VERSION}-i686-linux-gnu \ | ||
g++-${GCC_VERSION}-multilib \ | ||
g++-${GCC_VERSION}-multilib-i686-linux-gnu && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
# | ||
# Install gdb dependencies | ||
# | ||
|
||
RUN apt-get update -qq && \ | ||
apt-get clean && \ | ||
apt-get -y install texinfo \ | ||
libncurses5-dev \ | ||
libmpfr-dev \ | ||
libgmp-dev \ | ||
libexpat1-dev \ | ||
libunwind-dev \ | ||
libpython3.10-dev \ | ||
python3.10-distutils && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
RUN mkdir -p /gdb/ | ||
|
||
ADD ./build.sh /gdb/build.sh | ||
|
||
# | ||
# Add docker user | ||
# | ||
|
||
RUN adduser --disabled-password --gecos "" gdb && \ | ||
adduser gdb sudo && \ | ||
echo "%sudo ALL=(ALL) NOPASSWD:ALL" >>/etc/sudoers | ||
|
||
USER gdb | ||
|
||
WORKDIR /gdb/ | ||
|
||
ENTRYPOINT ["bash", "build.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
DOCKERFILE_PATH=$(realpath Dockerfile) | ||
DOCKER_IMAGE_NAME="gdb-compiler-image" | ||
DOCKER_CONTAINER_NAME="gdb-compiler-builder" | ||
|
||
echo "[+] Building docker image: ${DOCKER_IMAGE_NAME}" | ||
docker build --tag ${DOCKER_IMAGE_NAME} -f "${DOCKERFILE_PATH}" . | ||
|
||
echo | ||
echo "[+] Running gdb container: ${DOCKER_CONTAINER_NAME}" | ||
docker run -it --rm -v "$PWD:/gdb" --name ${DOCKER_CONTAINER_NAME} ${DOCKER_IMAGE_NAME} | ||
echo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
PROJECT_DIR=$(dirname "$(realpath -s "$0")") | ||
|
||
GCC_VERSION=12 | ||
GDB_VERSION=12.1 | ||
PYTHON_VERSION=3.10 | ||
GDB_ARCHS=("x86_64-linux-gnu") | ||
GDBSERVER_ARCHS=("i686-linux-gnu" "x86_64-linux-gnu" "arm-linux-gnueabi" "aarch64-linux-gnu") | ||
BUILD_PATH="${PROJECT_DIR}/build" | ||
SOURCE_DIR="${BUILD_PATH}/gdb-${GDB_VERSION}" | ||
|
||
function buildGDB() { | ||
local isGDBServer="$1" | ||
local eabi="$2" | ||
local buildPath | ||
local prefix | ||
|
||
echo "" | ||
|
||
if [ "${isGDBServer}" = true ]; then | ||
echo "[+] Building GDB server for abi: ${eabi}" | ||
prefix=gdbserver | ||
else | ||
echo "[+] Building GDB for abi: ${eabi}" | ||
prefix=gdb | ||
fi | ||
|
||
local buildPath="${BUILD_PATH}/${prefix}/${eabi}" | ||
|
||
if [[ ! -d "${buildPath}" ]]; then | ||
mkdir -p "${buildPath}" | ||
cd "${buildPath}" || exit | ||
|
||
if [ "${isGDBServer}" = true ]; then | ||
${SOURCE_DIR}/configure \ | ||
--host="${eabi}" \ | ||
--disable-gdb \ | ||
--disable-docs \ | ||
--disable-binutils \ | ||
--disable-gas \ | ||
--disable-sim \ | ||
--disable-gprof \ | ||
--disable-inprocess-agent \ | ||
--enable-gdbserver \ | ||
--prefix="${buildPath}/binaries" \ | ||
CC="${eabi}-gcc-${GCC_VERSION}" \ | ||
CXX="${eabi}-g++-${GCC_VERSION}" \ | ||
LDFLAGS="-static -static-libstdc++" | ||
else | ||
${SOURCE_DIR}/configure \ | ||
--host="${eabi}" \ | ||
--enable-targets=all \ | ||
--with-python=/usr/bin/python${PYTHON_VERSION} \ | ||
--disable-docs \ | ||
--disable-gdbserver \ | ||
--disable-binutils \ | ||
--disable-gas \ | ||
--disable-sim \ | ||
--disable-gprof \ | ||
--disable-inprocess-agent \ | ||
--prefix="${buildPath}/binaries" \ | ||
CC="${eabi}-gcc-${GCC_VERSION}" \ | ||
CXX="${eabi}-g++-${GCC_VERSION}" | ||
fi | ||
else | ||
cd "${buildPath}" || exit | ||
fi | ||
|
||
echo -e "\t[*] Path: ${buildPath}" | ||
|
||
make | ||
make install | ||
|
||
find ./* -maxdepth 0 -name "binaries" -prune -o -exec rm -rf {} \; | ||
mv binaries/* . | ||
rm -rf binaries | ||
|
||
echo "" | ||
|
||
cd "${PROJECT_DIR}" || exit | ||
} | ||
|
||
function downloadGDB() { | ||
local url="https://ftp.gnu.org/gnu/gdb/gdb-${GDB_VERSION}.tar.gz" | ||
local sourceDir="$1" | ||
|
||
if [[ ! -d "${sourceDir}" ]]; then | ||
mkdir -p "${sourceDir}" | ||
echo "[+] Downloading: ${url} in ${sourceDir}" | ||
wget -qO- "${url}" | tar -xz --strip-components=1 -C "${sourceDir}" | ||
fi | ||
} | ||
|
||
mkdir -p "${BUILD_PATH}" | ||
|
||
downloadGDB "${SOURCE_DIR}" | ||
|
||
# | ||
# Build gdb and gdbserver | ||
# | ||
|
||
for ABI in "${GDB_ARCHS[@]}"; do | ||
buildGDB false "${ABI}" | ||
done | ||
|
||
for ABI in "${GDBSERVER_ARCHS[@]}"; do | ||
buildGDB true "${ABI}" | ||
done |