250Chapter8 • Cross-Platform and Embedded Systems Development
8.4.3.1Building Cross Debugger
Building a cross debugger is similar to the building process of a native debugger. When
you configure
gdb
, you need to mention the target CPU on the command line of the configure
script. You also need the required libraries for the target.
8.5Connecting to Target
Using
gdb
, there are two basic methods of connecting to the target machine when you debug a
program. These are:
•Using
gdbserver
program
•Using a stub
In this section we shall discuss the
gdbserver
method in detail because it is the same
for all platforms. The stub method differs from platform to platform and you need to create stub
file(s) for your target and tailor these into your code.
8.5.1Using
gdbserver
with GNU Debugger
The
gdbserver
utility comes with GNU debugger. I have used
gdb
version 5.1.1 and
you can compile the
gdbserver
after you compile your debugger. If the host machine is dif-
ferent from the target machine, you must cross-compile the
gdbserver
program. This utility
can run a program on a remote target and can communicate to
gdb
running on host.
When you build
gdb
from the source code, the
gdbserver
is not compiled during this
process. This is what happened when I compiled
gdb
version 5.1.1 on my RedHat 7.1 machine.
You have to compile it separately by going into the
gdb/gdbserver
directory. You can run
the following two commands to build and install it:
make
make install
You may choose to build a static binary of the
gdbserver
program if you don’t have
dynamic libraries installed on your target board. For the purpose of this book, I used the Arcom
board, which is introduced later in this chapter, and which has dynamic libraries installed. After
compiling, you can strip down symbols from the binary to reduce size because embedded sys-
tems usually have small storage areas.
The
gdbserver
program may display some error messages when you connect to the
server as it needed
/etc/protocols
files on the target Arcom board, which I copied manually.
The step-by-step process of using
gdbserver
is as follows:
•Compile a program on the host machine using the –
g
option.
•Transfer a stripped version of the output to the target machine. You can use a stripped
version because you don’t need symbols on the target.