Will the real debug package please stand up
While mucking around with stack traces, valgrind, and apport-valgrind, I stumbled across two types of debug symbol  packages:
- dbg packages, for example: empathy-dbg
- dbgsym packages, for example: empathy-dbgsym
The package Description fields  shed no light on which to use:
Description-en: GNOME multi-protocol chat and call client (debug symbols) Instant messaging program supporting text, voice, video, file transfers and inter-application communication over many different protocols, including: AIM, MSN, Google Talk (Jabber/XMPP), Facebook, Yahoo!, Salut, Gadu-Gadu, Groupwise, ICQ and QQ. This package contains the Empathy IM application and account manager.empathy-dbgsym:
Description: debug symbols for package empathy Instant messaging program supporting text, voice, video, file transfers and inter-application communication over many different protocols, including: AIM, MSN, Google Talk (Jabber/XMPP), Facebook, Yahoo!, Salut, Gadu-Gadu, Groupwise, ICQ and QQ. This package contains the Empathy IM application and account manager.Turning to the internet, I found many others had asked the same question, and they usually got answers like this:
You can use either the -dbg or the -dbgsym packages, but you can't use both.Still, no guidance as to which to use. And anyway, I wanted to understand what was going on at a deeper level. Investigating further, I found that dbg packages are hosted in the standard archive (archive.ubuntu.com), whereas dbgsym packages are hosted in a special archive: ddebs.ubuntu.com.
It also turns out that the dbgsym packages on ddebs.ubuntu.com com do not appear to be strictly normal debian packages:
- Normal debian packages end in ".deb" (for example: empathy-dbg_22.214.171.124-0ubuntu1_amd64.deb)
- The packages on ddebs.ubuntu.com end in ".ddeb" (empathy-dbgsym_3.6.3-0ubuntu2_amd64.ddeb)
This warranted further poking around. Here are my findings.
dbg packages are the traditional debian method for providing debug symbols separately from the normally installed binary packages.
dbg packages are created by upstream packagers and flow naturally into the standard Ubuntu archives. They are normal debian packages (that end in ".deb").
There is usually only one binary dbg package per source package. That is, there are usually not separate dbg packages for individual binary packages, there's just one named after the source package, like empathy-dbg.
They are pretty easy to make these days. The normal way is described here.
So, thanks to a lot of upstream work, the Ubuntu standard archive already has lots of these dbg packages. You can see a list of them with something like this:
$ apt-cache search dbg | less
These dbg packages work as expected: if you install, for example, empathy-dbg, and then generate an empathy stack trace (with valgrind or gdb, for example):
- The symbols it contains should be converted to useful function names (instead of being question marks)
- The source file names should be displayed (instead of paths to shared object (.so) and other binary files)
But, not every package in Ubuntu has a dbg package. And, even those that do may have created them in different ways, and possibly with different naming conventions, which makes them difficult (or impossible) to find mechanistically.
This is where dbgsym packages come in.
Consider the Ubuntu archive: thousands of binary packages (more than 7000 in the Ubuntu 12.10 Quantal main archive component alone).
That's a lot of different people in teams maintaining a lot of packages.
Inevitably, some packages that arguably should provide binary debug symbol packages do not. Or they do, but in a slightly different way, for example, the package name may not follow the standard pattern.
This wonderful diversity adds up to a concrete problem: the complete set of debug symbols required for debugging and creating useful stack traces of any arbitrary packaged C executable (ELF file) are not reliably present in standard Ubuntu archives.
Suppose I need to check something for memory leaks using apport-valgrind or debug it with gdb and I hit one of these missing bits?
Fortunately, there is a systematic (and automatic) solution (which is almost fully working).
The idea is to automate the generation of debug symbols at package build time (whether or not the package maintainers took steps to create dbg packages). For each binary package that installs an executable for which symbols may be helpful, automatically create a new BINARYPACKAGE-dbgysm package, and let it install the appropriate set of debug symbol binaries. Make it conflict with the dbg package to avoid file collisions. Then, publish them in ddebs.ubuntu.com.
That's two steps:
- Creating the dbgsym binary packages (this part seems to be fully implemented)
- Publishing them to ddebs.ubuntu.com (this part may not be fully implemented)
Binary package oriented
The dbgsym approach has a finer granularity than the usual dbg approach: it is binary package oriented. That is, a dbgysm package is created for each appropriate binary package (each that installs an ELF), whereas with the traditional, manual dbg approach, there is usually one dbg package created for all binary packages.
So there are often many dbgsym packages per source package with this approach, which results in many more dbgsym packages than dbg packages, a good thing: you only need to download and install the parts you want.
Conflicts - a closer look
These automatically generated binary dbgsym packages install some of the same files  as the corresponding dbg package, by design. But, without additional packaging steps, this would amount to a packaging error (since no single file may be installed by two binary packages without special steps to resolve this collision).
This is automatically handled by setting the dbgsym package to conflict with the dbg package(s). (Conflicting packages cannot both be fully installed at the same time.) This explains why I found so many statements saying that "dbg and dbgsym packages cannot both be installed at the same time." It is literally not possible due to these intentional conflicts settings.
How dbgsym packages are created
dbgsym packages are automatically created during a normal source package binary build by the pkg-create-dbgsym package, if it is installed. That is, if you install pkg-create-dbgsym, whenever a debian source package is built (for example with
debuildin the source tree), pkg-create-dbgsym scripts create the dbgysm binary packages and set them to conflict as appropriate. (Thanks to Martin Pitt and other debian developers.) These steps are in addition to the normal activities of a build, so you also generate non-debug binary packages.
For example, after installing pkg-create-dbgsym, I built the empathy source package, and here are the binary packages that were created . Lots of dbgsym ddebs!
ddeb: Huh? What?
These dbgsym binary package files end in ".ddeb", not ".deb", so what's up with that?
As far as I can tell, this is merely a convenience for archive maintenance. That is: a .ddeb is exactly the same as a .deb, except that its extension is different. This serves the purpose of allowing archive management tools to find ddeb binary packages and treat them differently, in this case:
- Posting them on ddebs.ubuntu.com
- Not posting them on archive.ubuntu.com
Enough already: which to use?
So, after this exploration, I vote for dbgsym packages over dbg packages for the following reasons
- The trend is towards automatic generation of dbgsym packages and automatic posting of them to separate ddebs archive like http://ddebs.ubuntu.com
- Such ddeb archives should contain more debug symbol packages than the traditional dbg packages because they are automatically created for all appropriate packages (instead of relying on maintainers to add a dbg package) so you get more
- Such ddeb archives certainly should contain equivalents for the existing dbg packages as well, so you lose nothing
- If you want, you can just get the debug symbols you need, since dbgsym packages are more granular
Also, manually created dbg packages may disappear over time. Why? No need for package maintainers to think about debug packages. And the normal archives get smaller as debug symbol packages disappear.
As noted, the dbgsym packages are published on ddebs.ubuntu.com. Ubuntu systems do not know this archive by default.
You can easily add it to your "software sources". For example, the following line adds ddebs.ubuntu.com for Quantal, main to your /etc/apt/sources.list file:
deb http://ddebs.ubuntu.com quantal main
sudo apt-get update, and you should be all set to go.
For example, check whether empathy-dbgsym is available for installation:
$ apt-cache policy empathy-dbgsym
*** 126.96.36.199-0ubuntu1 0
500 http://ddebs.ubuntu.com/ quantal/main amd64 Packages
500 http://ddebs.ubuntu.com/ quantal/main amd64 Packages
There it is! (I happen to have this one installed.)
How about the dbgsym version of empathy's binary package account-plugin-aim?
$ apt-cache policy account-plugin-aim-dbgsym
500 http://ddebs.ubuntu.com/ quantal/main amd64 Packages
There it is!
It appears that not all dbgsym binary packages that one might expect are actually present on ddebs.ubuntu.com.
For example, when I built empathy on a Quantal amd64 system with pgk-create-dbgsym installed, the expected dbgsym binary packages were created, including, for example, one for the account-plugin-irc binary package, and here it is:
But, I don't see a dbgsym package for account-plugin-irc published in the Ubuntu ddebs quantal main archive. The same is true for some (but by no means all) other binary packages deriving from empathy, like account-plugin-icq-dbgsym
This would seem to be a hiccup in the publishing part of the automation, not the dbgsym generation part.
 Debug symbols fill in stack traces to make them more human readable by substituting C function names and C source code file name for question marks and library file names. See apport-valgrind for details.
 You can display a package Description for any package your system's apt knows about with
apt-cache show PACKAGE, and look for the Description field.
 Conflicting with the dbg package(s), an example using account-plugin-aim as an example:
The empathy source package has the accounts-plugin-aim binary package. It installs the following file: /usr/lib/libaccount-plugin-1.0/providers/libaim.so (as shown by dpkg -S /usr/lib/libaccount-plugin-1.0/providers/libaim.so).
The empathy-dbg package installs a debug symbol version of this file in a debug directory: /usr/lib/debug/usr/lib/libaccount-plugin-1.0/providers/libaim.so. There is no conflict yet, since the paths are different.
The automatically generated dbgsym packages for empathy include account-plugin-aim-dbgsym. This package installs the same debug .so file as we saw for the empathy-dbg package: /usr/lib/debug/usr/lib/libaccount-plugin-1.0/providers/libaim.so.
That's a conflict. Two packages (empathy-dbg and account-plugin-aim-dbgsym) install the same file.
This is expected and handled by making the dbgysm binary packages conflict with the dbg package (if any), which it does:
$ apt-cache show account-plugin-aim-dbgsym | grep Conflicts
 With pkg-create-dbgsym installed, building empathy creates all these debs and dbgsym/ddebs: