Building Cross-GDB in the MinGW VM

This step is optional, so it can be skipped.

You only need to build Cross-GDB if you would like to debug remotely by running a gdb server on the Raspberry Pi hardware and controlling debug session using Eclipse on Windows.


1. Download GDB source files

Download GDB source files from ftp.gnu.org. We will use gdb-7.4.1 in this tutorial.

2. Compile and install libexpat

  • Download source code of libexpat from the official website: https://expat.sourceforge.net/
  • Boot MinGW virtual machine.
  • Import expat-2.1.0.tar.gz into the virtual machine and copy it to C:\MinGW\msys\1.0\opt folder
  • Run MinGW shell and run the following commands:
    cd /opt
    tar zxf expat-2.1.0.tar.gz
    cd expat-2.1.0
    ./configure
    make
    make install
    cd ..
    rm -rf expat-2.1.0
    rm expat-2.1.0.tar.gz
    exit

3. Prepare to build GDB

  • Import gdb-7.4.1.tar.bz2 file into the MinGW virtual machine and copy it to the C:\MinGW\msys\1.0\opt\crosstool\src folder.
  • Run MinGW shell and run the following commands:
    $ cd /opt/crosstool/src
    tar jxf gdb-7.4.1.tar.bz2
  • Create C:\MinGW\msys\1.0\opt\crosstool\src\build-gdb folder.
  • Assign the following contents to the C:\MinGW\msys\1.0\opt\crosstool\src\build_gcc_cross.sh:
    #!/bin/bash
    export TARGET=arm-linux-gnueabihf
    export PREFIX=/opt/crosstool/gcc-4.6.3-eglibc-2.13/$TARGET
    
    cd /opt/crosstool/src/build-gdb
    find . -delete
    cp -R ../gdb-7.4.1/. .
    ./configure --prefix=$PREFIX --target=$TARGET --with-expat --with-libexpat-prefix=/usr/local
    if [ "$?" -ne "0" ]; then
        echo "=== build script: failed to configure cross-gdb-client ==="
        exit 1
    fi
    make
    if [ "$?" -ne "0" ]; then
        echo "=== build script: failed to make cross-gdb-client ==="
        exit 1
    fi
    make install
    if [ "$?" -ne "0" ]; then
        echo "=== build script: failed to install cross-gdb-client ==="
        exit 1
    fi
    
    cd /opt/crosstool/src/build-gdb/gdb/gdbserver
    export CC=$PREFIX/bin/$TARGET-gcc
    export LDFLAGS=-static
    ./configure --host=$TARGET
    if [ "$?" -ne "0" ]; then
        echo "=== build script: failed to configure cross-gdb-server ==="
        exit 1
    fi
    make
    if [ "$?" -ne "0" ]; then
        echo "=== build script: failed to make cross-gdb-server ==="
        exit 1
    fi
    cp ./gdbserver $PREFIX/usr/bin
    cp ./gdbreplay $PREFIX/usr/bin
    cp ./gdbserver.1 $PREFIX/share/man/man1/$TARGET-gdbserver.1
    
    echo "=== build script: OK ==="
    
    
  • Reapply dos2unix to C:\MinGW\msys\1.0\opt\crosstool\src\build_gcc_cross.sh if your text editor does not preserve line endings.

4. Build GDB

  • Run C:\MinGW\msys\1.0\opt\crosstool\src\build_gcc_cross.cmd and wait until it completes.
  • Replace TARGET=arm-linux-gnueabihf with TARGET=arm-linux-gnueabi in build_gcc_cross.sh, reapply dos2unix if you have to, then run & wait for build_gcc_cross.cmd again.
  • If there are no errors, shutdown the MinGW VM and make snapshot "SNAP-F".


>> Read next section or buy already prepared cross-compiler (€10) to save your time.