Debugging Mozilla with gdb

  • Revision slug: Debugging_Mozilla_with_gdb
  • Revision title: Debugging Mozilla with gdb
  • Revision id: 68153
  • Created:
  • Creator: jdm
  • Is current revision? No
  • Comment 7 words added

Revision Content

This page details some tricks that you can use to make it easier to debug Mozilla and to work around some of the problems that GDB has.

Make sure you have gdb 5 or higher.  You can get a more recent copy of GDB from the GDB site at sourceware.  If you have less than 256 MB of RAM, be sure to see Using gdb on wimpy computers.

Where can I find general gdb documentation?

Using GDB is well beyond the scope of this document. There is documentation available on your system if you have GDB installed in the form of info pages. You might want to use the gnome help browser to read that documentation as many people find the info reader on Linux hard to use. Additionally, you can use a graphical front end to GDB like ddd or insight. Here's a site that has more information:

How do I run Mozilla under gdb?

The mozilla script that is launches the browser can also be used to launch the debugger as well. You can use it like this:

$ cd mozilla/dist/bin
$ ./mozilla -g -d gdb

(You can leave off "-d gdb" if gdb is the default debugger in your distro.)

Or you can be sneaky:

$ ./run-mozilla.sh /bin/bash 
$ gdb mozilla-bin

Or simple:

$ export LD_LIBRARY_PATH=.
$ gdb mozilla-bin

How do I pass arguments over to the app using GDB/ddd?

You should now be able to convey arguments using ./mozilla -g your-list-of-arguments For example you can call the mozilla script like this if you want to launch mail at startup: ./mozilla -g -mail

How do I pass arguments in prun?

Set the arguments in GDB before calling prun. Here's an example on how to do that:

(gdb) set args http://www.mozilla.org
(gdb) prun

 

 

How do I set a breakpoint in a library that hasn't been loaded?

Since GDB 6.1, GDB has support for "pending breakpoints".  This is controlled by the "set breakpoint pending" setting, and is enabled by default.  What this means is that a breakpoint that cannot be immediately resolved will be re-checked each time a shared library is loaded by the process being debugged.  If your GDB is older than this, you should upgrade.

In older versions, there isn't a way to set a breakpoint in GDB in a library that hasn't been loaded. If you are actually intersted in setting a breakpoint in a real component when it's loaded please see the section on setting a breakpoint when a component is loaded. If you are completely desperate and have to set a breakpoint in a library when it's loaded you can set a breakpoint on the symbol _dl_open. This function is called when a new library is loaded. You can set your breakpoint after you see that your library has been loaded.

How do I set a breakpoint when a component is loaded?

There's a faculity in XPCOM that allows you to set an environment variable that triggers the program to drop into the debugger when it loads a certain component. You have to set the XPCOM_BREAK_ON_LOAD environment variable before you run Mozilla. You set the variable to a string that contains the names of libraries you might want to load. For example, if you wanted to stop when a library named raptor or necko is loaded, you can set the variable to raptor:necko. Here's an example:

(gdb) set env XPCOM_BREAK_ON_LOAD raptor:necko
(gdb) prun

I can't set a breakpoint. Why not?

You probably can't set a breakpoint because the library in which that breakpoint is located hasn't been loaded. If you know the library has actually been loaded into Mozilla but you can't set the breakpoint see the section on loading shared libraries. If the library hasn't been loaded yet you will have to wait until it is. If you want to set a breakpoint as soon as the library is loaded, see the section on breaking when a component is loaded and breaking on a library load.

How do I display PRUnichar's?

Several people have suggested ways to do this:

(gdb) print ((PRUnichar*)uri.mBuffer)[0]@16
$47 = {114, 100, 102, 58, 110, 117, 108, 108, 0, 0, 8, 0, 0, 0, 37432,
16514}
(gdb) print aURI
$1 = (const PRUnichar *) 0x855e6e0
(gdb) x/32ch aURI
0x855e6e0:      104 'h' 116 't' 116 't' 112 'p' 58 ':'  47 '/'  47 '/'  119 'w'
0x855e6f0:      119 'w' 119 'w' 46 '.'  109 'm' 111 'o' 122 'z' 105 'i' 108 'l'
0x855e700:      108 'l' 97 'a'  46 '.'  111 'o' 114 'r' 103 'g' 47 '/'  115 's'
0x855e710:      116 't' 97 'a'  114 'r' 116 't' 47 '/'  0 '\0'  25 '\031'       0 '\0'
(gdb)
  • Define helper functions in your .gdbinit
  # define "pu" command to display PRUnichar * strings (100 chars max)
  def pu
    set $uni = $arg0
    set $i = 0
    while (*$uni && $i++<100)
      if (*$uni < 0x80)
        printf "%c" *(char*)$uni++
      else
        printf "%xh" *(short*)$uni++
      end
    end
    printf "\n"
  end
  
  # define "ps" command to display nsString/nsAutoString/nsCString/nsCAutoString
  def ps
    set $ns = $arg0
    if ($ns->mCharSize)
      pu $ns->mUStr
    else
      print $ns->mStr
    end
  end  

