Monday, October 1, 2007

Using LXR / MXR

LXR/MXR is a cross-reference display of Mozilla source code. A user can perform a search using a keyword and it will return results of all occurrences of that keyword in the Mozilla source code. The results can also be broken down into more specific identities i.e. function name, variable name, etc.

In the lab, I tested MXR and tried to find how the "Go Back" feature in Firefox was coded. I typed in go "Go Back" into the search text field, performed a search and was shown a resulting list of all occurrences where "Go Back" was typed, be it actual code or comments. As it searched the entire Mozilla source code, I wanted a more application specific query so I typed in "browser" in the "in files matching" field. This helped narrow the search significantly.

The first file that caught my eye was the browser.js file as Mozilla was mainly written in JavaScript. I went into that file and only saw a few lines of code in the "BrowserBack" function. It appeared as if the JavaScript file served as a linking mediator. After further searching, I was able to narrow the GoBack() function down to the "nsIWebNavigation.idl" file and "nsDocShell.cpp." As the "nsIWebNavigation.idl" was an interface file, I only saw a declaration of void goback() but there was no actual code. In "nsDocShell.cpp." there was some code and further call to webnav->GoBack(). I was unable to find any more code form there, the files that resulted in further searching came up as more *.idl, *.js and *.h files which were linker files.

From my experience, MXR seems like a helpful tool, as the Mozilla source code contains over 6 million lines of code as well as thousands of files, manually searching, it would take a very long time to navigate and narrow down to what you need to find. MXR really helps cut this time down as it provides links in the source code to help you further progress your search. The search still takes a while though, it took me about 40 minutes to traverse through the results but once you get more familiar with how the searching works, you'll be able to include more specific options and that should cut your searching time down even more.

Creating a Debug Mozilla Build

My initial attempts of creating a debug Mozilla build was a pretty rough ride that ended in a terrible crash. At first, I had to download and install the Visual Studios 2005 which took me about 2 days. After I got my computer set up to the point where I can start following the steps for "Building Mozilla for the first time." I realized I was way over my head.

I have never built anything this big from source before so my inexperience proved to be a liability. As hard as I tried to follow the instructions, in the end I was still unsuccessful with compiling the source. My two attempts ended with memory accessing errors. I looked at my task manager and it was bombarded with make.exe that took up around 1.7MB but there were several hundred of them which in the end ate up all of the memory I had on my laptop (~2GB).

Fortunately, we did a build in our lab class and although I built the debug Mozilla build on Linux (much faster than Windows) I was able to transfer the knowledge so that my third attempt at building Mozilla at home was finally successful.

The two problems that I identified was that I had some mistypes in my "check out" statement so I never actually downloading the Mozilla source. The second problem was that my .mozconfig did not specify any project. All it had was:

# Add options
mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/obj-@CONFIG_GUESS@

# Optimization
ac_add_options --disable-optimize
ac_add_options --enable-debug
ac_add_options --disable-static --enable-shared

The combination of those two problems, I think, caused the program to continuously looping, creating make.exe until my machine ran out of RAM which took about six hours for each attempt.