Connecting to Target251
•Run
gdbserver
on the target machine. It will control your application program. It is
explained later in this section.
•Run
gdb
on the host machine.
•Connect
gdb
to the remotely running
gdbserver
process.
•Start debugging.
You can connect
gdb
on the host to the
gdbserver
running on the target over the net-
work or using the serial port. Both of these methods are described here.
8.5.1.1Running
gdbserver
On Target Using TCP/IP
When you have transferred the executable binary to the target, you can start the
gdbserver
process. The example below shows that the program being debugged is
/tmp/sum
, IP address of
the host machine is 192.168.1.3 and we are using TCP port 2000 for connection between the host
and the target machine. Note that the debugger will be running on the host machine.
In the following session, the
gdbserver
waits for connection from the debugger after
starting up. When you step through the program on the debugger side, you can enter values of
two numbers on the target machine. I used a Telnet session to open a window on the target. This
window was used to start
gdbserver
and enter values of two numbers.
root@SBC-GXx /bin# gdbserver 192.168.1.3:2000 /tmp/sum
Process /tmp/sum created; pid = 154
Remote debugging using 192.168.1.3:2000
Enter first number : 5
Enter second number : 7
The sum is : 12
Killing inferior
root@SBC-GXx /bin#
Note that the
gdbserver
terminates when you disconnect the debugger on the host side.
Source code of the program
sum.c
used in this example is as follows:
#include
main ()
{
int num1, num2, total ;
printf("Enter first number : ");
scanf("%d", &num1);
printf("Enter second number : ");
scanf("%d", &num2);
total = num1 + num2;
printf("\nThe sum is : %d\n", total);
}
Next Page >>
<< Previous Page
Back to the Table of Contents