GDB Help Page for Beginners

This page contains some basic information for getting started with GDB development and GDB testing using DejaGNU testing framework.

Getting Your Environment Ready

The following command will install all packages that may be needed to build fresh gdb from sources:

  • sudo apt-get install git gcc make texinfo libncurses5-dev libexpat1-dev flex bison dejagnu

Obtaining GDB Sources

Linaro GDB changes are developed using the upstream GDB repository, which has a git mirror:

  • git clone git://sourceware.org/git/binutils-gdb.git

Building GDB

  • <gdb-source-directory>/configure --with-expat --disable-nls --disable-sim --disable-install-libbfd
    make -j`getconf _NPROCESSORS_ONLN`

Other Configure Options

--prefix=DIR

  • Configures the source to install programs and files under directory `DIR'.

--exec-prefix=DIR

  • Configures the source to install programs under directory `DIR'.

--target=TARGET

  • Configure GDB for cross-debugging programs running on the specified TARGET. Without this option, GDB is configured to debug programs that run on the same machine (HOST) as GDB itself. There is no convenient way to generate a list of all available targets.

HOST ...

  • Configure GDB to run on the specified HOST. There is no convenient way to generate a list of all available hosts.

--with-sysroot=DIR

  • Configures GDB to use header files and libraries from the specified sysroot directory `DIR' while building library code which runs on the specified target.

Running GDB Testsuite

  • make -j2 -k check

Testing gdbserver in a remote cross-target configuration

To run gdbserver on a remote machine with a different architecture, first you might need a cross-compiler properly configured in your local machine. Also, you need to build gdb and gdbserver for the specific target architecture. In this case, the GDB you're using for tests should be build with the option "--with-sysroot=/path/to/sysroot" pointing to the sysroot directory where the cross-target libraries are located or "--with-sysroot=remote:" (don't forget the colon at the end) if the libraries can be retrieved from the target machine.

Remember to check if gdb was built with expat support (--with-expat option, enabled by default), otherwise it will not be able to communicate properly with gdbserver. Moreover, you might need also dejagnu version 1.5 (or newer), since GDB testsuite cannot run due to a bug existing on dejagnu's previous versions.

The remaining steps follow a similar setup from when you are testing gdbserver locally:

Create an empty file named site.exp.

touch ${my_dejagnu_dir}/site.exp

Create a directory named boards in the same location as site.exp.

mkdir ${my_dejagnu_dir}/boards

Set the DEJAGNU environment variable to point to the empty site.exp.

export DEJAGNU=${my_dejagnu_dir}/site.exp

Create a file named remote-gdbserver.exp in the boards directory. Fill in remote-gdbserver.exp with contents similar to given below. Make appropriate changes according to your target and host configuration.

# gdbserver running remotely over ssh

load_generic_config "gdbserver"

process_multilib_options ""

# The default compiler for this target.
#set_board_info compiler  "[find_gcc]"
# If gdbserver runs in a cross-target arch, the testsuite should use a cross-compiler
set_board_info compiler  "/usr/bin/arm-linux-gnueabihf-gcc-4.5"
set_board_info c++compiler  "/usr/bin/arm-linux-gnueabihf-g++-4.6"

set_board_info rsh_prog /usr/bin/ssh
set_board_info rcp_prog /usr/bin/scp
set_board_info protocol standard
set_board_info hostname board

# Path to the gdbserver executable on target board.
set_board_info gdb_server_prog /home/omair-javaid/gdb-7.5/gdb/gdbserver/gdbserver

# We will be using the standard GDB remote protocol
set_board_info gdb_protocol "remote"

# Name of the computer whose socket will be used, if required.
set_board_info sockethost "localhost:"

# Port ID to use for socket connection
set_board_info gdb,socketport "45679"

# Use techniques appropriate to a stub
set_board_info use_gdb_stub 1

# This gdbserver can only run a process once per session.
set_board_info gdb,do_reload_on_run 1

# There's no support for argument-passing (yet).
set_board_info noargs 1

# Can't do input (or output) in the current gdbserver.
set_board_info gdb,noinferiorio 1

# Can't do hardware watchpoints, in general (it depends on gdbserver support for your target arch)
set_board_info gdb,no_hardware_watchpoints 1

set gdb_test_timeout 120

Running the testsuite.

cd ${gdb_source_dir}
make check RUNTESTFLAGS="--target_board=native-gdbserver"

Testing gdbserver in a native configuration

You can use the <gdb_source_directory>/gdb/testsuite/boards/native-gdbserver.exp board file to configure the testsuite like you did for remote targets in above configurations to run natively using gdbserver. To do so, follow the instructions provided in introductory comment of that file.

WorkingGroups/ToolChain/GDB/GettingStarted (last modified 2014-07-19 08:45:28)