How to Cross Compile GNU Project Debugger a Step by Step Guide

Introduction

This tutorial will show how to cross compile the GNU Project Debugger project on an GNU Linux embedded platform.

Overview of the project

GDB, the GNU Project debugger, allows you to see what is going on `inside' another program while it executes -- or what another program was doing at the moment it crashed.

GDB can do four main kinds of things (plus other things in support of these) to help you catch bugs in the act:

  • Start your program, specifying anything that might affect its behavior.
  • Make your program stop on specified conditions.
  • Examine what has happened, when your program has stopped.
  • Change things in your program, so you can experiment with correcting the effects of one bug and go on to learn about another.

The program being debugged can be written in Ada, C, C++, Objective-C, Pascal (and many other languages). Those programs might be executing on the same machine as GDB (native) or on another machine (remote). GDB can run on most popular UNIX and Microsoft Windows variants.

Download

You can download the GNU Project Debugger from: http://sourceware.org/gdb/download

The latest available release by the time of writing of this tutorial is 6.7.1 (October 29th 2007)To download it, please type the following command:

wget http://ftp.gnu.org/gnu/gdb/gdb-6.7.1.tar.gz

Environment Setup

The host machine will be a PC with a GNU Linux distribution installed.
The embedded platform might be constructed on top of one of the following architectures:

  • arm.
  • mips.
  • mipsel.
  • ppc.
  • sparc.

Prerequisites

To cross compile the GNU Project Debugger, you need either a cross compiler, or an emulated Linux running on top of a virtualization software such as QEMU, matching your specific targeted platform.

In order to build yourself such a cross compiler, at crosstool page we introduced the way to build a C,C++ 4.1 GNU compiler for an ARM platform.

Also, hackers will be interested finding all the details to setup an ARM Debian system on their traditional Ubuntun distro following the indications quoted in this other arm-debian-on-ubuntu.

Concerning the dependencies requested by the GNU Project Debugger, we assume that the following software also installed:

  • Termcap 1.3.1 under /opt/external_packages/termcap/1.3.1/compiled/xxx-yyy-linux-gnu

The Cross compilation process

Option 1: Using a cross compiler

Assumptions
During the process, we will assume the cross toolchain is called xxx-yyy-linux-gnu, meaning that the gcc, g++, ar, ..., ld utilities are prefixed by xxx-yyy-linux-gnu. For example, for this toolchain the C compiler is called xxx-yyy-linux-gnu-gcc.

We will also assume that the bin, include, lib and libexec folders of the cross toolchain are accessible through the PATH variable environment in order to work with the compilers from any place in the file system.

Finally, we suppose it is intalled in the following folder: /opt/crosstool/gcc-4.1.2-glibc-2.3.2/xxx-yyy-linux-gnu.

Organization

As mentioned above:

  • The release being cross compiled is: 6.7.1
  • The tar.gz file will then be extracted under: /opt/external_packages/gdb/6.7.1/source
  • The results of the compilation will be stored under: /opt/external_packages/gdb/6.7.1/compiled/xxx-yyy-linux-gnu

The files resulting from the cross compilation are listed here (the share directory is voluntary not appearing):

.:
total 20
drwxr-xr-x 2 root root 4096 2008-03-04 15:44 bin
drwxr-xr-x 2 root root 4096 2008-03-04 15:43 include
drwxr-xr-x 2 root root 4096 2008-03-04 15:44 info
drwxr-xr-x 2 root root 4096 2008-03-04 15:44 lib
drwxr-xr-x 3 root root 4096 2008-03-04 15:44 man
drwxr-xr-x 3 root root 4096 2008-03-04 15:44 share

./bin:
total 13400
-rwxr-xr-x 1 root root 10797550 2008-03-04 15:44 gdb
-rwxr-xr-x 1 root root   190306 2008-03-04 15:44 gdbserver
-rwxr-xr-x 1 root root  2702920 2008-03-04 15:44 run

./include:
total 252
-rw-r--r-- 1 root root  13139 2008-03-04 15:43 ansidecl.h
-rw-r--r-- 1 root root 181292 2008-03-04 15:43 bfd.h
-rw-r--r-- 1 root root  29372 2008-03-04 15:43 bfdlink.h
-rw-r--r-- 1 root root  15888 2008-03-04 15:43 dis-asm.h
-rw-r--r-- 1 root root   1902 2008-03-04 15:43 symcat.h

./info:
total 2476
-rw-r--r-- 1 root root  44804 2008-03-04 15:44 annotate.info
-rw-r--r-- 1 root root 452986 2008-03-04 15:43 bfd.info
-rw-r--r-- 1 root root 116422 2008-03-04 15:43 configure.info
-rw-r--r-- 1 root root  12231 2008-03-04 15:44 gdb.info
-rw-r--r-- 1 root root 300312 2008-03-04 15:44 gdb.info-1
-rw-r--r-- 1 root root 301111 2008-03-04 15:44 gdb.info-2
-rw-r--r-- 1 root root 296956 2008-03-04 15:44 gdb.info-3
-rw-r--r-- 1 root root 220849 2008-03-04 15:44 gdb.info-4
-rw-r--r-- 1 root root   3025 2008-03-04 15:44 gdbint.info
-rw-r--r-- 1 root root 287026 2008-03-04 15:44 gdbint.info-1
-rw-r--r-- 1 root root  41441 2008-03-04 15:44 gdbint.info-2
-rw-r--r-- 1 root root 180387 2008-03-04 15:44 stabs.info
-rw-r--r-- 1 root root 215726 2008-03-04 15:43 standards.info

./lib:
total 6152
-rw-r--r-- 1 root root  828328 2008-03-04 15:44 libarm-unknown-linux-gnu-sim.a
-rw-r--r-- 1 root root 4310810 2008-03-04 15:43 libbfd.a
-rwxr-xr-x 1 root root     921 2008-03-04 15:43 libbfd.la
-rw-r--r-- 1 root root  664964 2008-03-04 15:43 libiberty.a
-rw-r--r-- 1 root root  450594 2008-03-04 15:43 libopcodes.a
-rwxr-xr-x 1 root root     933 2008-03-04 15:43 libopcodes.la

./man:
total 4
drwxr-xr-x 2 root root 4096 2008-03-04 15:44 man1

./man/man1:
total 44
-rw-r--r-- 1 root root  8345 2008-03-04 15:44 gdb.1
-rw-r--r-- 1 root root  4570 2008-03-04 15:44 gdbserver.1
-rw-r--r-- 1 root root 22121 2008-03-04 15:44 run.1

Cross Compiling

Step 1

Install the GNU Project Debugger software by untaring it in /opt/external_packages/gdb/6.7.1/source folder and then cd to this directory.

Note:
All the directories and files listed below must be moved from the gdb-6.7.1 folder
to its parent folder (/opt/external_packages/gdb/6.7.1/source).

Directories and files:

  bfd
  COPYING
  install-sh
  Makefile.def
  readline
  config
  COPYING3
  intl
  Makefile.in
  README
  config.guess
  COPYING3.LIB
  libiberty
  Makefile.tpl
  sim
  config-ml.in
  COPYING.LIB
  libtool.m4
  md5.sum
  src-release
  config.rpath
  djunpack.bat
  ltmain.sh
  missing
  symlink-tree
  config.sub
  etc
  ltoptions.m4
  mkinstalldirs
  texinfo
  configure
  gdb
  ltsugar.m4
  move-if-change
  ylwrap
  configure.ac
  include
  ltversion.m4
  opcodes
Step 2

We want to cross compile the GNU Project Debugger with the default options, but one of the major issues of the configure process is the termcap library which is not found in the right place.

Our solution is to cross compile the termcap library as indicated in this section termcap 1.3.1, and once finished to execute the configure command this way:

env CPPFLAGS="-I/opt/external_packages/termcap/1.3.1/compiled/xxx-yyy-linux-gnu/include" LDFLAGS="-L/opt/external_packages/termcap/1.3.1/compiled/xxx-yyy-linux-gnu/lib" ./configure --host=xxx-yyy-linux-gnu --prefix=/opt/external_packages/gdb/6.7.1/compiled/xxx-yyy-linux-gnu

Then the Makefile should be created.

Step 3

To compile and install the GNU Project Debugger, type successively make and make install.
You should find the directories and files listed above under /opt/external_packages/gdb/6.7.1/compiled/xxx-yyy-linux-gnu.

Option 2: Using QEMU

This section is not yet available.

Download

  • arm-gdb-6.7.1-tar.gz

You may consult this section if you want to download the GNU Project Debugger already cross compiled for your target platform if it is available. You can also contribute to expand the crosscompile.org community by uploading your own results in the case a given platform is not already supported.

Supported platforms

arm-unknown-linux-gnu


Written by David Sayada.

Edit History Last Modified March 10, 2008