Remote Debugging

   


In remote debugging, the executable being debugged and the debugger run on different computers. The executable runs on the target computer, and the debugger runs on the host computer. Remote debugging requires a debugging server running on the target computer. The debugging server, gdbserver, interfaces the target executable with the host debugger, gdb. The debugging server and the debugger converse over a communications link. You are using the TCP/IP Ethernet network, but serial links can also be used. After link establishment, the debugging process proceeds like a local debugging session.

In this section, you'll boot the MediaEngine, tbdevarm, as you did in Chapter 4, "Booting Linux," and then you'll run gdbserver on it. (In Chapter 4, the buildrootfilesystem script copied gdbserver and helloworld-arm-linux to the target's root file system.) You can run gdb on the tbdev1 host and establish a TCP connection to tbdevarm's gdbserver. Then, you can debug helloworld-arm-linux running on the tbdevarm.

Figure 5.1 shows tbdev1 and tbdevarm, with a serial connection and a network connection. You are again using minicom on tbdev1 to boot the tbdevarm (see Chapter 4) and gain access to bash. Remember that tbdevarm's console is routed through its serial port, ttyS0.

Figure 5.1. The remote debugging computer configuration.

graphics/05fig01.gif

Here are the steps to remotely debug helloworld-arm-linux running on the MediaEngine and gdb running on tbdev1:

  1. Run minicom on tbdev1 and boot tbdevarm. Start gdbserver on tbdevarm, telling gdbserver to accept a TCP/IP connection from tbdev1 and start executing helloworld-arm-linux:

     bash-2.04# cd /tmp bash-2.04# gdbserver 192.168.1.11:2345 helloworld-arm-linux Process helloworld-arm-linux created; pid = 17 

    tbdevarm's gdbserver is now executing helloworld-arm-linux and will accept a connection on port 2345 from 192.168.1.11 (that is, tbdev1).

  2. In a different console window on tbdev1, start gdb. (You can use Alt+F2 on tbdev1 to switch to the second virtual console window.) You need to be in the correct directory, /root/cross/builds, where the helloworld source code exists. If helloworld-arm-linux doesn't exist, compile it by using the -g debugging flag. You also need to run the processor-specific cross-compiled version of gdb that was compiled in Chapter 3. In this case, it's arm-linux-gdb. Here are the commands to cross-compile helloworld.c with the debugging option and start gdb:

     root@tbdev1[530]: cd /root/cross/builds root@tbdev1[531]: arm-linux-gcc -g -o helloworld-arm-linux helloworld.c  root@tbdev1[532]: arm-linux-gdb helloworld-arm-linux GNU gdb 5.0 Copyright 2000 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 "--host=i686-pc-linux-gnu --target=arm-linux"... (gdb) 
  3. Tell gdb to establish the remote connection to tbdevarm, by using the target extended-remote command. Using extended-remote allows for the target executable to restart without restarting tbdevarm's gdbserver.

     (gdb) target extended-remote 192.168.1.21:2345 Remote debugging using 192.168.1.21:2345 0x40002a50 in ?? () (gdb) 
  4. Switch to the minicom console (by pressing Alt+F1), and you'll see that remote debugging has begun:

     Process helloworld-arm-linux created; pid = 17 Remote debugging using 192.168.1.11:2345 

    gdb (arm-linux-gdb), running on tbdev1, is now connected to tbdevarm's gdbserver, which is running helloworld-arm-linux. Any tbdev1 gdb commands that you issue now actually execute on tbdevarm.

  5. Again step through the local debugging session described in the preceding section, this time debugging remotely. Switch back to tbdev1's second console:

     (gdb) run The program being debugged has been started already. Start it from the beginning? (y or n) y Starting program: /root/cross/builds/helloworld-arm-linux Program exited with code 025. (gdb) 

    Not much happened here because helloworld's printf went to tbdevarm's console, not to the debugger. Check this by switching back to the minicom console, and you should see this:

     GDBserver restarting Process helloworld-arm-linux created; pid = 21 Hello world 1 times! Hello world 2 times! Hello world 3 times! Hello world 4 times! Hello world 5 times! Hello world 6 times! Hello world 7 times! Hello world 8 times! Hello world 9 times! Child exited with retcode = 15 Child exited with status 0 Killing inferior GDBserver restarting Process helloworld-arm-linux created; pid = 22 

    The cross-compiled version of helloworld has successfully executed on the ARM processor of tbdevarm.

  6. Set a breakpoint at line 9 and then step through the program, examine the value of variable i, change the value, and view the program's output on the tbdevarm console:

     (gdb) break 9 Breakpoint 1 at 0x83cc: file helloworld.c, line 9. (gdb) run The program being debugged has been started already. Start it from the beginning? (y or n) y Starting program: /root/cross/builds/helloworld-arm-linux Breakpoint 1, main () at helloworld.c:9 9                       printf("Hello world %d times!\n",i); (gdb) print i $1 = 1 (gdb) next 7               for (i = 1; i < 10; i++) (gdb) set variable i = 8 (gdb) continue Continuing. Breakpoint 1, main () at helloworld.c:9 9                       printf("Hello world %d times!\n",i); (gdb) continue Continuing. Program exited with code 025. (gdb) 
  7. Switch back to the minicom console to see the expected printf result of variable i being changed from 1 to 8:

     GDBserver restarting Process helloworld-arm-linux created; pid = 34 Hello world 1 times! Hello world 9 times! Child exited with retcode = 15 Child exited with status 0 Killing inferior GDBserver restarting Process helloworld-arm-linux created; pid = 35 

You have now completed your first multi-architecture remote debugging session. Wasn't that easy? You now have a functional multiarchitecture system to build on. From here, you can investigate the use of the tools that are built on gdb, such as ddd and insight, to make your debugging life easier. See the "Additional Reading" section at the end of this chapter for more information.


       
    Top


    Embedded LinuxR. Hardware, Software, and Interfacing
    Embedded LinuxR. Hardware, Software, and Interfacing
    ISBN: N/A
    EAN: N/A
    Year: 2001
    Pages: 103

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net