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. $ . ./

  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: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)

  5. 3. It is recommended to rebuild your application on the development host with special GCC options. Use the following options:
  6. ${CROSS_COMPILE_APPS}gcc -g -o app app.c

  7. 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.
  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. $ 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 <> 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: <>. Find the GDB manual and other documentation resources online at: <>. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from app... (gdb)

  12. Establish a connection to the target:
  13. (gdb) target remote Remote debugging using Reading /lib/ from remote target... warning: File transfers from remote targets can be slow. Use "set sysroot" to access files locally instead. 0x82110a40 in ?? ()

  14. Debug your application using the standard GDB commands. Here is a sample debug session:
  15. (gdb) b main Breakpoint 1 at 0x8211d774: file app.c, line 16. (gdb) c Continuing. Reading /lib/ from remote target... Reading /lib/ 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)