256Chapter8 • Cross-Platform and Embedded Systems Development
8.5.3Using Stubs with GNU Debugger
Stubs are software routines that you can link with your program. Using a stub, you can
connect the process created by the program to the GNU debugger from a remote target, eliminat-
ing the need for the
gdbserver
program.
Stubs are different for different targets. The GNU debugger contains some stubs by default
in the source code tree. For example, the
i386-stub.c
file can be used for targets that use
Intel CPUs. However you have to customize your stub depending on the target. Some instruc-
tions are included in the example source code files for the stub.
8.5.4Debugging the Debug Session
If you are not successful in connecting to the target machine using GDB, you can get help
from the remote debug mode of GNU debugger. After turning this mode ON, you will see a lot
on information on your screen when
gdb
establishes or tries to establish connection to a remote
target. This information shows packets sent and received by
gdb
. The following session shows
that we set the baud rate to 9600 using the
remotebaud
command, turn the remote debug
mode ON and then connect to the remote target on serial port
/dev/ttyS0
.
[root@desktop /root]# gdb sum
GNU gdb 5.1.1
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public
License, and you are
welcome to change it and/or distribute copies of it under
certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty"
for details.
This GDB was configured as "i686-pc-linux-gnu"...
(gdb) break main
Breakpoint 1 at 0x8048496: file sum.c, line 6.
(gdb) set remotebaud 9600
(gdb) set debug remote 1
(gdb) target remote /dev/ttyS0
Remote debugging using /dev/ttyS0
Sending packet: $Hc-1#09...Ack
Packet received: OK
Sending packet: $qC#b4...Ack
Packet received:
Sending packet: $qOffsets#4b...Ack
Packet received:
Sending packet: $.#3f...Ack
Packet received: T0508:30190040;05:00000000;04:f8fdffbf;
Sending packet: $m40001930,8#62...Ack
Packet received: 54e8520000005b89
Sending packet: $m40001930,7#61...Ack