Yocto: Debugging programs on the target using GDB

local.conf

IMAGE_INSTALL_append = "gdbserver"
EXTRA_IMAGE_FEATURES += "debug-tweaks"

GDB with tui support (optional)

Create recipe in meta-foo/recipes-devtools/gdb/gdb-%.bbappend and insert

EXTRA_OECONF_remove = " --disable-tui"
EXTRA_OECONF += " --enable-tui"

SDK

Use the extensible SDK, built using, e.g., bitbake -c populate_sdk_ext core-image-minimal

eSDK documentation

Use $ devtool modify <recipe> docs here to build and then install packages to be debugged into the eSDK.

I think using devtool, in most cases, automatically enables debug symbols, and installs them to the host sysroot, so they don’t have to be installed to the target.

Then build and deploy

$ devtool build recipe
$ devtool deploy-target <recipe> root@<machine-ip>

Run GDB on the target

# gdbserver localhost:1234 <prog> <args...>

Run GDB on the host, within the sdk env

$ $GDB

Then in gdb connect and debug

(gdb) target remote <machine-ip>:1234
(gdb) b main
(gdb) c