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:

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

First, let us look at the options offered by the pkg:

[/usr/pkgsrc/www/firefox] martin@whoever-brings-the-night > make show-options
Any of the following general options may be selected:
    alsa     Enable ALSA support.
    debug    Enable debugging facilities in the package.
    debug-info       Enable debug info in generated binaries (e.g. for crash analysis), but not full scale debugging.
    gnome    Enable GNOME support.
    mozilla-jemalloc        Enable building with Mozilla'a jemalloc.
    official-mozilla-branding       Use official Mozilla reg. trademarks and logos.
    pulseaudio       Enable support for the PulseAudio sound server.
    webrtc   Enable web realtime communications API.

These options are enabled by default:
    pulseaudio

These options are currently enabled:
    official-mozilla-branding pulseaudio

You can select which build options to use by setting PKG_DEFAULT_OPTIONS
or PKG_OPTIONS.firefox.

The two interesting ones are debug and debug-info:

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.

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.

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:

[/usr/pkgobj/www/firefox/work/build/dist/bin] martin@night-owl > ./run-mozilla.sh -g ./firefox
MOZILLA_FIVE_HOME=.
  LD_LIBRARY_PATH=.:./plugins:.
 DYLD_LIBRARY_PATH=.:.
 LIBRARY_PATH=
   SHLIB_PATH=.:.
      LIBPATH=.:.
   ADDON_PATH=
  MOZ_PROGRAM=./firefox
  MOZ_TOOLKIT=
    moz_debug=1
 moz_debugger=
 moz_debugger_args=
 /usr/bin/gdb  --args ./firefox
 GNU gdb (GDB) 7.7.1
 Copyright (C) 2014 Free Software Foundation, Inc.
 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
 This is free software: you are free to change and redistribute it.
 There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
 and "show warranty" for details.
 This GDB was configured as "x86_64--netbsd".
 Type "show configuration" for configuration details.
 For bug reporting instructions, please see:
 <http://www.gnu.org/software/gdb/bugs/>.
 Find the GDB manual and other documentation resources online at:
 <http://www.gnu.org/software/gdb/documentation/>.
 For help, type "help".
 Type "apropos word" to search for commands related to "word"...
 Reading symbols from ./firefox...done.
 (gdb) 

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.

Add a comment