The Mozilla
Organization
At A Glance
Feedback
Get Involved
Newsgroups
License Terms
Newsbot
Developer Docs
Roadmap
Projects
Ports
Module Owners
Hacking
Get the Source
Build It
Testing
Download
Bugzilla
Bug Writing
Tools
View Source
Tree Status
New Checkins
Submit A Bug
FAQ
Search
Debugging Mozilla on Linux FAQ
last modified:


Contents:
  1. Introduction
  2. How do I debug 5.0 on Linux?
  3. How do I use ddd / gdb?
  4. The debugger is slow. How can I make it faster?
  5. ddd/gdb won't let me set a break point. Why not?
  6. The application is aborting. Where do I set the break point to find out where it is exiting?
  7. What is strace and how do I use it?
  8. What should I do about the SIG32 I'm getting on RH 6.0?
  9. How do I use LD_BIND_NOW env variable?
  10. This is too hard, just give me a .gdbinit that works.
  11. How do I display PRUnichar's?
  12. Debian's gdb doesn't work. What do I do?
  13. "run" or "prun" in gdb fails with "error in loading shared libraries."
  14. I have questions. Who do I ask?
  15. I have comments about this FAQ. Who do I send them to?
  16. I want to add to this FAQ. Who do I send my additions to?

  1. Introduction:

    This document is to help those Mac and Windows people debug Mozilla on Linux. This is a work in progress.

  2. How do I debug 5.0 on Linux?
      $ cd mozilla/dist/bin
      $ ./mozilla-apprunner.sh -g
    

    If you are new to debugging on Linux, I recommend using ddd. ddd is a graphical debugger that runs on top of gdb. You may still find yourself doing gdb command from within ddd.

  3. How do I use ddd / gdb?

    Some docs to get started:
    http://www.gnu.org/manual/gdb-4.17/html_mono/gdb.html
    http://www.cs.tu-bs.de/softech/ddd/ddd-tips.html
    http://www.cs.tu-bs.de/softech/ddd/ddd-faq.html

  4. The debugger (gdb/ddd) is slow. How can I make it faster?

    Add this line to your $HOME/.gdbinit file:
       set auto-solib-add 0
    

    This will cause gdb to lazily read symbol tables. (If you are using this option with glibc 2.1, please see What should I do about the SIG32 I'm getting in RH 6.0?)

    Example:

    I'm debugging apprunner. I interrupt the process. Looking at the stack trace, I see this:

    (gdb) where
    #0 0x4085e7d0 in ?? () from /lib/libc.so.6
    #1 0x4066cbf0 in ?? () from /usr/lib/libglib-1.2.so.0
    #2 0x4066c634 in ?? () from /usr/lib/libglib-1.2.so.0
    #3 0x4066c979 in ?? () from /usr/lib/libglib-1.2.so.0
    #4 0x4059bf3a in ?? () from /usr/lib/libgtk-1.2.so.0
    #5 0x40222a19 in ?? () from /builds/seth/MOZILLA/06.23.1999/04.30/mozilla/dist/bin/libwidgetgtk.so
    #6 0x4015617d in ?? () from /builds/seth/MOZILLA/06.23.1999/04.30/mozilla/dist/bin/libnsappshell.so
    #7 0x804aa00 in main (argc=2, argv=0xbffffa04) at nsAppRunner.cpp:670
    #8 0x407cecb3 in ?? () from /lib/libc.so.6
    (gdb)
    

    To load the symbol tables, type this at the gdb prompt:

    (gdb) shar libwidgetgtk.so
    (gdb) shar libnsappshell.so
    (gdb) shar libc.so.6
    (gdb) shar libglib-1.2.so.0
    (gdb) shar libgtk-1.2.so.0
    

    Now, if I do "where" again to see the stack trace, I get this:

    (gdb) where #0 0x4085e7d0 in __poll (fds=0x83171f8, nfds=3, timeout=19) at ../sysdeps/unix/sysv/linux/poll.c:45 #1 0x4066cbf0 in g_main_poll () #2 0x4066c634 in g_main_iterate () #3 0x4066c979 in g_main_run () #4 0x4059bf3a in gtk_main () #5 0x40222a19 in nsAppShell::Run (this=0x80c35e0) at nsAppShell.cpp:237 #6 0x4015617d in nsAppShellService::Run (this=0x80b4a80) at nsAppShellService.cpp:428 #7 0x804aa00 in main (argc=2, argv=0xbffffa04) at nsAppRunner.cpp:670 #8 0x407cecb3 in __libc_start_main (main=0x8049abc <main>, argc=2, argv=0xbffffa04, init=0x804956c <_init>, fini=0x804b738 <_fini>, rtld_fini=0x4000a350, stack_end=0xbffff9fc) at ../sysdeps/generic/libc-start.c:78

    Advanced tricks:
    1) you don't have to type the full library name to load it

    "shar msg" will load any libraries (used by the process you are debugging) that match this pattern lib*msg*

    (gdb) shar msg
    Reading symbols from /builds/seth/MOZILLA/06.23.1999/04.30/mozilla/dist/bin/libmsgbaseutil.so...done.
    Reading symbols from /builds/seth/MOZILLA/06.23.1999/04.30/mozilla/dist/bin/components/libmsgimap.so...done.
    Reading symbols from /builds/seth/MOZILLA/06.23.1999/04.30/mozilla/dist/bin/components/libmsgnews.so...done.
    Reading symbols from /builds/seth/MOZILLA/06.23.1999/04.30/mozilla/dist/bin/components/libmsgcompose.so...done.
    Reading symbols from /builds/seth/MOZILLA/06.23.1999/04.30/mozilla/dist/bin/components/libmsgdb.so...done.
    

    2) mozilla/tools/debug/gdb/solib.gdbinit

    I added some macros to load symbols from chunks of code that im
    interested in - as opposed to the whole damn thing.
    For rdf, mailnews, etc, you will need new entries.

    thanks to Arun Sharma for this tip.

  5. ddd/gdb won't let me set a break point. Why not?

    You probably can't set a breakpoint because the library where the symbol lives isn't loaded yet.
    (This happens if you are using the "auto-solib-add" trick (from #4).)
    But here's a trick from blizzard@redhat.com:
    "You can't set a breakpoint in a library that hasn't been loaded but you can
    set a breakpoint in _dl_open and set the breakpoint once the library has been
    loaded.  It's not pretty but it works."
    

  6. Where do I break to track down aborts?

    PR_ASSERT() vs NS_ASSERTION() on Linux.

    (gdb) b abort
    (gdb) b exit
    
  7. What is strace and how do I use it?

    strace is your friend. more on this later.

  8. Why do I keep stopping with SIG32? How do I stop that?

    For rh 6.0, you may need to add this line to your $HOME/.gdbinit file:

       handle SIG32 nostop
    

    With the landing of Necko, mozilla is a multi-threaded application on Unix. Unfortunately, this confuses pthreads when run under gdb on glibc 2.1 with the auto-solib-add option.

    The solution is to have libpthread.so loaded when the first thread gets created. One trick to do this is to set a breakpoint in main() and then load libpthread at this point:

    gdb ./apprunner 
    GNU gdb 4.17.0.11 with Linux support
    Copyright 1998 Free Software Foundation, Inc.
    GDB is free software, covered by the GNU General Public License, and you are
    welcome to change it and/or distribute copies of it under certain conditions.
    Type "show copying" to see the conditions.
    There is absolutely no warranty for GDB.  Type "show warranty" for details.
    This GDB was configured as "i386-redhat-linux"...
    (gdb) tbreak main
    Breakpoint 1 at 0x804b289: file nsAppRunner.cpp, line 808.
    (gdb) run
    Starting program: .../mozilla/dist/bin/./apprunner 
    
    Breakpoint 1, main (argc=1, argv=0xbffff8a4) at nsAppRunner.cpp:808
    808	    rv = NS_InitXPCOM(NULL);
    (gdb) sha pthread
    Reading symbols from /lib/libpthread.so.0...done.
    (gdb) cont
    
    You can also add these lines to your .gdbinit:
    def prun
      tbreak main
      run
      sha pthread
      cont
    end
    
    And then simply type "prun" instead of "run" to run apprunner.

  9. How do I use the LD_BIND_NOW environment variable?

    You might want to add information about environment. I always have this
    set:

    export LD_BIND_NOW=1

    or, if you are using tcsh as your shell:

    setenv LD_BIND_NOW 1

    The LD_BIND_NOW=1 keeps the dynamic linker from lazily linking symbols.
    This means that when you're walking through code you never suddenly end up in the dynamic loader hunting for a symbol.
    from Christopher Blizzard <blizzard@redhat.com>

  10. This is too hard, just give me a .gdbinit that works.

    .gdbinit

  11. 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}
      
    • Define a small helper function "punichar" in #ifdef NS_DEBUG code somewhere.

  12. 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.

  13. "run" or "prun" in gdb with "error in loading shared libraries."

    Attempting to run apprunner inside gdb fails with an error message similar to the following:

    Starting program: /u/dmose/s/mozilla/mozilla-all/mozilla/dist/bin/./apprunner /u/dmose/s/mozilla/mozilla-all/mozilla/dist/bin/./apprunner: 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'.

  14. I have questions.

    post your questions to this newsgroup:

    news://news.mozilla.org/netscape.public.mozilla.unix

    If you are trying to debug Mozilla on UNIX, we'll gladly help.

  15. I have comments.

    post your constructive comments to this newsgroup:

    news://news.mozilla.org/netscape.public.mozilla.unix

    whining will be ignored.

  16. I want to add to this FAQ. Who I send my additions to?

    post your additions to this newsgroup:

    news://news.mozilla.org/netscape.public.mozilla.unix or send mail to sspitzer@netscape.com.

Copyright © 1998-1999 The Mozilla Organization.
Last modified November 5, 1999.