252Chapter8 • Cross-Platform and Embedded Systems Development
It is the same program that was used in Chapter 5 for different examples.
8.5.1.2Running
gdb
on Host Using TCP/IP
After starting
gdbserver
on the target, now you can start the GNU debugger on host.
The host and target must be connected over a TCP/IP network for this example. In the following
session on the host machine, file
sum
is a non-stripped version of the program that you uploaded
to the target machine as it provides the symbol table to the debugger. After starting the debugger,
you use the “
target remote 192.168.1.10:2000
” command to connect to the
gdb-
server
running on the target machine 192.168.1.10. After that you can continue with normal
debugging process.
[rrehman@desktop 5]$ 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) target remote 192.168.1.10:2000
Remote debugging using 192.168.1.10:2000
0x40001930 in .. ()
(gdb) break main
Breakpoint 1 at 0x8048496: file sum.c, line 6.
(gdb) continue
Continuing.
Breakpoint 1, main () at sum.c:6
6 printf("Enter first number : ");
(gdb) n
7 scanf("%d", &num1);
(gdb) n
8 printf("Enter second number : ");
(gdb) n
9 scanf("%d", &num2);
(gdb) n
11 total = num1 + num2;
(gdb) n
13 printf("\nThe sum is : %d\n", total);
(gdb) n
14 }
(gdb) n
warning: Cannot insert breakpoint 0:
Cannot access memory at address 0x1