C/C++ Eclipse Project Generation

With the landing of bug 973770 (and a few touch up landing this week) the Mozilla build system can now generate a fully working out-of-the-box no hassle eclipse workspace for C++ gecko development. This has been tested for Mac, Fennec and B2G. For Windows please use the Visual Studio project generator. If you find any bugs please file and link off bug 973770.

Didn’t we already support eclipse projects? Yes we did but the setup was quite tedious to setup and maintain. My approach automates some of these instructions and uses the information now available from within moz.build to generate the project. This also means we can remove the build scanning phase which tends to make Eclipse unresponsive.

To use this:

  • Download the latest Eclipse CDT 8.3 package for your platform
  • Build your tree
  • Run |./mach build-backend -b CppEclipse|. For b2g cd into objdir-gecko and use |../gecko/mach build-backend -b CppEclipse|
  • Start eclipse, use $OBJDIR/eclipse_workspace as the workspace
  • File->Import->Existing Project with path $OBJDIR/eclipse_workspace/gecko
  • Let the indexer run on the first start. This can take about 20 mins (long but worth it, see below). This will index your exact mozconfig setup (example -DDEBUG, b2g system libs).

Here are some benefits:


Code Completion

Call Hierarchy

Call Hierarchy

Build, Flash (b2g), Launch

Build, Flash (b2g), Launch

Type Hierarchy

Type Hierarchy

Mozilla Formatter

Mozilla Formatter

If you find yourself tweaking the project let me know so that I can integrate changes into the project generator instead where everyone can benefit.

Dev Tip: Debugging optimized code without a clobber – Rebuilding a module without optimization

Sometimes you have an optimized build for whatever reason (say you’re doing a lot of profiling) but optimizations make non trivial debugging impossible. You don’t have an up to date build without optimization so you whine, start a non optimize build and start looking at bugzilla for 20 mins.

Frankenstein optimized/non optimized build to the rescue! Simply add:

CXXFLAGS += -O0 -g

or for moz.build use:

MOZ_OPTIMIZE_FLAGS += ['-O0', '-g']

or for MSVC:


to the Makefile for the module(s) you’re interested in debugging, for me it was gfx/layers/Makefile.in.

How does this work? Well optimizations are done at the object level and each object file are built to follow the ABI. As long as the ABI is followed, and it really really should, then you can expect this to work without any problems.

Disclaimer: This isn’t supported! If you have problems then do a clobber build.

IRC SMS Notification

You may notice that my nick now switches to “BenWa|Sms” when I am away, if you are curious read on:

I made a ZNC (IRC Bouncer) module called cmdnotify. The module will invoke a script when a highlighted word is mentioned if you are not attached to the bouncer. In my case I relay the message over SMS to my phone.

If you’re interested in setting this up for yourself you will first want to configure ZNC and then install my cmdnotify module.

Using Visual Studio 2010 IDE

This has been replaced by the following:


Setting up the build is somewhat straight forward on windows however I could not find any instructions on setting up a Visual Studio project for editing and debugging. I’m writing down the instructions I was given on IRC for my future benefits and for others. I hope at some point someone will take the initiative to put this information on MDN.

These instructions start from the point where you have a simple build of Firefox completed with the latest windows SDK and VS 10.

  • Create a new project using ‘Project from Existing Code’ (See Joe Walker’s comment if you don’t have this).
  • Select ‘Visual C++’, enter a project name (ex: mozilla-central), source directory as project file location, select ‘Show all files in Solution Explorer’.
  • Make sure you un-select ‘Add Files to the project from these folders’, hit Next.
  • Select ‘Use external build system’, hit Finish.
  • Project will be empty until you select ‘Show all Files’ from top middle icon in the solution explorer when the project is selected, File -> close the solution, re-open it. Source files should appear (I had to do this step 3 times)
  • For autocomplete select Project ->Properties -> NMake.
  • Under ‘Preprocessor Definitions’ add XP_WIN (return here later to add any definition your may be compiling with/find missing)
  • Under ‘Include Search Path’ type in ‘<objdir>\dist\include’ (I recommend to have built your project from command line for this step)
  • For debugging select ‘Debugging’ still under the property page, type in the absolute path to firefox.exe. Recommended command argument ‘-P “Minefield” -no-remote’.

I strongly recommend using ‘Console’ when working from the command line.

Optional: Add a build/clean target (Can otherwise be done outside of Visual Studio using the command line)

  • Create a single script, build.sh, that you can invoke that will trigger a build with the configuration you need. It should set all environment variables needed.
  • Copy the ‘mozilla-build/start-msvc10.bat’ to ‘mozilla-build/start-msvc10-build.bat’.
  • Replace the last line to read something like ‘”%MOZILLABUILD%”\msys\bin\bash –login <path-to-your-build-script>/build.sh’.
  • Select Project->Properties->NMake, for Build Command Line type ‘C:\mozilla-build\start-msvc10-build.bat’.
  • Advanced: Create multiple project configuration for each mozconfig build configuration you would like to work with then have them invoke specific build scripts and firefox.exe.

You can modify your script to do incremental builds to reduce your turn around time.

Improving Incremental Builds Using ObjDir Method

One annoyance I’ve ran into while working with incremental builds is that the Makefile are generated in the obj-dir. Rebuilding requires you to go from your source directory to your corresponding obj-dir and invoking ‘make’.

Just place the following command in a script in your path:

cd $(pwd | sed 's/mozilla-central/mozilla-central\/obj-ff-dbg/g') && make; cd -

make -C $(pwd | sed 's/mozilla-central/mozilla-central\/obj-ff-dbg/g')

This script will call the corresponding obj-dir Makefile from the source folder. As readers mentioned the second version removes the ‘cd’ nastiness, thanks!

This is great if your working with both 32 and 64-bits obj-dirs since you can create a make32.sh and make64.sh script to trigger the corresponding incremental build from the same source folder and manage two builds!

Sharing Your Session


I’ve been working a lot with remote people over IRC here at Mozilla. Pastebin can be your friend to share stackdumps but sometimes you need to show an interactive session. This is great if you want someone more experience to help you debug the problem in GDB for example. GNU Screen is a great terminal multiplexer but the drawback is that it requires some configuration.

How to:

Here is a simpler way to quickly share your session over a chat session. You can redirect ‘script’ to a listening port using the following command:

touch transcript; tail -f transcript & script -q -t 0 | tee transcript | nc -l 5678; rm transcript;

That’s a long and complicated command but that is the best way I have found to redirect script to both the screen and ‘nc’. Let me know if you know a better way!
To have someone watch your interactive session ask them to execute the following commands:

nc <HOSTNAME/IP> 5678


If this is useful others I could extend this to allow the person watching to interact with the session as well, however for now I can just claim that it’s a security issue!

I’d also like to extend this to work with NATs by deploying an online web app where you can request that you would like to share a session with someone and it will give you addresses to connect to and act as a connector so that two users located in different intranets can use this as well.