This is hard. Give me a .gdbinit that already has the functions.

  • Define a small helper function "punichar" in #ifdef NS_DEBUG code somewhere.

How do I display an nsString?

You can call the ToNewCString() method on the nsString in question. It leaks a little memory but it shouldn't hurt anything if you only do it a few times in one gdb session. ( from akkana@netscape.com )

(gdb) p string.ToNewCString()

Another method (via bent) is the following (replace n with: the returned length of your string):

(gdb) p string.Length()
$1 = n
(gdb) x/ns string.BeginReading()

You can of course use any of the above unichar-printing routines instead of x/s.

This is hard. Give me a .gdbinit that works.

Ok. Here's one. It contains four function definitions.

  • "prun" to start the browser and disable library loading.
  • "pmail" which will launch mail.
  • "pu" which will display a (PRUnichar *) string.
  • "ps" which will display a nsString.

How do I determine the concrete type of an object pointed to by an interface pointer?

You can determine the concrete type of any object pointed to by an XPCOM interface pointer by looking at the mangled name of the symbol for the object's vtable:

(gdb) p aKidFrame
$1 = (nsIFrame *) 0x85058d4
(gdb) x/wa *(void**)aKidFrame
0x4210d380 <__vt_14nsRootBoxFrame>: 0x0
(gdb) p *(nsRootBoxFrame*)aKidFrame
 [ all the member variables of aKidFrame ]

(If you're using gcc 3.x, the output is slightly different from the above (which is for gcc 2.9x), but just pay attention to the vtable symbol (which in this case would be _ZTV14nsRootBoxFrame) rather than the mangled name of the first virtual function, since some classes may not override the first virtual function (although they usually do, since it's QueryInterface).) Note that you won't get anything useful if the shared library containing the implementation of the object you're looking at is not loaded. See "How do I load shared libraries?" and "How do I see what libraries I already have loaded?".

Or, just use the gdb command "set print object on".

How can I debug JavaScript from gdb?

If you find JavaScript Engine code on the stack, you'll probably want to get a JS stack in addition to a C++ stack.

(gbd) call DumpJSStack() 

See http://www.mozilla.org/scriptable/javascript-stack-dumper.html for more JS debugging tricks.

How can I debug race conditions and/or how can I make something different happen at NS_ASSERTION time?

{{ mediawiki.external('submitted by Dan Mosedale') }}
Since Linux is unable to generate useful core files for multi-threaded applications, tracking down race-conditions that don't show up under the debugger can be a bit tricky. Unless you've given the --enable-crash-on-assert switch to configure, you can now change the behavior of NS_ASSERTION (actually nsDebug::Break) using the XPCOM_DEBUG_BREAK environment variable.  See the corresponding article for details on its possible values.

How do I run the debugger in emacs/xemacs?

Emacs and XEmacs contain modes for doing visual debugging that many programmers use. However, you might want to set up environment variables to make sure that when running the debugger and Mozilla they know where to load symbols from and where to find components. The easiest way to set up those environment variables is to use the run-mozilla.sh script that's in the dist/bin directory of your build. This script will set up the environment that you need to run the editor, shell or debugger. Another trick is to use the script to run /bin/bash ( or your favorite shell ) to set up a shell that has the right setup and then you can run any commands you want inside it.

[blizzard@gunhead bin]$ ./run-mozilla.sh /bin/bash
MOZILLA_FIVE_HOME=/home/blizzard/src/mozilla/build/dist/bin
  LD_LIBRARY_PATH=/home/blizzard/src/mozilla/build/dist/bin
     LIBRARY_PATH=/home/blizzard/src/mozilla/build/dist/bin
       SHLIB_PATH=/home/blizzard/src/mozilla/build/dist/bin
          LIBPATH=/home/blizzard/src/mozilla/build/dist/bin
       ADDON_PATH=/home/blizzard/src/mozilla/build/dist/bin
      MOZ_PROGRAM=/bin/bash
      MOZ_TOOLKIT=
        moz_debug=0
     moz_debugger=
[blizzard@gunhead bin]$

gdb 5 used to work for me, but now Mozilla won't start. What can I do?

