Fedora includes a special type of rpms called debuginfo rpms. These automatically created rpms contains the debugging information from the program files, but moved into an external file. All the tools that handle debugging information knows how to automatically look in these files. This lets you easily install debugging information when you need it. You must install the exact matching version and architecture of debuginfo as the application you are trying to debug.

Fedora includes a special type of rpms called debuginfo rpms. These automatically created rpms contains the debugging information from the program files, but moved into an external file. All the tools that handle debugging information knows how to automatically look in these files. This lets you easily install debugging information when you need it. You must install the exact matching version and architecture of debuginfo as the application you are trying to debug.

Revision as of 14:29, 15 January 2010

A stack trace is one of the most important pieces of information you can provide to help others debug an application crash. This page details the importance of stack traces and outlines several methods for obtaining stack traces.

If you are experiencing a crash, the basic steps to generating a useful stack trace for common Gnome desktop applications are:

What is a stack trace (backtrace)?

A stack trace (sometimes also called a backtrace) is a list of function calls that leads to some point in the program. Debugging tools like gdb or bug-buddy can get stack traces from crashed applications so that developers can figure out what went wrong.

Notice the filenames and line numbers of where the functions are called appearing.

What are debugging symbols, and why are they important?

When a program is compiled with special switches to generate debugging symbols (the -g compiler switch) extra information is stored in the program file. This information can be used to generate a stack trace that contains much more information, such as the exact line number of the source file where things went wrong. Without this information it is very hard to figure out what went wrong by looking at the stack trace.

What are debuginfo rpms, and how do I get them?

Fedora includes a special type of rpms called debuginfo rpms. These automatically created rpms contains the debugging information from the program files, but moved into an external file. All the tools that handle debugging information knows how to automatically look in these files. This lets you easily install debugging information when you need it. You must install the exact matching version and architecture of debuginfo as the application you are trying to debug.

Packagers

How do I generate a backtrace?

First make sure that you have installed the debuginfo packages for the application you are debugging and all related libraries. A developer often tells you to install specific debuginfo packages because he can tell from a stack trace which libraries are involved in the crash. See below for recommended packages for some common type of applications.

Obtaining a stack trace using just GDB

NOTE: If you are running a Java program such as Eclipse or Tomcat, the situation is a bit more complicated - see JavaStackTraces for details.

First, run the following command to start gdb:

gdb name-of-program

Where name-of-program is the name of the program that crashed (for example: /usr/bin/gnome-panel).

Then, at the gdb prompt, type:

run

If you need to give any arguments to the program, give them after the run command, like:

run --argument

Once the program is running, reproduce the crash and go back to the terminal where you ran gdb. The gdb prompt should be shown - if not, hit Control+C to break into the debugger. At the gdb debugger prompt, type:

thread apply all bt

