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.

No comments: