Software Emulators Cross Compilations

Connecting to Target 253 gdb quit The program is running. Exit anyway? y or n y [rrehmandesktop 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.3 Running 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 devttyS1. GNU debugger uses its own serial port protocol to exchange information between host and target machines. The program being debugged is stored as tmpsum on the target machine. This example session is completed on an Arcom single-board computer running embedded Linux. rootSBC-GXx bin gdbserver devttyS1 tmpsum Process tmpsum created; pid = 180 Remote debugging using devttyS1 Enter first number : 3 Enter second number : 8 The sum is : 11 Killing inferior rootSBC-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 etcinittab file to stop the getty process from using the serial port. 8.5.1.4 Running gdb on Host Using Serial Port To connect to a target over a serial port devttyS0, you can use “target remote devttyS0 ” command after starting GNU debugger. A typical session to debug the sum.c program is shown below. [rootdesktop 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 andor 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. 254 Chapter 8 • Cross-Platform and Embedded Systems Development gdb target remote devttyS0 Remote debugging using devttyS0 0x40001930 in ?? gdb continue Continuing. Breakpoint 1, main at sum.c:6 6 printfEnter first number : ; gdb n 7 scanfd, num1; gdb n 8 printfEnter second number : ; gdb n 9 scanfd, 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 gdb quit The program is running. Exit anyway? y or n y [rootdesktop root] You do not use the run command in this session because the program has already been started by the gdbserver running on the target machine. 8.5.1.5 Serial Cable You can use a null modem cable to connect serial ports on the host and target machines. Connections for the null modem cable for a DB-9 connector are as shown in Table 8-1. How- ever, I hope that most people can simply go out and buy a null modem cable, without worrying about pinouts.