This series of articles describes how to use GDB on Mac OS X to debug C/C++ applications targeted for and running on a remote Linux machine (possibly a virtual machine) equipped with gdbserver. Moreover, I will explain how to configure Eclipse to make debugging a little nicer.
This first part explains how to configure GDB for the Linux target environment when compiled on Mac OS X. This will allow you to remotely debug a Linux executable in the Linux Elf binary format with the debugger running on Mac OS X.
gettext, gmp, and libelf
The easiest way to install gettext, gmp, and libelf is MacPorts which is a package manager for Mac OS X. After installing MacPorts you can install the packages with sudo port install gettext, sudo port install gmp, and sudo port install libelf.
Compile GDB
Next, you need to download the GDB archive from here. The following line configures GDB so that it understands the x86_64 Linux binary format. It also sets the executable name to gdb-x86_64-linux-gnu which avoids possible conflicts with other GDB installations you may have on your system:
./configure --prefix=/opt/local --program-suffix=-linux-x86_64 --target=x86_64-linux-gnu --with-gmp=/opt/local --with-libelf=/opt/local --with-build-libsubdir=/opt/local
Now the time has come for make and make install which should leave you with a GDB binary that allows remote debugging.
Next: Configure Eclipse for Remote Debugging
GDB offers command-line-style remote debugging; so you could stop here. If, however, you prefer a graphical interface for debugging (i.e., Eclipse) you should read the part 2 in this series.