File:  [NetBSD Developer Wiki] / wikisrc / tutorials / pkgsrc / debugging_firefox.mdwn
Revision 1.2: download - view: text, annotated - select for diffs
Thu Sep 6 01:23:09 2018 UTC (20 months, 2 weeks ago) by maya
Branches: MAIN
CVS tags: HEAD
give people a stronger chance if we get a debugger that can handle firefox.

    1: [[!meta title="Debugging Firefox"]]
    2: 
    3: The Firefox package in www/firefox (and also, maybe starting with the next update to firefox 31, the long term stability release version) support various ways to support debugging the resulting binary. Here is when and how to use them:
    4: 
    5: Assuming you have a firefox from pkgsrc installed already, but it crashes (on startup, or reproducable when you visit certain pages), you can build a special debuggable version of the pkg (without overwriting your existing install).
    6: 
    7: First, let us look at the options offered by the pkg:
    8: 
    9:     [/usr/pkgsrc/www/firefox] martin@whoever-brings-the-night > make show-options
   10:     Any of the following general options may be selected:
   11:         alsa     Enable ALSA support.
   12:         debug    Enable debugging facilities in the package.
   13:         debug-info       Enable debug info in generated binaries (e.g. for crash analysis), but not full scale debugging.
   14:         gnome    Enable GNOME support.
   15:         mozilla-jemalloc        Enable building with Mozilla'a jemalloc.
   16:         official-mozilla-branding       Use official Mozilla reg. trademarks and logos.
   17:         pulseaudio       Enable support for the PulseAudio sound server.
   18:         webrtc   Enable web realtime communications API.
   19: 
   20:     These options are enabled by default:
   21:         pulseaudio
   22: 
   23:     These options are currently enabled:
   24:         official-mozilla-branding pulseaudio
   25: 
   26:     You can select which build options to use by setting PKG_DEFAULT_OPTIONS
   27:     or PKG_OPTIONS.firefox.
   28: 
   29: The two interesting ones are `debug` and `debug-info`:
   30: 
   31: * `debug` will create a version with all internal mozilla consistency checking enabled, and all optimization turned off. This is usefull when creating extensions or plugins, but not what we want here. Especially the disabled optimization might hide all issues created by optimization or compiler bugs.
   32: 
   33: * `debug-info` is what we are looking for: it creates a stock release version of firefox, but with debug information available
   34: 
   35: So set `PKG_OPTIONS.firefox += debug-info` in /etc/mk.conf (or wherever your relevant mk.conf lives) and build the package from scratch (i.e. do `make cleandir && make`). You do **NOT** need to install this version. You can optionally set the environment variable MAKE_JOBS to some number greater than the number of cpu/cores you want the build to use, this will speed up parts of the build significantly.
   36: 
   37: After building the pkg, you can use files in the obj/workdir to run this firefox inside gdb. But first make sure to not have any remaining firefox instances running, as those would cause just another window to open but running the non-debugable code version of the already running instance.
   38: 
   39: You have to locate your pkgsrc work directory for this pkg, which could be for example `pkgsrc/www/firefox/work`, or if you have set WRKOBJDIR to a special directory, something like: `/usr/pkgobj/www/firefox/work`. Assuming the latter, now cd to the `build/dist/bin` directory inside it, and invoke the helper shell script `run-mozilla.sh` with `-g` option:
   40: 
   41:     [/usr/pkgobj/www/firefox/work/build/dist/bin] martin@night-owl > paxctl +m ./firefox
   42:     [/usr/pkgobj/www/firefox/work/build/dist/bin] martin@night-owl > ./run-mozilla.sh -g ./firefox
   43:     MOZILLA_FIVE_HOME=.
   44:       LD_LIBRARY_PATH=.:./plugins:.
   45:      DYLD_LIBRARY_PATH=.:.
   46:      LIBRARY_PATH=
   47:        SHLIB_PATH=.:.
   48:           LIBPATH=.:.
   49:        ADDON_PATH=
   50:       MOZ_PROGRAM=./firefox
   51:       MOZ_TOOLKIT=
   52:         moz_debug=1
   53:      moz_debugger=
   54:      moz_debugger_args=
   55:      /usr/bin/gdb  --args ./firefox
   56:      GNU gdb (GDB) 7.7.1
   57:      Copyright (C) 2014 Free Software Foundation, Inc.
   58:      License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
   59:      This is free software: you are free to change and redistribute it.
   60:      There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
   61:      and "show warranty" for details.
   62:      This GDB was configured as "x86_64--netbsd".
   63:      Type "show configuration" for configuration details.
   64:      For bug reporting instructions, please see:
   65:      <http://www.gnu.org/software/gdb/bugs/>.
   66:      Find the GDB manual and other documentation resources online at:
   67:      <http://www.gnu.org/software/gdb/documentation/>.
   68:      For help, type "help".
   69:      Type "apropos word" to search for commands related to "word"...
   70:      Reading symbols from ./firefox...done.
   71:      (gdb) 
   72: 
   73: and issue the `run` command. This will start firefox (with quite a bit of delay, since gdb needs to read a lot symbols from the shared libraries loaded now). Then make firefox crash, and try to find out why.

CVSweb for NetBSD wikisrc <wikimaster@NetBSD.org> software: FreeBSD-CVSweb