Remote debugging using gdbserver

The key component for remote debugging is the debug agent, gdbserver, which runs on the target and controls execution of the program being debugged. Gdbserver connects to a copy of GDB running on the host machine via a network connection or an RS-232 serial interface.

Debugging through gdbserver is almost, but not quite, the same as debugging natively. The differences are mostly centered around the fact that there are two computers involved and they have to be in the right state for debugging to take place. Here are some things to look out for:

Debug symbols increase the size of executables dramatically, sometimes by a factor of 10. As mentioned in Chapter 5, Building a Root Filesystem, it can be useful to remove debug symbols without recompiling everything. The tool for the job is strip from your cross toolchain. You can control the aggressiveness of the strip with these switches:

With that in mind, let's look at the specifics involved in debugging with the Yocto Project and Buildroot.

The Yocto Project builds a cross GDB for the host as part of the SDK, but you will have to make changes to your target configuration to include gdbserver in the target image. You can add the package explicitly, for example by adding this to conf/local.conf, noting once again that there must be a leading space at the start of this string:

Or, you can add tools-debug to EXTRA_IMAGE_FEATURES, which will add both gdbserver and strace to the target image (I will talk about strace in the next chapter):

With Buildroot, you need to enable options both to build the cross GDB for the host (assuming that you are using the Buildroot internal toolchain) and to build gdbserver for the target. Specifically you need to enable: