Monday, February 4, 2013

dbg versus dbgsym

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 [1] packages:
  • dbg packages, for example: empathy-dbg
  • dbgsym packages, for example: empathy-dbgsym
Being rather new to this area, I was not sure which to use. But, I wanted to valgrind empathy, so I looked further.

The package Description fields [2] shed no light on which to use:

empathy-dbg:
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_3.6.0.3-0ubuntu1_amd64.deb)
  • The packages on ddebs.ubuntu.com end in ".ddeb" (empathy-dbgsym_3.6.3-0ubuntu2_amd64.ddeb)
This ".ddeb" extension reminded me of ".udeb" packages, which I have encountered in the context of live-build installations. Are these dbgsym/ddeb packages also intended for some narrowly defined use case?

This warranted further poking around. Here are my findings.

dbg packages


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)
So let's take a moment to appreciate the work upstream maintainers have done!


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.

dbgsym packages


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?


Automation \o/


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:
  1. Creating the dbgsym binary packages (this part seems to be fully implemented)
  2. 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 [3] 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 debuild in 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 [4]. 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 
This all means that if you use dbgsym packages, your stack traces and debugging experiences are more likely to provide you the data you need to get your work done, with less bloat.

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.

Using dbgsym


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

Then run 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
empathy-dbgsym:
  Installed: 3.6.0.3-0ubuntu1
  Candidate: 3.6.0.3-0ubuntu1
  Version table:
 *** 3.6.0.3-0ubuntu1 0
        500 http://ddebs.ubuntu.com/ quantal/main amd64 Packages
        500 http://ddebs.ubuntu.com/ quantal/main amd64 Packages
        100 /var/lib/dpkg/status

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
account-plugin-aim-dbgsym:
  Installed: (none)
  Candidate: 3.6.0.3-0ubuntu1
  Version table:
     3.6.0.3-0ubuntu1 0
        500 http://ddebs.ubuntu.com/ quantal/main amd64 Packages

There it is!

A caveat


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:

account-plugin-irc-dbgsym_3.6.0.3-0ubuntu1_amd64.ddeb

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.

Footnotes


[1] 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.

[2] 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.

[3] 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
Conflicts: empathy-dbg 


[4] With pkg-create-dbgsym installed, building empathy creates all these debs and dbgsym/ddebs:

account-plugin-zephyr_3.6.0.3-0ubuntu1_amd64.deb
account-plugin-yahoojp_3.6.0.3-0ubuntu1_amd64.deb
account-plugin-yahoo_3.6.0.3-0ubuntu1_amd64.deb
account-plugin-sip_3.6.0.3-0ubuntu1_amd64.deb
account-plugin-sametime_3.6.0.3-0ubuntu1_amd64.deb
account-plugin-salut_3.6.0.3-0ubuntu1_amd64.deb
account-plugin-myspace_3.6.0.3-0ubuntu1_amd64.deb
account-plugin-mxit_3.6.0.3-0ubuntu1_amd64.deb
account-plugin-jabber_3.6.0.3-0ubuntu1_amd64.deb
account-plugin-irc_3.6.0.3-0ubuntu1_amd64.deb
account-plugin-icq_3.6.0.3-0ubuntu1_amd64.deb
account-plugin-groupwise_3.6.0.3-0ubuntu1_amd64.deb
account-plugin-gadugadu_3.6.0.3-0ubuntu1_amd64.deb
account-plugin-aim_3.6.0.3-0ubuntu1_amd64.deb
mcp-account-manager-uoa_3.6.0.3-0ubuntu1_amd64.deb
mcp-account-manager-goa_3.6.0.3-0ubuntu1_amd64.deb
nautilus-sendto-empathy_3.6.0.3-0ubuntu1_amd64.deb
empathy-dbg_3.6.0.3-0ubuntu1_amd64.deb
empathy_3.6.0.3-0ubuntu1_amd64.deb
account-plugin-zephyr-dbgsym_3.6.0.3-0ubuntu1_amd64.ddeb
account-plugin-yahoojp-dbgsym_3.6.0.3-0ubuntu1_amd64.ddeb
account-plugin-yahoo-dbgsym_3.6.0.3-0ubuntu1_amd64.ddeb
account-plugin-sip-dbgsym_3.6.0.3-0ubuntu1_amd64.ddeb
account-plugin-sametime-dbgsym_3.6.0.3-0ubuntu1_amd64.ddeb
account-plugin-salut-dbgsym_3.6.0.3-0ubuntu1_amd64.ddeb
account-plugin-myspace-dbgsym_3.6.0.3-0ubuntu1_amd64.ddeb
account-plugin-mxit-dbgsym_3.6.0.3-0ubuntu1_amd64.ddeb
account-plugin-jabber-dbgsym_3.6.0.3-0ubuntu1_amd64.ddeb
account-plugin-irc-dbgsym_3.6.0.3-0ubuntu1_amd64.ddeb
account-plugin-icq-dbgsym_3.6.0.3-0ubuntu1_amd64.ddeb
account-plugin-groupwise-dbgsym_3.6.0.3-0ubuntu1_amd64.ddeb
account-plugin-gadugadu-dbgsym_3.6.0.3-0ubuntu1_amd64.ddeb
account-plugin-aim-dbgsym_3.6.0.3-0ubuntu1_amd64.ddeb
mcp-account-manager-uoa-dbgsym_3.6.0.3-0ubuntu1_amd64.ddeb
mcp-account-manager-goa-dbgsym_3.6.0.3-0ubuntu1_amd64.ddeb
nautilus-sendto-empathy-dbgsym_3.6.0.3-0ubuntu1_amd64.ddeb
empathy-dbgsym_3.6.0.3-0ubuntu1_amd64.ddeb
empathy-common_3.6.0.3-0ubuntu1_all.deb

3 comments:

  1. To generate dbgsym packages do you need to modify the rules file at all?

    ReplyDelete
    Replies
    1. No need to modify the rules file. It is enough just to install pkg-create-dbgysm, then build the package as usual.

      Delete
  2. Another ddeb difference, although minor, is that dpkg won't tab complete a name that ends in .ddeb.

    ReplyDelete

Note: Only a member of this blog may post a comment.