Remote Debugging with GDB Print

 

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

  • Go to the top of your Linux i.MX6 installation and activate the cross development environment:
  • [sasha@liman linux-imx6sx-2.3.3]$ . ACTIVATE.sh

  • Make sure your target board has TCP/IP configured and up in Linux:
  • ~ # ifconfig eth0 Link encap:Ethernet HWaddr 3C:FB:96:02:04:9B inet addr:192.168.0.66 Bcast:192.168.0.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:13108 errors:0 dropped:0 overruns:0 frame:0 TX packets:10853 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:1475879 (1.4 MiB) TX bytes:1121568 (1.0 MiB)

  • It is recommended to rebuild your application (see attached for example) with special GCC options. Use the following options:
  • [sasha@liman app]$ $CC -o app app.c -O0 -g

  • Deploy your application binary (app) to the target. For example, you can scp it or add to the initramfs image:
  • [sasha@liman app]$ scp app This e-mail address is being protected from spambots. You need JavaScript enabled to view it :/tmp/ app 100% 10KB 10.4KB/s 00:00

  • Run gdbserver on the target:
  • ~ # gdbserver :1234 /tmp/app Process /tmp/app created; pid = 527 Listening on port 1234

  • Run GDB on the development host:
  • [sasha@liman app]$ arm-poky-linux-gnueabi-gdb ./app GNU gdb (GDB) 7.8.1 Copyright (C) 2014 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-pokysdk-linux -- target=arm-poky-linux-gnueabi". 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...done. (gdb)

  • Specify the sysroot directory containing copies of the target libraries:
  • (gdb) set sysroot /opt/poky/1.8.1/sysroots/\ cortexa5hf-vfp-neon-poky-linux-gnueabi (gdb)

  • Establish a connection to the target:
  • (gdb) target remote 192.168.0.66:1234 Remote debugging using 192.168.0.66:1234 Reading symbols from /opt/poky/1.8.1/sysroots/cortexa5hf-vfp-neon-poky- linux-gnueabi/lib/ld-linux-armhf.so.3...Reading symbols from /opt/poky/ 1.8.1/sysroots/cortexa5hf-vfp- neon-poky-linux-gnueabi/lib/.debug/ld-2.21.so...done. done. Loaded symbols for /opt/poky/1.8.1/sysroots/cortexa5hf-vfp-neon-poky- linux-gnueabi/lib/ld-linux-armhf.so.3 0x76fd7b00 in _start () from /opt/poky/1.8.1/sysroots/cortexa5hf-vfp-neon-poky-linux-gnueabi /lib/ld-linux-armhf.so.3 (gdb)

  • Debug your application using the standard GDB commands. Here is a sample debug session:
  • (gdb) b main Breakpoint 1 at 0x8490: file app.c, line 16. (gdb) c Continuing. warning: Could not load shared library symbols for linux-vdso.so.1. Do you need "set solib-search-path" or "set sysroot"? 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 0x000084ac 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 0x000084ac in main () at app.c:20 20 ret = func(a,b); Value returned is $4 = 15 (gdb)

The linux-vdso warning above is benign and can be ignored.