Debugging shared libraries

To debug the libraries that are built by the build tool you will have to make a few changes to the build configuration. For libraries built outside the build environment you will have to do some extra work.

The Yocto Project

The Yocto Project builds debug variants of binary packages and puts them into build/tmp/deploy/<package manager>/<target architecture>. Here is an example of the debug package, for the C library in this case:

build/tmp/deploy/rpm/armv5e/libc6-dbg-2.21-r0.armv5e.rpm

You can add these debug packages selectively to your target image by adding <package name-dbg> to your target recipe. For glibc, the package is named glibc-dbg. Alternatively, you can simply tell the Yocto Project to install all debug packages by adding dbg-pkgs to EXTRA_IMAGE_FEATURES. Be warned that this will increase the size of the target image dramatically, perhaps by several hundred megabytes.

The Yocto Project places the debug symbols in a hidden directory named .debug in both the lib and usr/lib, directories. GDB knows to look for symbol information in these locations within the sysroot.

The debug packages also contain a copy of the source code which is installed into directory usr/src/debug/<package name> in the target image, which is one of the reasons for the increase in size. You can prevent it from happening by adding to your recipes:

PACKAGE_DEBUG_SPLIT_STYLE = "debug-without-src"

Remember, though, that when you are debugging remotely with gdbserver, you only need the debug symbols and source code on the host, not on the target. There is nothing to stop you from deleting the lib/.debug, usr/lib/.debug and usr/src directories from the copy of the image that is installed on the target.

Buildroot

Buildroot is characteristically straightforward. You just need to rebuild with line-level debug symbols, for which you need to enable the following:

  • BR2_ENABLE_DEBUG in the menu Build options | build packages with debugging symbols

This will create the libraries with debug symbols in output/host/usr/<arch>/sysroot, but the copies in the target image are still stripped. If you need debug symbols on the target, perhaps to run GDB natively, you can disable stripping by setting Build options | strip command for binaries on target to none.

Other libraries

In addition to building with debug symbols you will have to tell GDB where to find the source code. GDB has a search path for source files, which you can see using the command show directories:

(gdb) show directories
Source directories searched: $cdir:$cwd

These are the default search paths: $cdir is the compile directory, which is the directory where the source was compiled; $cwd is the current working directory of GDB.

Normally these are sufficient, but if the source code has been moved you will have to use the directory command as shown here:

(gdb) dir /home/chris/MELP/src/lib_mylib
Source directories searched: /home/chris/MELP/src/lib_mylib:$cdir:$cwd
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.79.147