- Go to the top of your Linux Cortex-M installation and activate a Linux Cortex-M development session:
[yur@ubuntu linux-cortexm-2.5.0]$ . ./ACTIVATE.sh
- 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.101 Bcast:192.168.1.255 Mask:255.255.255.0
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)
- It is recommended to rebuild your application with special GCC options. Use the following options:
[yur@ubuntu app]$ arm-v7-linux-uclibceabi-gcc -o app app.c \
-mcpu=cortex-m3 -mthumb -static -O0 -g
- 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.
- 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
- Run GDB on the development host:
[yur@ubuntu app]$ arm-v7-linux-uclibceabi-gdb ./app
GNU gdb (20171018-043249- build on skywanderer.emcraft.com by psl) 7.5.1
Copyright (C) 2012 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=i686-pc-linux-gnu
--target=arm-v7-linux-uclibceabi"...
Reading symbols from /home/yur/imx/linux-cortexm-2.5.0/
app/app...done.
(gdb)
- Establish a connection to the target:
(gdb) target remote 192.168.1.101:1234
Remote debugging using 192.168.1.101:1234
0x805a0200 in _start ()
- Debug your application using the standard GDB commands. Here is a sample debug session:
(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)