Remote Debugging with GDB
Step through the following procedure in order to start remote debugging with gdbserver
:
Go to the top of your Linux Cortex-M installation and activate a Linux Cortex-M development session:
$ . ./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.82 Bcast:192.168.255.255 Mask:255.255.0.0 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)
Develop source files for whatever application user would like to debug on the uClinux target. For instance:
$ vi app.c #include <stdio.h> int func(int a, int b) { int c = (a+b)/2; printf("%s: (%d + %d)/2 = %d\n", __func__, a, b, c); return c; } int main() { int a, b, ret; a = 10; b = 20; ret = func(a,b); printf("%s: got result %d\n", __func__, ret); return 0; }
It is recommended to rebuild your application on the development host with special GCC options. Use the following options:
Make your application binary (
app
) and thegdbserver
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 theinitramfs
list of your kernel image. The gdbserver binary (${TOOLS_DIR}/debug-root/usr/bin/gdbserver
) is already included theinitramfs
file.Run
gdbserver
on the target (assuming/mnt/nfs
is NFS-mounted to the host):Run GDB on the development host:
Establish a connection to the target:
Debug your application using the standard GDB commands. Here is a sample debug session:
Â