Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Step through the following procedure in order to start remote debugging with gdbserver:

  1. Go to the top of your Linux Cortex-M installation and activate a Linux Cortex-M development session:

    $ . ./ACTIVATE.sh
  2. Make sure your target board has TCP/IP configured and up in Linux:

    / # ifconfig eth0
    eth0      Link encap:Ethernet  HWaddr AA:BB:CC:DD:EE:F0
              inet addr:192.168.1.82  Bcast:192.168.255.255  Mask:255.255.0.0
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:3014 errors:0 dropped:11 overruns:0 frame:0
              TX packets:344 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000
              RX bytes:248079 (242.2 KiB)  TX bytes:402628 (393.1 KiB)
    
  3. It is recommended to rebuild your application on the development host with special GCC options. Use the following options:

    ${CROSS_COMPILE_APPS}gcc -g -o app app.c
  4. Make your application binary (app) and the gdbserver binary (${TOOLS_DIR}/debug-root/usr/bin/gdbserver) accessible from the target. You can NFS-mount some host directory from the target for that purpose or put these binaries to the initramfs list of your kernel image. The gdbserver binary (${TOOLS_DIR}/debug-root/usr/bin/gdbserver) is already included the initramfs file.

  5. Run gdbserver on the target (assuming /mnt/nfs is NFS-mounted to the host):

    / # gdbserver :1234 /mnt/nfs/app
    Process /mnt/nfs/app created; pid = 100
    Listening on port 1234
  6. Run GDB on the development host:

    $ arm-buildroot-uclinuxfdpiceabi-gdb app
    GNU gdb (GDB) 11.2
    Copyright (C) 2022 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=x86_64-pc-linux-gnu --target=arm-
    buildroot-uclinuxfdpiceabi".
    Type "show configuration" for configuration details.
    For bug reporting instructions, please see:
    <https://www.gnu.org/software/gdb/bugs/>.
    Find the GDB manual and other documentation resources online at:
        <http://www.gnu.org/software/gdb/documentation/>.
    
    For help, type "help".
    Type "apropos word" to search for commands related to "word"...
    Reading symbols from app...
    (gdb) 
    
  7. Establish a connection to the target:

    (gdb) target remote 192.168.1.82:1234
    Remote debugging using 192.168.1.82:1234
    Reading /lib/ld-uClibc.so.0 from remote target...
    warning: File transfers from remote targets can be slow. Use "set sysroot" 
    to access files locally instead.
    0x82110a40 in ?? ()
  8. Debug your application using the standard GDB commands. Here is a sample debug session:

    (gdb) b main
    Breakpoint 1 at 0x8211d774: file app.c, line 16.
    (gdb) c
    Continuing.
    Reading /lib/libc.so.0 from remote target...
    Reading /lib/ld-uClibc.so.0 from remote target...
    
    Breakpoint 1, main () at app.c:16
    16              a = 10;
    (gdb) n
    18              b = 20;
    (gdb) p a
    $1 = 10
    (gdb) n
    20              ret = func(a,b);
    (gdb) p b
    $2 = 20
    (gdb) s
    func (a=10, b=20) at app.c:5
    5               int c = (a+b)/2;
    (gdb) n
    7               printf("%s: (%d + %d)/2 = %d\n", __func__, a, b, c);
    (gdb) p c
    $3 = 15
    (gdb) bt
    #0  func (a=10, b=20) at app.c:7
    #1  0x8211d784 in main () at app.c:20
    (gdb) n
    9               return c;
    (gdb) n
    10      }
    (gdb) fini
    Run till exit from #0  func (a=10, b=20) at app.c:10
    0x8211d784 in main () at app.c:20
    20              ret = func(a,b);
    Value returned is $4 = 15
    (gdb)

  • No labels