Getting Stack Traces and Debugging Information on Gentoo

If you want to extract a useful debugging information from a crashing application do not try mistakenly to enable the “debug” USE flag in the corresponding ebuild. The “debug” USE flag is used for other purposes [1]. The proper way to do so, is mostly to enable the “-ggdb” compile flag and rebuild the application. In the case of “evince” the command line would be:

# CFLAGS="-march=native -pipe -O2 -ggdb" \
FEATURES="${FEATURES} splitdebug" emerge -1av evince

Luckily, there is no need to keep this in mind, because portage provides a possibility of configuration storing [2,3]. So the debugging configuration can be created once and used for all later purposes. To make use of it, create an “env” directory

# mkdir -p /etc/portage/env/

and put the above introduced debug setup in the file of your taste, like a “debug.conf”:

# cat /etc/portage/env/debug.conf
CFLAGS="-march=native -pipe -O2 -ggdb"
FEATURES="${FEATURES} splitdebug"

For now you can place all packages you would like to debug in the “package.env” file, using the following already similar to you syntax:

# cat /etc/portage/package.env
app-text/evince debug.conf
dev-libs/glib debug.conf
dev-libs/gtk+ debug.conf
# >gnome-base/nautilus-3.8.1 debug.conf

Rebuild the desired packages and you are ready for debugging:

# emerge -a1v evince glib gtk+

Obtaining stack traces is a straightforward process from this point, which mainly consists of issuing the following commands in order within gdb [1,4]:

$ gdb evince
GNU gdb (Gentoo 7.5.1 p2) 7.5.1

(gdb) run

(gdb) set logging file backtrace.log
(gdb) set logging on
Copying output to backtrace.log.

(gdb) thread apply all bt full

(gdb) set logging off
Done logging to backtrace.log.
(gdb) quit

Further resources:

  1. How to get meaningful backtraces in Gentoo
  2. Overriding environment variables per package
  3. /etc/portage/env
  4. Getting Traces in GNOME

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s