Monday, January 9, 2012

Debugging Firefox in Windows with VS2010

Download and Make a Debug Build

1. Download Mozilla source from http://hg.mozilla.org/mozilla-central/ (choose files, then click on zip). Alternatively, you can follow the instructions at https://developer.mozilla.org/en/Download_Mozilla_Source_Code which leads to Mozilla's FTP server ftp://ftp.mozilla.org/pub/mozilla.org/firefox/releases/9.0/source/ . (first link is nightly build, second is release build).

2. Extract the source code. 7-zip works best. (e.g. to C:\FFBuild\mozilla-release).


4. Download and install MozillaBuild.

5. If you have VS2010 it comes bundled with Windows SDK. No worries here.

6. Create a .mozconfig file in the root directory of the source code (mozilla-central or mozilla-release). This file will contain the build configuration for the source. For our purposes, we have to do the "debug" build. I followed the .mozconfig from https://developer.mozilla.org/en/Configuring_Build_Options#Firefox.2C_Debugging_Build . (Note: windows won't allow creating .mozconfig file, so create a text file new.txt, go to cmd, and from cmd rename the file to .mozconfig like this: a) cd to root dir of source code, b) rename new.txt .mozconfig).

7. For windows, use of pymake instead of make is advocated here https://developer.mozilla.org/en/pymake . Follow those instructions to start the build (might take upto 2 hours). (Note: to make builds faster, edit this line in the .mozconfig file : mk_add_options MOZ_MAKE_FLAGS="-jN", edit N to be twice the number of your processor cores. For example, for a 4 core processor, replace N with 8).

Debugging in Visual Studio

8. If the build is successful, there should be a firefox.exe at [mozilla-source]\ff-dbg\dist\bin . Test it to see if it works.

9. Start VS2010. Go to File>Open>Project/Solution>[mozilla-source]\ff-dbg\dist\bin\firefox.exe .

10. Right click on firefox.exe in the Solution Explorer and go to Properties. Edit Environment Variable to add MOZ_NO_REMOTE=1. (https://cs.senecac.on.ca/~david.humphrey/writing/debugging-firefox.html ).

11. Open any file from the source code directory (CAUTION: NOT FROM THE ff-dbg DIRECTORY). Set a debug point. For example: line 143 of [mozilla-source]\caps\src\nScriptSecurityManager.cpp.

12. Right click on firefox.exe and Debug>Start New Instance.