17
Mar 08

Dehydra World Tour

After a few weeks of mindnumbing work on treehydra gutts, I finally have something exciting to talk about!

We will be presenting  Dehydra at the GCC Developer’s Summit in lovely Ottawa. The GCC version of Dehydra exceeded all of my expectations, so it will be exciting to meet awesome GCC hackers who lay the groundwork to make this possible. Got suggestions for other venues to present Dehydra?

Packaging Help Needed

I feel that the Dehydra concept is getting mature enough for a 1.0 release. Recently baked GCC 4.3 means I’ll be able to distribute a 4.3-specific plugin patch(currently it’s against trunk, aka 4.4to-be). Now I need README, LICENSE, configure files, etc.

I will need help with packaging dehydra + patched gcc into .dpkg and .rpm files. Leave a comment, email me/static analysis list or poke me in #mmgc on irc.mozilla.org if you can help with packaging.

Logo/Mascot Wanted

Since every serious project has a cool mascot, it would be cool to get one for Dehydra. I’d be curious to see what people think could symbolize a code scanning monster that makes grep feel inadequate. I have a feeling a cartoon version of a giant Heavy Metal Duck might be it, but I haven’t made up my mind yet.

Treehydra What?

Treehydra is a work-in-progress name for the low-level equivalent of Dehydra. Currently it is built as separate GCC plugin. I haven’t yet made up mind on whether Treehydra will end up extending Dehydra or stay a separate tool. Since treehydra needs dehydra for bootstrap, they’ll stay separate for now.

Last week I managed to run treehydra to completition on my mozilla checkout and walk the resulting AST in JS correctly. Now comes the fun part of making it do useful tricks.


12
Mar 08

Recipe: How many classes are instantiated in Mozilla?

I got this question in the mail today.

Seems like a simple enough question, but grep won’t provide that answer :) It also happens to be an excellent usecase for Dehydra.

My script:

var classes = []
function process_type (c) {
if (!/class|struct/(c.kind)) return
classes.push (c.name)
}


function input_end() {
var f = this.aux_base_name + ".counter"
print(f)
write_file (f, classes.join ("\n"))
}

process_type is called every time GCC hits a class declaration or a template is instantiated(also for enums and unions, but those get ignored with the .kind check). Then input_end is called when GCC is done processing the file. this.aux_base_name is the input filename.

I hooked up this script to the mozilla build by adding the following to .mozconfig:

export CXX=$HOME/gcc/bin/g++
export CXXFLAGS="-fplugin=$HOME/work/gccplugin/gcc_dehydra.so -fplugin-arg=$HOME/work/gccplugin/test/count_classes.js"

Then I built:

make -f client.mk build WARNINGS_AS_ERRORS=

Count:

find -name \*.counter|xargs cat |sort |uniq > /tmp/classes.txt
wc /tmp/classes.txt

Answer: 15001

There are a million other trivial queries that could be accomplished in a similar manner that weren’t easy or possible before.

Update: Fixed typo, had an extra zero in the answer


11
Mar 08

Dehydra as Pesticide?

Joshua, pointed me at a fabulous article over at the Economist. The brave souls went to great deal of effort to compare, contrast static and dynamic analyses in an easy to understand fashion. My favourite part of the article:

Seth Hallem, the co-founder of Coverity, which makes a static-analysis tool, expects greater integration between programming and testing tools in future.

I suspect in the future, there will be awesome tools that even integrate into one’s compiler. Egads!

Treehydra

I spent a few days chasing my own tail looking for bugs in the C->JS conversion code. Turns it out it wasn’t bug, but a manifestation of GCC having slightly more AST mutation than I expected*. Bugs in the mental model hurt most :) The upside is that this forced me to switched the conversion process from eager to lazy which also gave a big performance boost. I hope to finally have something capable of doing initial analyses by the end of the week.

* In a perfect world compilers are written in functional languages where AST are transformed instead of mutated.


03
Mar 08

Random News in the Dehydra Corner

I have not blogged recently because I have been busy working on a rather fancy new mode for Dehydra. Turned out it is indeed possible to use JavaScript to walk and generate code to automagically convert thousands of recursive C structures into corresponding JS Objects. Now dehydra will have two modes: a simple pattern matcher that is easy to get started with and a hardcore mode for compiler geeks capable of advanced analyses. More on this later, for now subscribe to static analysis mailing list for more information.

Turns out that I’m not the first person to embed SpiderMonkey into GCC.

I have gotten in touch with two different GCC plugin projects. Seems that other projects are more academic in nature and still in the early design/development stages.

In constrast, Dehydra efforts are driven by existing unmet needs. In two months we went from having a crazy idea about using GCC for static analysis to having Benjamin integrate support for Dehydra checks into the moz 2 development repository to be run in a tinderbox.

I am also excited to see that people are discovering that Dehydra can be used to explore the codebase. We are not quite at the stage where one can interactively query the codebase from an ajax UI, but we are making steps in the right direction. As part of this trend, dehydra documentation is starting to migrate to MDC.