If that does not work (meaning that you don't get any output--this may be the case in programs which are not multi-threaded), type bt instead. If you still do not have any output, read this note about obtaining a stack trace under special circumstances. The output is the stack trace. Cut and paste all of it into a text file.

You can quit gdb by typing quit.

Obtaining a stack trace from a core dump

If the program that crashes leaves a core dump, you can use GDB to obtain a stack trace. Core dumps are saved in a file on your hard disk and are usually named something along the lines of "core" or "core.3124". To obtain a stack trace from one of these files, run the following command:

gdb name-of-program core-file-name

Where name-of-program is the name of the program that crashed (for example: /usr/bin/gnome-panel), and core-file-name is the name of the core file that contains the core dump (for example: core.7812).

Then, at the gdb prompt, type:

thread apply all bt full

If that does not work (meaning that you don't get any output--this may be the case in programs which are not multi-threaded), type bt instead. If you still do not have any output, read this note about obtaining a stack trace under special circumstances. The output is the stack trace. Cut and paste all of it into a text file.

You can quit gdb by typing quit.

Note that creation of core files is disabled in Fedora Core by default (in /etc/profile). To enable them for a shell session, type at the shell prompt:

ulimit -c unlimited

How to install ABRT

If you installed Fedora via a LiveCD image, ABRT should already be installed. You should be able to start it in Applications -> System Tools -> Automatic Bug Reporting Tool. If ABRT is not installed, for whatever reason, you can install it manually by doing the following on a command line:

su -c 'yum install abrt'

or go to System -> Administration -> Add/Remove Software in Gnome, and type "abrt" in the search box and hit Find. Select abrt and apply the changes.

Configuring ABRT for Bugzilla

Go to Application -> System Tools -> Automated Bug Reporting Tool and select it to start it manually. Once the gui window appears, choose Edit -> Plugins and from the Settings window, scroll down, highlight Bugzilla and choose "Configure Plugin". The Bugzilla URL should be https://bugzilla.redhat.com and enter your own Bugzilla login and password in the proper boxes. (NOTE: if you do not yet have a Bugzilla account, now is the time to get one, just go to the URL as displayed on that page and create a new account.) https://bugzilla.redhat.com/createaccount.cgi

Next time you have a program crash, and ABRT triggers, when you hit Report, ABRT will be able to automatically log in to Bugzilla and submit a Bug Report for you.

Using ABRT

(The following assumes Gnome as the desktop ... someone else will have to update for KDE/Others)

If ABRT detects a crashed program, you will get an ABRT alert. This will be visually indicated by a flashing red light in the system tray. Left click on the alert light, and the Automatic Bug Reporting Tool should start, displaying all of the crashes it has registered. To report the bug, right click on it and choose report. ABRT will gather the logs it needs to submit with the bug and will then let you know it is going to submit a bug on your behalf. If you have configured ABRT as in the previous section, it will then ask you to verify whether or not to include the various logs, then will automatically go out to Bugzilla and open a bug, attaching the logs into the bug. It will then show you the bug number so that you can track the bug as it is worked on.

Configuring ABRT when missing Debuginfos

When you right click on a bug in ABRT and choose Report, ABRT will attempt to go out and retrieve the logs it will need to send as part of the bug report. The developers have added code to detect whether or not symbolic traces are included within the backtrace, and if it detects that there are none, ABRT will alert you of this, and will show you the command to run. This is the same as what is shown in the debuginfo section.

How to install Bug Buddy

Run the following on the command line:

su -c 'yum install bug-buddy'

or go to System -> Administration -> Add/Remove Software in Gnome, and type "bug-buddy" in the search box and hit Find. Select bug-buddy and apply the changes.

Obtaining a stack trace from a Gnome application using Bug Buddy

Gnome applications use a program called bug-buddy to let you submit bug reports. The bug reports submitted by it normally go to the upstream bugtracking system, but you can also use it to just extract a stack trace.

When bug-buddy is installed, and an application which uses it crashes you will get a dialog saying The Application "application" has quit unexpectedly. You can then press the Inform Developers button, which will bring up bug-buddy. It will show a dialog where it says its collecting debug info, with a button that says Show Debugging Details. If you press this button it will show you the stack trace of the crash, and lets you copy or save the text so that you can submit it to a bug report.

When you are done with bug-buddy you can just press the Cancel button to quit without reporting a bug.

Obtaining a stack trace from a Gnome application using both Bug Buddy and GDB

This starts similarly to the normal bug-buddy approach , but when you get the initial crash dialog you don't do anything with that window. Instead you open a terminal and start gdb by typing:

gdb name-of-program process-number

Where name-of-program is the name of the program that crashed along with the full path to where it is located (for example: /usr/bin/gnome-panel ; if you don't know the full path you can use which gnome-panel--but be sure to include the backward quote marks), and process-number is the process number of the application that crashed, which can be found using the ps command.

Normally bug-buddy does a good job of collecting the stack trace, but in some cases the developer might want some extra information from gdb. In that case he will give some extra commands to be typed into gdb. In that case this method of starting gdb is very useful.

Special cases

Programs running as another user

If you do not get any output from gdb after typing thread apply all bt or bt, it may be because the program is run as root or as another user. In GNOME for example, this is the case when running gnome-games. In such cases, you will need to be root in order to capture a trace. So, quit gdb, login as root, and then repeat the steps to obtain a stack trace.

Firefox

Run "firefox -g" on the command line. That will start firefox running inside of gdb debugger.

In gdb, issue the command "run".

Do whatever is necessary to make firefox crash and follow the instructions above for gdb usage.

Java programs

See JavaStackTraces for info on getting stack traces from programs running in Java.

Daemons and their spawn

You will need to gather the backtrace from the core file.

Make sure your daemon's initscript isn't forbidding dumping core files to the disk. Add the line DAEMON_COREFILE_LIMIT=unlimited to its configuration file in /etc/sysconfig. For example, the Bluetooth daemon (hcid) uses /etc/sysconfig/bluetooth.

Then setup the kernel so that the core dump is written to a known location such as /tmp/. As root, run:

Finally, after reproducing your problem, you can double-check which binary created the core file with file /tmp/core.1234. Then run gdb on the file to create a post-mortem stack trace:

gdb /path/to/binary/file /tmp/core.1234

and follow the instructions above for gdb usage.

Note: you can test whether dumping a core file would work by running kill -SEGV 1234 where 1234 is the PID of the program you're testing.

Other tools

Valgrind

The brilliant tool valgrind is often able to say more about what is going wrong; it can give a strack trace to the point where things start to go wrong, which might be long time before the program actually crashes. Programs run through valgrind will run an order of magnitude slower and use more memory, but it will be amazingly usable.

With valgrind installed ("yum install valgrind") you can use it on a program:

valgrind name-of-program program-arguments

With debuginfo installed stacktraces will use symbolic names. See valgrind.org for more info and tips and tricks.

strace

strace can track all system calls made by a program, which can also be helpful in debugging, though it cannot produce stack traces. Install with "yum install strace", and see "man strace" for details.