debian tips/ tips/ Compiling a Debian package with debug symbols

Today I was experiencing a SIGSEGV while using mutt, and running in gdb was useless as there are were no debug symbols in the binary.

This is standard practice for Debian packages, so if you want to provide a backtrace for a bug report you will need to recompile the package. Here I demonstrate a quick and dirty way to do that. This method is not recommended if you want to make changes to the code as well.

So first check if the package has a debug package for it. More and more libraries are providing these packages to make debugging easier. If you are experiencing a problem with a library just installing the associated -dbg package should provide all the debugging symbols. (Marc Haber wrote this script to automatically install any -dbg packages of dependencies if they exist. Requires debfoster and grep-dctrl packages. This should help fill in gaps in the backtrace if possible).

If there is no debug package then you will have to recompile. First get the necessary dependencies (I will use mutt as my example).

     apt-get build-dep mutt

Then get the source of the package

     apt-get source mutt

Then enter the source directory

     cd mutt-1.5.13/

Most (all?) packages that use C code should look at the environment variable DEB_BUILD_OPTIONS to see whether to include debug symbols. The other use is to turn off optimisations. This can be useful, so try it, but it is possible that turning off optimistations solves the problem, in which case you should not use noopt.

     export DEB_BUILD_OPTIONS=nostrip,noopt

Now recompile the package (requires dpkg-dev and fakeroot),

     dpkg-buildpackage -rfakeroot -uc -us

This should complete normally, and leav a .deb in the parent directory, so then (as root):

     dpkg -i ../mutt_1.5.13-1_i386.deb

This will install the new package. Now try running under gdb again, and the debug symbols should be present.