Connecting to Target253
(gdb) quit
The program is running. Exit anyway. (y or n) y
[rrehman@desktop 5]$
Note that after each
scanf
statement, you have to enter the input value on the target. This
is because the program is actually running on the target machine. Since both host and target are
connected over a network, you can open a Telnet window on the target for input and output.
8.5.1.3Running
gdbserver
on Target Using Serial Port
You can also use
gdbserver
to connect a host and target machine over a serial port link.
In the following example, you start
gdbserver
to communicate to the debugger over serial
port
/dev/ttyS1
. GNU debugger uses its own serial port protocol to exchange information
between host and target machines. The program being debugged is stored as
/tmp/sum
on the
target machine. This example session is completed on an Arcom single-board computer running
embedded Linux.
root@SBC-GXx /bin# gdbserver /dev/ttyS1 /tmp/sum
Process /tmp/sum created; pid = 180
Remote debugging using /dev/ttyS1
Enter first number : 3
Enter second number : 8
The sum is : 11
Killing inferior
root@SBC-GXx /bin#
Note that if you are running any other program on the serial port, it should be stopped. In
most cases a
getty
process is running on serial ports. You can edit the
/etc/inittab
file to
stop the
getty
process from using the serial port.
8.5.1.4Running
gdb
on Host Using Serial Port
To connect to a target over a serial port
/dev/ttyS0
, you can use “
target remote
/dev/ttyS0
” command after starting GNU debugger. A typical session to debug the
sum.c
program is shown below.
[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.
Next Page >>
<< Previous Page
Back to the Table of Contents