Tobias Mühlbauer

Remote Debugging, Part 1: Configure GDB on Mac OS X for Linux Applications

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.

  • http://twitter.com/costaskleopa Costas Kleopa

    I believe there was an error in your command line: –target=-x86_64-linux-gnu should be without the dash: –target=x86_64-linux-gnu.

    Did you manage to get gdb compiled successfully? I am getting this error when trying to compile with in Mac OS Lion:

    In file included from archive.c:130:sysdep.h:173:21: error: libintl.h: No such file or directorycc1: warnings being treated as errorsarchive.c: In function ‘_bfd_write_archive_contents’:archive.c:2126: warning: implicit declaration of function ‘dgettext’archive.c:2126: warning: incompatible implicit declaration of built-in function ‘dgettext’archive.c: In function ‘_bfd_archive_bsd_update_armap_timestamp’:archive.c:2414: warning: incompatible implicit declaration of built-in function ‘dgettext’archive.c:2438: warning: incompatible implicit declaration of built-in function ‘dgettext’make[4]: *** [archive.lo] Error 1

    Finally, is Part 2 coming?

    Thanks!

    • http://www.wolf-zone.de/ Wolf Rödiger

      Hi Costas,

      Thanks, I corrected the target parameter. I had no problems compiling gdb in Mac OS X Lion. Did you install gettext? Part 2 is now online.

      Cheers, Wolf

    • Thomas Fanghaenel

      I ran into the same error when trying to compile gdb-7.5.  The problem is that the libtool commands don’t seem to pass along the proper -I switches to the gcc command.  I’ve worked around this by changing gdb-7.5/bfd/Makefile.in, line 325 from:

      CSEARCH = -I. -I$(srcdir) -I$(INCDIR)

      to:

      CSEARCH = -I. -I$(srcdir) -I$(INCDIR) -I$(INCINTL)

      This works for me, and allows me to compile gdb properly without errors.

      • Thomas Fanghaenel

        What I pointed out before doesn’t work, actually.  Something must have kept hanging around in my environment, and polluted the variables.

        A crude, kill-it-with-iron kind of workaround (which does work) is to do:

        export CFLAGS=”-I/opt/local/include”

        Make sure you clean up, and rerun configure…  Not pretty, but it does get the job done