How to Use GDB and GDBServer

GDBServer is a program that allows you to run GDB on a different machine than the one running the program being debugged.

Prerequisites

  • Toolchain
    • GDB
      • Web Factory: Enabled by default
      • Desktop Factory: Enable in Toolchain Configuration --> GDB
    • GDB Server (will be installed to RFS)
      • Web Factory: Enable the gdbserver package (Development category)
      • Desktop Factory: Enable in Toolchain Configuration --> GDB --> GDB Server for target
  • Program to be debugged
    • copy on host including debug information (no stripping, compiled with -g)
    • copy on target RFS to run

If you are using Factory on your desktop, then you can run "make checktool-gdb" to check your platform for compatibility with GDB/GDBServer.

Procedure

  • On the target:
    • Run GDBServer with your target program
      gdbserver localhost:10000 <program> <args>
  • On the host
    • Start GDB
      /path/to/your/toolchain/bin/<arch>-gdb
    • Load the symbols from your unstripped copy of the binary
      file <program>
    • Connect to the target GDBServer
      target remote <ip-of-target>:10000
    • Optionally set your target sysroot
      set sysroot <path to unstripped rfs>
    • Debug as normal. Note that instead of issuing the run command to begin, you need to enter continue as the program will already be running on the target.

Examples

  • Target:
    bash-3.1# gdbserver localhost:10000 vim /etc/network/interfaces 
    Process vim created; pid = 335
    Listening on port 10000
    
  • Host:
    $ ~/timesys/omap3530zoom/toolchain/bin/armv7l-timesys-linux-gnueabi-gdb
    GNU gdb 6.8
    Copyright (C) 2008 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.  Type "show copying" 
    and "show warranty" for details.
    This GDB was configured as "--host=i486-linux-gnu --target=armv7l-timesys-linux-gnueabi".
    (gdb) file vim
    Reading symbols from /home/timesys/factory/build_armv7l-timesys-linux-gnueabi/vim-7.2/vim72/src/vim...done.
    (gdb) target remote 10.5.5.30:10000
    Remote debugging using 10.5.5.30:10000
    [New Thread 335]
    0x400007c0 in _start ()
       from ~/timesys/omap3530zoom/toolchain/lib/ld-linux.so.3
    (gdb) 
    

Additional Resources