I was fortunate to have a good start in building firefox for the first time – except the windows style line endings error – I didn’t have any other difficulties and was able to get the build running locally quickly.

However, when I started to play around to make a change to the source code, I started getting into a lot of trouble. I have been trying to re-build firefox for about the last 4 hours, and only now got it to work again. Here’s what happened and what I learned:

For my first mod to the code, I thought I would insert a printf statement just before an error that I was getting on my build:

Firefox debug mode build

The error was inside a .cpp file inside my object directory. Even though it was inside my objdir, I thought it will be safe to make a change, as I was modifying a cpp file and not .obj file. I made the following change to the code, just before the line that threw the exception that I saw in my build.

if ( aInstancePtr )
        nsCOMPtr<nsISupportsWeakReference> factoryPtr = do_QueryInterface(aInstancePtr, &status);
        printf("My first printf! Woohoo!");
        NS_ASSERTION(factoryPtr, "Oops!  You're asking for a weak reference to an object that doesn't support that.");
        if ( factoryPtr )
            status = factoryPtr->GetWeakReference(&result);
        // else, |status| has already been set by |do_QueryInterface|

I ran the make command again in a different objdir and waited for the new ff to build, but it kept stalling at different steps. I waited for over 30 minutes the first time, and then an hour and so on but the make command would just freeze. I tried building with slightly different config options (disabling debug and test just to build quickly), but it still kept hanging.

During this whole time that it was building and failing, I was going over the different folders and files of the source code. While the folder names and file names made some sense, opening the file and trying to understand the code made far lesser sense. Even in files I thought I will be able to follow the more code I read, I got lost very quickly.

Then, I made a small change to one of the only files I could make sense of:


There were no comments for the lines I changed, but they were self-explanatory – they set the default url for firefox. I changed the value of the url from about:blank to the url for Planet CDOT.


I made the same change in another similar file I found, but then reverted it back, because I thought this was the reason my build didn’t work (the comments had warned not to make the change):


# Do NOT localize or otherwise change these values

I had been trying the re-build in another objdir all this while because I wanted to save the working build I had, and also preserve one of the changes I had made to a .cpp file inside it. This is when I realized how silly it is to modify a file (whichever type of file) inside the objdir – because the changes will just get overwritten with a new build. And if you don’t rebuild, the changes will never take effect. (I know….I can’t believe it took me to long to realize this :P)

So it was pretty straight-forward from here, I delete all the other objdirs I had created leaving the original one that worked. I ran the make command again, targeting the same objdir – the build worked, taking just 16 minutes, as most of the object files didn’t have to be compiled again.

I knew my printf change was a lost cause, but I was hoping to see if the other change I made (changing the default url) would work. I didn’t expect it to work because there was the other properties files that still clearly defined the start-up homepage as ‘about:blank’, but somehow – and you’ll just have to trust me on this (or try it for yourself) – the default url that the firefox nightly build opened with was Planet CDOT!

Firefox debug mode build

While going through the c++ code and the “wall” of text during the builds, I noticed a lot of interface names and class names began with the prefix ‘ns’. For example, nsIArray. I wondered if this was a remnant of the code borrowed into the Mozilla project from ‘Netscape’. I have seen the NS prefix in class names in ios code library (iPhone) too, but that was because that code was imported from NextStep, which was the second company founded by Steve Jobs after he left Apple, which was merged back into Apple when he re-joined.

So I googled to see if my assumption was right, and it turns out the stated reason for why a lot of the code has the ‘ns’ prefix is because it stands for ‘Namespace’. Strange.

Anyway, in that search I also came across this useful article:


Stay tuned for my first working printf in Mozilla code…

3 responses

Do you want to comment?

Comments RSS and TrackBack Identifier URI ?

where do you get output of printf() statement when you run firefox…?

February 3, 2012 12:25 pm

ameya, it will get printed in the console from where you build your firefox.

February 6, 2012 11:18 pm

Comment now!