MozillaZine

Getting a stacktrace with gdb

From MozillaZine Knowledge Base

Contents

Obtaining debugging symbols

In order for a stacktrace to be useful, you must have debugging symbols for Firefox. There are two ways to get debugging symbols:

  • build a debug build
  • install a debug package

If you're using a distro-provided version of Firefox, the easiest thing to do is to install a debug package. Most distros provide these and they're usually named "firefox-dbg" or "firefox-debug". Just search using your package manager until you find it.

The other option is to build a debug build of Firefox yourself. This is slightly more complicated and time consuming. You'll probably want to consult the build documentation if you plan on doing this.

Using gdb to get a stacktrace

gdb, the GNU Project Debugger, is a popular debugger that's available on most Unix-based OSes. gdb is a very powerful tool, but we'll just be using it to get a stacktrace for the crash.

In order to be able to "trap" Firefox in the debugger, you'll need to start Firefox in the following manner:

 firefox -g -d gdb

The -g flag tells Firefox to start in debugging mode, and the -d flag allows us to specifiy a debugger, which in this case is gdb.

This should start gdb and load the debugging symbols for Firefox. You now should be in gdb and should have the following in your terminal:

 (gdb)

Next we'll need to tell gdb to ignore real-time events (SIG33). This is done with the following command:

 handle SIG33 noprint nostop

Now we're really to start Firefox. This is done using the run command:

 run

After a few moments, Firefox should start. Now you should do what's needed to crash Firefox. Go to the website that's causing the crash, try and open a file, etc.

When you crash, Firefox should become unresponsive (it will still remain open, though). Now go back to the terminal and type:

 backtrace

This should print out a stacktrace for the crash. It only prints out ten lines at a time, so you'll probably need to hit enter a few times to get the full stack.

What to do with the stacktrace

Most of the time, stacktraces can be directly pasted in bug reports as a comment. If someone asks you explictly to attach the stacktrace to a bug, then you'll probably want to create a text file with the stacktrace in it, then attach it to the bug.

See Also

Talkback

External Links

gdb, the GNU Project Debugger