Remote Debugging with GDB Print


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:
  2. [yur@ubuntu linux-cortexm-2.5.0]$ . ./

  3. Make sure your target board has TCP/IP configured and up in Linux:
  4. / # ifconfig eth0 eth0 Link encap:Ethernet HWaddr AA:BB:CC:DD:EE:F0 inet addr: Bcast: Mask: UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:1 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:253 (253.0 B) TX bytes:0 (0.0 B)

  5. It is recommended to rebuild your application with special GCC options. Use the following options:
  6. [yur@ubuntu app]$ arm-v7-linux-uclibceabi-gcc -o app app.c \
    -mcpu=cortex-m3 -mthumb -static -O0 -g

  7. Make your application binary (app) and the gdbserver binary ({INSTALL_ROOT}/A2F/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.
  8. Run gdbserver on the target (assuming /mnt/nfs is NFS-mounted to the host):
  9. / # gdbserver :1234 /mnt/nfs/app Process /mnt/nfs/app created; pid = 100 Listening on port 1234

  10. Run GDB on the development host:
  11. [yur@ubuntu app]$ arm-v7-linux-uclibceabi-gdb ./app GNU gdb (20171018-043249- build on by psl) 7.5.1 Copyright (C) 2012 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <> 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=i686-pc-linux-gnu --target=arm-v7-linux-uclibceabi"... Reading symbols from /home/yur/imx/linux-cortexm-2.5.0/ app/app...done. (gdb)

  12. Establish a connection to the target:
  13. (gdb) target remote Remote debugging using 0x805a0200 in _start ()

  14. Debug your application using the standard GDB commands. Here is a sample debug session:
  15. (gdb) b main Breakpoint 1 at 0x805b03bc: file app.c, line 16. (gdb) c Continuing. 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 0x805b03cc 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 0x805b03cc in main () at app.c:20 20 ret = func(a,b); Value returned is $4 = 15 (gdb)