23
Apr 07

Mozilla Class Browser

My last attempt at visualizing the Mozilla class hierarchy ended up being way too slow to be useful. So I based my second attempt on using a different tree layout. After quite a few scalability optimizations, the graphing performance is now bearable.

This class browser uses the canvas tag to draw the pretty boxes & lines and links back into lxr. The class browser consumes a JSON file produced by running DeHydra on the layout/ directory. I am happy that I am finally able to examine gigantic code graphs interactively thanks to the <canvas> tag.

In the near future I hope to produce a few different kinds of complete graphs of the entire Firefox codebase. The idea is to have them generated nightly. Then that if someone has a general question about the Firefox codebase, it could be expressed as JavaScript within an interactive console in the browser. The answer would be either be graphed or returned as a JSON object.


04
Apr 07

What About JavaScript In Dehydra?

Most static analysis tools don’t let you script them. Oink is an example of that. Adding a new analysis requires extending an existing tool with a feature which may not fit in smoothly or writing a new tool in C++ with the corresponding boilerplate to handle command-line arguments, etc.

At the other extreme lives UNO which has a DSL that is designed strictly for solving control-flow programs.

I chose JavaScript for Dehydra to get the power of a full-blown (and memory safe) programming language while keeping JS’s view of the code under analysis as simple as possible. I think I got the C++/JS mix just right, the C++ codebase is growing slowly, yet I add JS scripts for any little task.

Additionally JS came in handy for publishing the data on the web. I wrote a script to determine the class inheritance graph. Then I added a little prefix to the file produced, combined it with jsviz and ended up with a really slow and unusable, but somewhat pretty class browser. This could evolve to be a rather neat way to supplement LXR.


02
Apr 07

Automated Code Refactoring

Squash

If you are working on any C++ refactoring, especially if it involves function calls, spans multiple files or feels like you need a compiler in your head to help you, drop me a note to see if squash can help. Squash provides a great deal of control over the refactoring process because it is not tied to a particular IDE and can be customized to accommodate for special cases.

On Friday, two squash-produced patches landed:

  1. A 212K patch to rename nsIFrame::GetPresContext to PresContext. It took a couple of minutes to produce a patch for mac & linux, and then some manual labour to complete it so it builds on Windows too. Unfortunately, Microsoft C++ is not yet supported by Oink. Windows-specific code will require magnitudes more of human labour until such support is contributed.
  2. A much simpler patch to calls to remove uses of the deprecated ::Recycle(). This took a few minutes once I added support for renaming global functions to squash.

Dehydra

C++ support in dehydra is coming along splendidly. I started working on cross-function analysis support. Currently my goal is to allow the user to build callgraphs of Mozilla. The first application of that is going to be dead code detection.

In the meantime, contact me if you are looking for patterns in the code that grep wont help with : control flow-sensitive code, type & syntax-aware matching, API misuse, etc. Dehydra can probably help.