The GDB server utility provided with Sourcery G++ Lite can be used to debug
a GNU/Linux application. While Sourcery G++ runs on your host system,
gdbserver
and the target application
run on your target system. Even though Sourcery G++ and your application
run on different systems, the debugging experience when using
gdbserver
is very similar to debugging a native application.
The GDB server executables are included in the sysroot in ABI-specific
subdirectories of
. Use the
executable from the sysroot and library subdirectory
that match your program.
See Section 3.2, “Library Configurations” for details.
sysroot
/usr
You must copy the sysroot to your target system as described in Section 3.6.1, “Installing the Sysroot”. You must also copy the executable you want to debug to your target system.
If you have installed the sysroot in the root directory of the filesystem
on the target, you can invoke gdbserver
as:
> gdbserver :10000 program arg1 arg2 ...
where program
is the path to the program you
want to debug and arg1 arg2 ...
are the arguments
you want to pass to it. The :10000
argument indicates
that gdbserver
should listen for connections from GDB
on port 10000.
You can use a different port, if you prefer.
If you have installed the sysroot in an alternate directory, invoking
gdbserver
becomes more complicated. You must build
your application using the link-time options to specify the location of
the sysroot, as described in Section 3.6.2, “Using Linker Options to Specify the Sysroot Location”. You
must also invoke gdbserver
itself using the dynamic
linker provided in the Sourcery G++ sysroot, as described in
Section 3.6.3, “Specifying the Sysroot Location at Runtime”. In other words, the command to
invoke gdbserver
in this case would be similar to:
>sysroot
/lib/ld-linux.so.3 \ --library-pathsysroot
/lib:sysroot
/usr/lib \sysroot
/usr/lib/bin/gdbserver :10000program arg1 arg2 ...
You can connect to GDB server by using the following command from within GDB:
(gdb) target remote target
:10000
where target
is the host name or IP address
of your target system.
When your program exits, gdbserver
exits too.
If you want to debug the program again, you must restart
gdbserver
on the target.
Then, in GDB, reissue the target
command shown above.
In order to debug shared libraries, GDB needs to map the pathnames of shared libraries on the target to the pathnames of equivalent files on the host system. Debugging of multi-threaded applications also depends on correctly locating copies of the libraries provided in the sysroot on the host system.
In some situations, the target pathnames are valid on the host system. Otherwise, you must tell GDB how to map target pathnames onto the equivalent host pathnames.
In the general case, there are two GDB commands required to set up the mapping:
(gdb) set sysroot-on-targettarget-pathname
(gdb) set sysroothost-pathname
This causes GDB to replace all instances of the
target-pathname
prefix in shared library
pathnames reported by the target with
host-pathname
to get the location of the
equivalent library on the host.
If you have installed the sysroot in the root filesystem on the target,
you can omit the set sysroot-on-target
command, and
use only set sysroot
to specify the location on the
host system.
Refer to Section 3.6.1, “Installing the Sysroot” for more information about installing the sysroot on the target. Note that if you have installed a stripped copy of the provided libraries on the target, you should give GDB the location of an unstripped copy on the host.