The Mozilla
Organization
Our Mission
Who We Are
Getting Involved
Community
Editorials
What's New
Newsbot
Development
Roadmap
Module Owners
Blue Sky
Projects
Status
Tools
Products
Source Code
Binaries
Documentation
License Terms
Bug Reports
Quality
Search
Feedback
Debugging Mozilla on Linux FAQ
last modified:


Contents:
Introduction:

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



Question: 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.



Question: How do I use ddd / gdb?

Start here:

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



Question: 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

To load the symbol tables, I'd do this on the gdb console:

(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) ramiro 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.



Question: I can't set a break point in 'nsNntpService::~nsNntpService(void)'. Why won't gdb let me?



Question: What is strace and how do I use it?

strace is your friend. more on this later.



Question: Where do I break to track down aborts?

PR_ASSERT() vs NS_ASSERTION() on Linux.

(gdb) b abort
(gdb) b exit



Question: 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.


Question: 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>



Question: 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.



Question: I have comments.

post your constructive comments to this newsgroup:

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

whining will be ignored.



Question: 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.