Step through the following procedure in order to start remote debugging of Linux userspace applications with gdbserver:
Download the Yocto toolchain from the Emcraft website.
Install the toolchain to your development host. The toolchain can be installed to an arbitrary directory:
$ sh ./meta-toolchain-qt5-openstlinux-weston-stm32mp1-som-x86_64-toolchain-2.4-snapshot.sh
Activate the cross-build environment:
$ source /opt/st/stm32mp1-som/2.4-snapshot/environment-setup-aarch64-poky- linux $ unset CCACHE_PATH
Make sure your target board has TCP/IP configured in Linux:
~ # ifconfig eth0 Link encap:Ethernet HWaddr 3c:fb:96:77:88:a0 inet addr:172.17.11.163 Bcast:172.17.255.255 Mask:255.255.0.0 inet6 addr: fe80::3efb:96ff:fe77:88a0/64 Scope:Link UP BROADCAST RUNNING MULTICAST DYNAMIC MTU:1500 Metric:1 RX packets:8407 errors:0 dropped:27 overruns:0 frame:0 TX packets:551 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:831648 (812.1 KiB) TX bytes:247626 (241.8 KiB) ...
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:[sasha@liman app]$ scp app root@172.17.11.163:/tmp/ app 100% 10KB 10.4KB/s 00:00
Alternatively, you can configure an NFS server on your development host and export your build directory. To mount the exported directory on the target, run the following commands:
~ # mount -o nolock 172.17.0.19:/work/stm32mp1 /mnt ~ # ls -l mnt ... -rwxrwxr-x 1 1002 1002 14612 Apr 16 20:37 app -rw-rw-r-- 1 1002 1002 219 Apr 16 20:36 app.c ~ # cp /mnt/app /tmp
Run
gdbserver
on the target:~ # gdbserver :1234 /tmp/app Process /tmp/app created; pid = 3366 Listening on port 1234
Run GDB on the development host:
[sasha@liman app]$ arm-openstlinux_weston-linux-gnueabi-gdb ./app GNU gdb (GDB) 8.0 Copyright (C) 2017 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-pokysdk-linux --target=arm-openstlinux_weston-linux-gnueabi". Type "show configuration" for configuration details. For bug reporting instructions, please see: <http://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...done. (gdb)
Specify the
sysroot
directory containing the copies of the target libraries:(gdb) set sysroot /opt/st/stm32mp1-som/2.4-snapshot/sysroots/cortexa7hf- neon-vfpv4-openstlinux_weston-linux-gnueabi (gdb)
Establish a connection to the target:
(gdb) target remote 172.17.11.163:1234 Remote debugging using 172.17.11.163:1234 Reading symbols from /opt/st/stm32mp1-som/2.4-snapshot/sysroots/cortexa7hf -neon-vfpv4-openstlinux_weston-linux-gnueabi/lib/ld-linux-armhf.so.3... Reading symbols from /opt/st/stm32mp1-som/2.4-snapshot/sysroots/cortexa7hf -neon-vfpv4-openstlinux_weston-linux-gnueabi/lib/.debug/ld-2.26.so...done. done. 0xb6fcea80 in _start () from /opt/st/stm32mp1-som/2.4-snapshot/sysroots/cortexa7hf-neon-vfpv4- openstlinux_weston-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 0x10478: 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 0x10494 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 0x10494 in main () at app.c:20 20 ret = func(a,b); Value returned is $4 = 15 (gdb)