A recent threading change (see bug 57051 for details) caused a problem on some systems: Mozilla would get partway through its initialization, then die before showing a window. A recent change to gdb has fixed this problem. Download and build [ http://sources.redhat.com/insight/ the latest version of Insight], or if you don't want a GUI, the latest version of gdb.

"run" or "prun" in GDB fails with "error in loading shared libraries."

Attempting to run mozilla-bin inside GDB fails with an error message similar to the following:

Starting program:
/u/dmose/s/mozilla/mozilla-all/mozilla/dist/bin/./mozilla-bin
/u/dmose/s/mozilla/mozilla-all/mozilla/dist/bin/./mozilla-bin: error
in loading shared libraries: libraptorgfx.so: cannot open shared
object file: No such file or directory

Your LD_LIBRARY_PATH is probably being reset by your .cshrc or .profile. From the GDB manual: *Warning:* GDB runs your program using the shell indicated by your 'SHELL' environment variable if it exists (or '/bin/sh' if not). If your 'SHELL' variable names a shell that runs an initialization file -- such as '.cshrc' for C-shell, or '.bashrc' for BASH--any variables you set in that file affect your program. You may wish to move setting of environment variables to files that are only run when you sign on, such as '.login' or '.profile'.

Debian's GDB doesn't work. What do I do?

[submitted by Bruce Mitchener]
Debian's unstable distribution currently uses glibc 2.1 and GDB 4.18. However, there is no package of GDB for Debian with the appropriate threads patches that will work with glibc 2.1. I was able to get this to work by getting the GDB 4.18 RPM from Red Hat's rawhide server and installing that. It has all of the patches necessary for debugging threaded software. These fixes are expected to be merged into GDB, which will fix the problem for Debian Linux.

Mozilla is aborting. Where do I set a breakpoint to find out where it is exiting?

On Linux there are two possible symbols that are causing this. They are PR_ASSERT() and NS_ASSERTION(). To catch the program before it exits to see where it's asserting you can stop at two places:

(gdb) b abort
(gdb) b exit

I keep getting a SIG32 in the debugger. How do I fix it?

If you are getting a SIG32 while trying to debug Mozilla you might have turned off shared library loading before the pthreads library was loaded, e.g. by having set auto-solib-add 0 in your .gdbinit file. In this case you can either:

  • Remove it and use the method explained in the section about GDB's memory usage instead.
  • Use handle SIG32 noprint either in gdb or in your .gdbinit file.

Alternatively the problem might lie in your pthread library. If this library has its symbols stripped, then GDB can't hook into thread events, and you end up with SIG32 signals. You can check if your libpthread is stripped by checking the output of file /lib/libpthread* for 'stripped'. To fix this problem for Gentoo Linux, you can re-emerge glibc after adding "nostrip" to your FEATURES in /etc/make.conf.

How do I get useful stack traces inside system libraries?

Many Linux distributions provide separate packages with debugging information for system libraries that you can install if you want gdb, valgrind, profiling tools, etc., to give useful stack traces for stacks that go through system libraries.

Fedora

On Fedora, you need to enable the debuginfo repositories, since the packages with debug symbols are provided in separate repositories. It is best to enable them permanently, since then you'll get the updates to the debug symbols when you get security updates for the packages. The best way I know to do this is simply to edit /etc/yum.repos.d/fedora.repo and fedora-updates.repo to change the enabled=0 line in the debuginfo section to enabled=1. Doing this will require dealing with the conflict (and redoing the change, I think) when upgrading to a new distribution version.

Once you do this, you can install debuginfo packages with yum or other package management tools. The best way to do this is to install the yum-utils package and then use the debuginfo-install command to install all the debuginfo:

# yum install yum-utils
# debuginfo-install firefox 

Installing a roughly complete set for debugging Mozilla can be done manually using:

 # yum install GConf2-debuginfo ORBit2-debuginfo atk-debuginfo \
 cairo-debuginfo dbus-debuginfo dbus-glib-debuginfo expat-debuginfo \
 fontconfig-debuginfo freetype-debuginfo gcc-debuginfo glib2-debuginfo \
 glibc-debuginfo gnome-vfs2-debuginfo gtk2-debuginfo gtk2-engines-debuginfo \
 hal-debuginfo libX11-debuginfo libXcursor-debuginfo libXext-debuginfo \
 libXfixes-debuginfo libXft-debuginfo libXi-debuginfo libXinerama-debuginfo \
 libXrender-debuginfo libbonobo-debuginfo libgnome-debuginfo \
 libselinux-debuginfo pango-debuginfo popt-debuginfo scim-bridge-debuginfo

Ubuntu 8.04

Ubuntu provides similar debug symbol packages for many of its libraries (although not all of them). To install them, simply run (to get a reasonably large set):

 $ sudo apt-get install libatk1.0-dbg libc6-dbg libcairo2-dbg \
 libfontconfig1-dbg libgcc1-dbg libglib2.0-0-dbg libgnomeui-0-dbg \
 libgnomevfs2-0-dbg libgnutls13-dbg libgtk2.0-0-dbg libice6-dbg \
 libjpeg62-dbg libpango1.0-0-dbg libpixman-1-0-dbg libstdc++6-4.2-dbg \
 libx11-6-dbg libx11-xcb1-dbg libxcb1-dbg libxft2-dbg zlib1g-dbg

 See also

Original Document Information

Revision Source

<p>This page details some tricks that you can use to make it easier to debug Mozilla and to work around some of the problems that GDB has.</p>
<p>Make sure you have gdb 5 or higher.  You can get a more recent copy of GDB from the <a class="external" href="http://sourceware.org/gdb/" title="http://sourceware.org/gdb/">GDB site at sourceware</a>.  If you have less than 256 MB of RAM, be sure to see <a class="internal" href="/en/Using_gdb_on_wimpy_computers" title="en/Using gdb on wimpy computers">Using gdb on wimpy computers</a>.</p>
<h3>Where can I find general gdb documentation?</h3>
<p><em>Using </em>GDB is well beyond the scope of this document. There is documentation available on your system if you have GDB installed in the form of info pages. You might want to use the gnome help browser to read that documentation as many people find the info reader on Linux hard to use. Additionally, you can use a graphical front end to GDB like <a class="external" href="http://www.gnu.org/software/ddd/">ddd</a> or <a class="external" href="http://sourceware.org/insight/" title="http://sourceware.org/insight/">insight</a>. Here's a site that has more information:</p>
<dl> <dd> <ul> <li><a class=" external" href="http://sourceware.org/gdb/current/onlinedocs/gdb/" title="http://sourceware.org/gdb/current/onlinedocs/gdb/">http://sourceware.org/gdb/current/onlinedocs/gdb/</a></li> </ul> </dd>
</dl>
<h3 name="How_do_I_debug_Mozilla_on_Linux.3F">How do I run Mozilla under gdb?</h3>
<p>The <code>mozilla</code> script that is launches the browser can also be used to launch the debugger as well. You can use it like this:</p>
<pre class="eval">$ cd mozilla/dist/bin
$ ./mozilla -g -d gdb
</pre>
<p>(You can leave off "-d gdb" if gdb is the default debugger in your distro.)</p>
<p>Or you can be sneaky:</p>
<pre class="eval">$ ./run-mozilla.sh /bin/bash 
$ gdb mozilla-bin</pre>
<p>Or simple:</p>
<pre class="eval">$ export LD_LIBRARY_PATH=.
$ gdb mozilla-bin</pre>
<h3 name="How_do_I_pass_arguments_over_to_the_app_using_GDB.2Fddd.3F">How do I pass arguments over to the app using GDB/ddd?</h3>
<p>You should now be able to convey arguments using ./mozilla -g your-list-of-arguments For example you can call the mozilla script like this if you want to launch mail at startup: ./mozilla -g -mail</p>
<h3 name="How_do_I_pass_arguments_in_prun.3F">How do I pass arguments in prun?</h3>
<p>Set the arguments in GDB before calling prun. Here's an example on how to do that:</p>
<pre class="eval">(gdb) <strong>set args <a class=" external" href="http://www.mozilla.org" rel="freelink">http://www.mozilla.org</a></strong>
(gdb) <strong>prun</strong>

</pre>
<p> </p>
<p> </p>
<h3 name="How_do_I_set_a_breakpoint_in_a_library_that_hasn.27t_been_loaded.3F">How do I set a breakpoint in a library that hasn't been loaded?</h3>
<p>Since GDB 6.1, GDB has support for "pending breakpoints".  This is controlled by the "<code>set breakpoint pending</code>" setting, and is enabled by default.  What this means is that a breakpoint that cannot be immediately resolved will be re-checked each time a shared library is loaded by the process being debugged.  If your GDB is older than this, you should upgrade.</p>
<p>In older versions, there isn't a way to set a breakpoint in GDB in a library that hasn't been loaded. If you are actually intersted in setting a breakpoint in a real component when it's loaded please see the section on <a href="#How_do_I_set_a_breakpoint_when_a_component_is_loaded.3F">setting a breakpoint when a component is loaded</a>. If you are completely desperate and have to set a breakpoint in a library when it's loaded you can set a breakpoint on the symbol <code>_dl_open</code>. This function is called when a new library is loaded. You can set your breakpoint after you see that your library has been loaded.</p><h3 name="How_do_I_set_a_breakpoint_when_a_component_is_loaded.3F">How do I set a breakpoint when a component is loaded?</h3>
<p>There's a faculity in XPCOM that allows you to set an environment variable that triggers the program to drop into the debugger when it loads a certain component. You have to set the <code>XPCOM_BREAK_ON_LOAD</code> environment variable before you run Mozilla. You set the variable to a string that contains the names of libraries you might want to load. For example, if you wanted to stop when a library named <code>raptor</code> or <code>necko</code> is loaded, you can set the variable to <code>raptor:necko</code>. Here's an example:</p>
<pre class="eval">(gdb) set env XPCOM_BREAK_ON_LOAD raptor:necko
(gdb) prun</pre>
<h3>I can't set a breakpoint. Why not?</h3>
<p>You probably can't set a breakpoint because the library in which that breakpoint is located hasn't been loaded. If you know the library has actually been loaded into Mozilla but you can't set the breakpoint see the section on <a href="#How_do_I_load_shared_libraries.3F">loading shared libraries</a>. If the library hasn't been loaded yet you will have to wait until it is. If you want to set a breakpoint as soon as the library is loaded, see the section on <a href="#How_do_I_set_a_breakpoint_when_a_component_is_loaded.3F">breaking when a component is loaded</a> and <a href="#How_do_I_set_a_breakpoint_when_a_component_is_loaded.3F">breaking on a library load</a>.</p>
<h3 name="How_do_I_display_PRUnichar.27s.3F">How do I display PRUnichar's?</h3>
<p>Several people have suggested ways to do this:</p>
<pre class="eval">(gdb) <strong>print ((PRUnichar*)uri.mBuffer)[0]@16</strong>
$47 = {114, 100, 102, 58, 110, 117, 108, 108, 0, 0, 8, 0, 0, 0, 37432,
16514}
</pre>
<dl> <dd>
</dd></dl>
<pre class="eval">(gdb) <strong>print aURI</strong>
$1 = (const PRUnichar *) 0x855e6e0
(gdb) <strong>x/32ch aURI</strong>
0x855e6e0:      104 'h' 116 't' 116 't' 112 'p' 58 ':'  47 '/'  47 '/'  119 'w'
0x855e6f0:      119 'w' 119 'w' 46 '.'  109 'm' 111 'o' 122 'z' 105 'i' 108 'l'
0x855e700:      108 'l' 97 'a'  46 '.'  111 'o' 114 'r' 103 'g' 47 '/'  115 's'
0x855e710:      116 't' 97 'a'  114 'r' 116 't' 47 '/'  0 '\0'  25 '\031'       0 '\0'
(gdb)
</pre>
<dl> <dd> <ul> <li>Define helper functions in your .gdbinit</li> </ul> </dd>
</dl>
<pre class="brush: text">  # define "pu" command to display PRUnichar * strings (100 chars max)
  def pu
    set $uni = $arg0
    set $i = 0
    while (*$uni &amp;&amp; $i++&lt;100)
      if (*$uni &lt; 0x80)
        printf "%c" *(char*)$uni++
      else
        printf "%xh" *(short*)$uni++
      end
    end
    printf "\n"
  end
  
  # define "ps" command to display nsString/nsAutoString/nsCString/nsCAutoString
  def ps
    set $ns = $arg0
    if ($ns-&gt;mCharSize)
      pu $ns-&gt;mUStr
    else
      print $ns-&gt;mStr
    end
  end  
</pre>
<p><a href="#This_is_hard._Give_me_a_.gdbinit_that_works.">This is hard. Give me a .gdbinit that already has the functions.</a></p>
<dl> <dd> <ul> <li>Define a small helper function "punichar" in #ifdef NS_DEBUG code somewhere.</li> </ul> </dd>
</dl><h3 name="How_do_I_display_an_nsString.3F">How do I display an nsString?</h3>
<p>You can call the ToNewCString() method on the nsString in question. It leaks a little memory but it shouldn't hurt anything if you only do it a few times in one gdb session. ( from <a class=" link-mailto" href="mailto:akkana@netscape.com" rel="freelink">akkana@netscape.com</a> )</p>
<pre class="eval">(gdb) p string.ToNewCString()
</pre>
<p>Another method (via bent) is the following (replace <code>n</code> with: the returned length of your string):</p>
<pre>(gdb) p string.Length()
$1 = n
(gdb) x/ns string.BeginReading()
</pre>
<p>You can of course use any of the above unichar-printing routines instead of x/s.</p>
<h3 name="This_is_hard._Give_me_a_.gdbinit_that_works.">This is hard. Give me a .gdbinit that works.</h3>
<p>Ok. <a class="external" href="http://www.mozilla.org/unix/.gdbinit">Here's one.</a> It contains four function definitions.</p>
<dl> <dd> <ul> <li>"prun" to start the browser and disable library loading.</li> <li>"pmail" which will launch mail.</li> <li>"pu" which will display a (PRUnichar *) string.</li> <li>"ps" which will display a nsString.</li> </ul> </dd>
</dl>
<h3 name="How_do_I_determine_the_concrete_type_of_an_object_pointed_to_by_an_interface_pointer.3F">How do I determine the concrete type of an object pointed to by an interface pointer?</h3>
<p>You can determine the concrete type of any object pointed to by an XPCOM interface pointer by looking at the mangled name of the symbol for the object's vtable:</p>
<pre class="eval">(gdb) <strong>p aKidFrame</strong>
$1 = (nsIFrame *) 0x85058d4
(gdb) <strong>x/wa *(void**)aKidFrame</strong>
0x4210d380 &lt;__vt_14<strong>nsRootBoxFrame</strong>&gt;: 0x0
(gdb) <strong>p *(nsRootBoxFrame*)aKidFrame</strong>
 <var>[ all the member variables of aKidFrame ]</var>
</pre>
<p>(If you're using gcc 3.x, the output is slightly different from the above (which is for gcc 2.9x), but just pay attention to the vtable symbol (which in this case would be <code>_ZTV14nsRootBoxFrame</code>) rather than the mangled name of the first virtual function, since some classes may not override the first virtual function (although they usually do, since it's <code>QueryInterface</code>).) Note that you won't get anything useful if the shared library containing the implementation of the object you're looking at is not loaded. See "<a href="#How_do_I_load_shared_libraries.3F">How do I load shared libraries?</a>" and "<a href="#How_do_I_see_what_libraries_I_already_have_loaded.3F">How do I see what libraries I already have loaded?</a>".</p>
<p>Or, just use the gdb command "set print object on".</p>
<h3 name=".22run.22_or_.22prun.22_in_GDB_fails_with_.22error_in_loading_shared_libraries..22">How can I debug JavaScript from gdb?</h3>
<p>If you find JavaScript Engine code on the stack, you'll probably want to get a JS stack in addition to a C++ stack.</p>
<pre>(gbd) <strong>call DumpJSStack() </strong></pre>
<p>See <a class="external" href="http://www.mozilla.org/scriptable/javascript-stack-dumper.html" title="http://www.mozilla.org/scriptable/javascript-stack-dumper.html">http://www.mozilla.org/scriptable/javascript-stack-dumper.html</a> for more JS debugging tricks.</p>
<h3 name="How_can_I_debug_race_conditions_and.2For_how_can_I_make_something_different_happen_at_NS_ASSERTION_time.3F">How can I debug race conditions and/or how can I make something different happen at NS_ASSERTION time?</h3>
<p>{{ mediawiki.external('submitted by Dan Mosedale') }}<br>
Since Linux is unable to generate useful core files for multi-threaded applications, tracking down race-conditions that don't show up under the debugger can be a bit tricky. Unless you've given the <code>--enable-crash-on-assert</code> switch to <code>configure</code>, you can now change the behavior of <code>NS_ASSERTION</code> (actually nsDebug::Break) using the <code><a class="internal" href="/en/XPCOM_DEBUG_BREAK" title="en/XPCOM DEBUG BREAK">XPCOM_DEBUG_BREAK</a></code> environment variable.  See the corresponding article for details on its possible values.</p>
<h3>How do I run the debugger in emacs/xemacs?</h3>
<p>Emacs and XEmacs contain modes for doing visual debugging that many programmers use. However, you might want to set up environment variables to make sure that when running the debugger and Mozilla they know where to load symbols from and where to find components. The easiest way to set up those environment variables is to use the <code>run-mozilla.sh</code> script that's in the dist/bin directory of your build. This script will set up the environment that you need to run the editor, shell or debugger. Another trick is to use the script to run /bin/bash ( or your favorite shell ) to set up a shell that has the right setup and then you can run any commands you want inside it.</p>
<pre class="eval">[blizzard@gunhead bin]$ <strong>./run-mozilla.sh /bin/bash</strong>
MOZILLA_FIVE_HOME=/home/blizzard/src/mozilla/build/dist/bin
  LD_LIBRARY_PATH=/home/blizzard/src/mozilla/build/dist/bin
     LIBRARY_PATH=/home/blizzard/src/mozilla/build/dist/bin
       SHLIB_PATH=/home/blizzard/src/mozilla/build/dist/bin
          LIBPATH=/home/blizzard/src/mozilla/build/dist/bin
       ADDON_PATH=/home/blizzard/src/mozilla/build/dist/bin
      MOZ_PROGRAM=/bin/bash
      MOZ_TOOLKIT=
        moz_debug=0
     moz_debugger=
