Building GDB

For Linux and Mac

Prerequisits

Building Python

  • Go to the directory where you have extracted the Python source and run:
    1. unset PYTHONHOME
    2. configure --prefix=<python path>
    3. make
    4. make install

Building Expat

  • Go to the directory where you have extracted the Expat source and run:
    1. configure --prefix=<expat path>
    2. make
    3. make install

Building GDB

  • Targets to build: x86_64-unknown-linux-gnu, i686-unknown-linux-gnu, arm-none-linux-gnueabi, arm-none-symbianelf
  • Note: Make sure to run “make distclean” between configure with different targets.
  • Go to the directory where you have extracted the GDB source and run once:
    1. patch -p2 < pythonhome-<gdb version>.patch
    2. patch -p1 < gdb-<gdb version>-IPv6.patch
  • Then run for each target:
    1. export PYTHONHOME=<python path>
    2. export PATH=<python path>/bin:<expat path>/bin:$PATH
    3. configure --disable-nls --prefix=/usr --target<target>
    4. make
    5. strip gdb/gdb

Shipping

  • Create a directory for the GDB’s from the last step.
  • Copy gdb/gdb from for every target you have build to this directory.
  • Rename gdb to gdb-<target> to differentiate the GDB’s.
  • Copy the directory <pythonpath>/lib to the created directory created in this step.

For Windows

A msys Environment with MinGW is required to build the GDB on Windows.
If this is not installed on the system download and install

Note: You should take a shortcut by downloading the pre-compiled Python 2.7 from the build link in the download section below.
Note: Make sure to extract files with Unix file endings. =configure= will fail spectacularly otherwise

Prerequisits

Building Python

Note: Only follow this part if you cannot use the pre-compiled version of Python for some reason!

  • Download the Python 2.7.1 source tarball [python.org]
  • Apply attached setpythonhome.diff patch (line numbers may need to be adjusted)
  • Build Python with MSVS according to the documentation
    • For the VS2008:
      1. cd PCbuild
      2. pcbuild.sln
    • file =readme.txt= tells what will build
    • For the VS2005,
      1. cd PC\VS8.0
      2. pcbuild.sln
    • But the VS2005 sln file is not guaranteed to be up to date. If you don’t have “pexports.exe” extract it somewhere in your path from the pexports zip file [emmestech.com]
  • From a command line in directory PCBuild or PC\VS8.0:
    1. pexports python27.dll | sed "s/^_\([[:alnum:]_]\+\)@[[:digit:]]\+/\1/" > python27.def
    2. dlltool -k --input-def python27.def --dllname python27.dll --output-lib libpython2.7.a
  • Note: the dot in 2.7 is important!

Building Expat

  • Start a msys shell and go to the directory where you have extracted the Expat source and run:
    1. configure --prefix=<expat path> --enable-static
    2. make
    3. make install

Building libiconv

  • Start a msys shell and go to the directory where you have extracted the libiconv source and run:
    1. configure --prefix=<libiconv path> --enable-static
    2. make
    3. make install

Building GDB

  • Targets to build: arm-none-symbianelf, arm-none-linux-gnueabi, i686-pc-mingw32
  • Note: Make sure to run “make distclean” between configure with different targets.
  • Start a msys shell and go to the directory where you have extracted the GDB source and run once:
    1. patch -p1 < gdb-<gdb version>-IPv6.patch
  • Then run for each target:
    1. configure --target<target> --disable-nls /
    2. --with-libiconv-prefix=<libiconv path> /
    3. --with-expat --with-libexpat-prefix=<expat path> /
    4. --with-python
    5. patch -p1 < gdb-<gdb version>-IPv6.patch
    6. make LDFLAGS="-L<python path>/lib -lpthread -ldl -lutil -lpython27" CFLAGS="-I<python path>/include"

Shipping

  • Create a directory for the GDB’s from the last step.
  • Copy gdb/gdb.exe from for every target you have build to this directory.
  • Rename gdb to gdb-<target> to differentiate the GDB’s.
  • Run depends.exe from DependencyWalker [dependencywalker.com] on each GDB and ship the required DLLs in the same directory.
  • For me, that’s:
    • libexpat-1.dll
    • libiconv-2.dll
    • libpython2.7.dll
  • You need to also ship the lib/ directory from the fake install directory.

Testing

  • To test the GDB’s just run the executable and type:
    1. python print 23
  • When the GDB prints “23” everything works fine.

Profit!

Congrats, if you have made it until here, you now have a Python enabled GDB debugger.

Downloads

Categories: