- Go to the top of your Linux Cortex-M installation and activate a Linux Cortex-M development session:
[psl@pvr linux-cortexm-x.x.x]$ . ./ACTIVATE.sh
- Make sure your target board has TCP/IP configured and up in Linux:
~ # ifconfig eth0
eth0 Link encap:Ethernet HWaddr C0:B1:3C:83:83:83
inet addr:172.17.5.100 Bcast:172.17.255.255 Mask:255.255.0.0
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 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:0 (0.0 B) TX bytes:0 (0.0 B)
Interrupt:12
- It is recommended to rebuild your application with special GCC options. If your target is Cortex-M3, use the following options:
[psl@pvr app]$ arm-uclinuxeabi-gcc -o app app.c -mcpu=cortex-m3 -mthumb -O0 -g
If your target is Cortex-M4, do the following instead:
[psl@pvr app]$ arm-uclinuxeabi-gcc -o app app.c -mcpu=cortex-m4 -mthumb -O0 -g
- Make your application binary (app, not app.gdb) 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 is NFS-mounted to the host):
~ # /mnt/gdbserver :1234 /mnt/app
- Run GDB on the development host:
[psl@pvr app]$ arm-uclinuxeabi-gdb ./app.gdb
GNU gdb (GDB) 7.2.50.20100908-cvs
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<http://www.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-linux --target=arm-uclinuxeabi".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>
...
Reading symbols from /home/work/psl/SF/devel/linux-cortexm-1.4.0/projects/gdbtest/app/app.gdb...done.
(gdb)
- Establish a connection to the target:
(gdb) target remote 172.17.5.100:1234
Remote debugging using 172.17.5.100:1234 0x64030044 in _stext ()
- Debug your application using the standard GDB commands. Here is a sample debug session:
(gdb) b main
Breakpoint 1 at 0x640300ee: 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 0x64030102 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
0x64030102 in main () at app.c:20
20 ret = func(a,b);
Value returned is $4 = 15
(gdb)