[blizzard@gunhead bin]$
</pre>
<h3>gdb 5 used to work for me, but now Mozilla won't start. What can I do?</h3>
<p>A recent threading change (see <a class="external" href="http://bugzilla.mozilla.org/show_bug.cgi?id=57051">bug 57051</a> for details) caused a problem on some systems: Mozilla would get partway through its initialization, then die before showing a window. A recent change to gdb has fixed this problem. Download and build [ <a class=" external" href="http://sources.redhat.com/insight/" rel="freelink">http://sources.redhat.com/insight/</a> the latest version of Insight], or if you don't want a GUI, <a class="external" href="http://sources.redhat.com/gdb/">the latest version of gdb</a>.</p>
<h3 name=".22run.22_or_.22prun.22_in_GDB_fails_with_.22error_in_loading_shared_libraries..22">"run" or "prun" in GDB fails with "error in loading shared libraries."</h3>
<p>Attempting to run mozilla-bin inside GDB fails with an error message similar to the following:</p>
<pre class="eval">Starting program:
/u/dmose/s/mozilla/mozilla-all/mozilla/dist/bin/./mozilla-bin
/u/dmose/s/mozilla/mozilla-all/mozilla/dist/bin/./mozilla-bin: error
in loading shared libraries: libraptorgfx.so: cannot open shared
object file: No such file or directory
</pre>
<p>Your LD_LIBRARY_PATH is probably being reset by your .cshrc or .profile. From the GDB manual: <em><span class="nowiki">*Warning:* GDB runs your program using the shell indicated by your 'SHELL' environment variable if it exists (or '/bin/sh' if not). If your 'SHELL' variable names a shell that runs an initialization file -- such as '.cshrc' for C-shell, or '.bashrc' for BASH--any variables you set in that file affect your program. You may wish to move setting of environment variables to files that are only run when you sign on, such as '.login' or '.profile'.</span></em></p>
<h3 name="Debian.27s_GDB_doesn.27t_work._What_do_I_do.3F">Debian's GDB doesn't work. What do I do?</h3>
<p>[submitted by <a class="link-mailto" href="mailto:bruce@cybersight.com">Bruce Mitchener</a>]<br>
Debian's unstable distribution currently uses glibc 2.1 and GDB 4.18. However, there is no package of GDB for Debian with the appropriate threads patches that will work with glibc 2.1. I was able to get this to work by getting the GDB 4.18 RPM from Red Hat's rawhide server and installing that. It has all of the patches necessary for debugging threaded software. These fixes are expected to be merged into GDB, which will fix the problem for Debian Linux.</p>
<h3 name="Mozilla_is_aborting._Where_do_I_set_a_breakpoint_to_find_out_where_it_is_exiting.3F">Mozilla is aborting. Where do I set a breakpoint to find out where it is exiting?</h3>
<p>On Linux there are two possible symbols that are causing this. They are <code>PR_ASSERT()</code> and <code>NS_ASSERTION()</code>. To catch the program before it exits to see where it's asserting you can stop at two places:</p>
<pre class="eval">(gdb) <strong>b abort</strong>
(gdb) <strong>b exit</strong>
</pre>
<h3 name="I_keep_getting_a_SIG32_in_the_debugger._How_do_I_fix_it.3F">I keep getting a SIG32 in the debugger. How do I fix it?</h3>
<p>If you are getting a SIG32 while trying to debug Mozilla you might have turned off shared library loading before the pthreads library was loaded, e.g. by having <code>set auto-solib-add 0</code> in your <code>.gdbinit</code> file. In this case you can either:</p>
<dl> <dd> <ul> <li>Remove it and use the method explained in the section about <a href="#The_debugger_uses_a_lot_of_memory._How_do_I_fix_it.3F">GDB's memory usage</a> instead.</li> <li>Use <code>handle SIG32 noprint</code> either in gdb or in your <code>.gdbinit</code> file.</li> </ul> </dd>
</dl>
<p>Alternatively the problem might lie in your pthread library. If this library has its symbols stripped, then GDB can't hook into thread events, and you end up with SIG32 signals. You can check if your libpthread is stripped by checking the output of <code>file /lib/libpthread*</code> for <code>'stripped'.</code> To fix this problem for Gentoo Linux, you can re-emerge glibc after adding <code>"nostrip"</code> to your <code>FEATURES</code> in <code>/etc/make.conf</code>.</p>
<h3 name="How_do_I_get_useful_stack_traces_inside_system_libraries.3F">How do I get useful stack traces inside system libraries?</h3>
<p>Many Linux distributions provide separate packages with debugging information for system libraries that you can install if you want gdb, valgrind, profiling tools, etc., to give useful stack traces for stacks that go through system libraries.</p>
<h4 name="Fedora_8">Fedora</h4>
<p>On Fedora, you need to enable the debuginfo repositories, since the packages with debug symbols are provided in separate repositories. It is best to enable them permanently, since then you'll get the updates to the debug symbols when you get security updates for the packages. The best way I know to do this is simply to edit <code>/etc/yum.repos.d/fedora.repo</code> and <code>fedora-updates.repo</code> to change the <code>enabled=0</code> line in the debuginfo section to <code>enabled=1</code>. Doing this will require dealing with the conflict (and redoing the change, I think) when upgrading to a new distribution version.</p>
<p>Once you do this, you can install debuginfo packages with yum or other package management tools. The best way to do this is to install the <code>yum-utils</code> package and then use the <code>debuginfo-install</code> command to install all the debuginfo:</p>
<pre># yum install yum-utils
# debuginfo-install firefox 
</pre>
<p>Installing a roughly complete set for debugging Mozilla can be done manually using:</p>
<pre class="eval"> # yum install GConf2-debuginfo ORBit2-debuginfo atk-debuginfo \
 cairo-debuginfo dbus-debuginfo dbus-glib-debuginfo expat-debuginfo \
 fontconfig-debuginfo freetype-debuginfo gcc-debuginfo glib2-debuginfo \
 glibc-debuginfo gnome-vfs2-debuginfo gtk2-debuginfo gtk2-engines-debuginfo \
 hal-debuginfo libX11-debuginfo libXcursor-debuginfo libXext-debuginfo \
 libXfixes-debuginfo libXft-debuginfo libXi-debuginfo libXinerama-debuginfo \
 libXrender-debuginfo libbonobo-debuginfo libgnome-debuginfo \
 libselinux-debuginfo pango-debuginfo popt-debuginfo scim-bridge-debuginfo
</pre><h4 name="Ubuntu_8.04">Ubuntu 8.04</h4>
<p>Ubuntu provides similar debug symbol packages for many of its libraries (although not all of them). To install them, simply run (to get a reasonably large set):</p>
<pre class="eval"> $ sudo apt-get install libatk1.0-dbg libc6-dbg libcairo2-dbg \
 libfontconfig1-dbg libgcc1-dbg libglib2.0-0-dbg libgnomeui-0-dbg \
 libgnomevfs2-0-dbg libgnutls13-dbg libgtk2.0-0-dbg libice6-dbg \
 libjpeg62-dbg libpango1.0-0-dbg libpixman-1-0-dbg libstdc++6-4.2-dbg \
 libx11-6-dbg libx11-xcb1-dbg libxcb1-dbg libxft2-dbg zlib1g-dbg
</pre>
<h3> See also</h3>
<ul> <li><a class="internal" href="/En/Debugging" title="en/Debugging">Debugging</a></li> <li><a class="link-https" href="https://wiki.mozilla.org/Performance:Tools" title="https://wiki.mozilla.org/Performance:Tools">Performance tools</a></li> <li><a class=" external" href="http://blog.mozilla.com/sfink/2011/02/22/fun-with-gdb/" title="http://blog.mozilla.com/sfink/2011/02/22/fun-with-gdb/">Fun with gdb</a> by Steve Fink</li> <li><a class=" external" href="http://hg.mozilla.org/users/jblandy_mozilla.com/archer-mozilla" title="http://hg.mozilla.org/users/jblandy_mozilla.com/archer-mozilla">Archer pretty printers for SpiderMonkey</a> (<a class=" external" href="http://itcouldbesomuchbetter.wordpress.com/2010/12/20/debugging-spidermonkey-with-archer-2/" title="http://itcouldbesomuchbetter.wordpress.com/2010/12/20/debugging-spidermonkey-with-archer-2/">blog post</a>)</li> <li><a class=" external" href="http://hg.mozilla.org/users/josh_joshmatthews.net/archer-mozilla/" title="http://hg.mozilla.org/users/josh_joshmatthews.net/archer-mozilla/">More pretty printers</a> for Gecko internals (<a class=" external" href="http://www.joshmatthews.net/blog/2011/06/nscomptr-has-never-been-so-pretty/" title="http://www.joshmatthews.net/blog/2011/06/nscomptr-has-never-been-so-pretty/">blog post</a>)<a href="/blog/2011/06/nscomptr-has-never-been-so-pretty" title="blog/2011/06/nscomptr-has-never-been-so-pretty/"><br> </a></li>
</ul>
<div class="originaldocinfo">
<h3 name="Original_Document_Information">Original Document Information</h3>
<ul> <li><a class="external" href="http://bonsai-www.mozilla.org/cvslog.cgi?file=mozilla-org/html/unix/debugging-faq.html&amp;rev=&amp;root=/www/">History</a></li> <li>Copyright Information: © 1998-2008 by individual mozilla.org contributors; content available under a <a class="external" href="http://www.mozilla.org/foundation/licensing/website-content.html">Creative Commons license</a></li>
</ul>
</div>
Revert to this revision