Well that was easy

Last week we were visited at Ozlabs and then treated to a seminar at the ANU by Nick Nethercote, one of the principal authors of Valgrind. I haven’t had much to do with Valgrind myself, and although I had a general idea of what it did, it was great to have it explained by Nick.

Ben decided that his “Christmas hacking project” would be to add a coverage analyser “skin” to Valgrind. With an hour or so to myself on Saturday I thought I’d have a quick poke around, and see if I could come up with anything. I was pleasantly surprised.

With 80 lines of C I could to a quick and dirty coverage analysis of a program’s execution. With another 65 lines of python I could take the coverage info and use it to markup the source into HTML:

int main(int argc, char *argv[])
{
    if (argc > 3) {
        printf("argc was greater than 3\n");
    } else {
        printf("argc was less than 3\n");
    }
    printf("argc was something\n");

    return 0;
}

There’s a bug in that the return 0 is supposedly never executed, and a real coverage tool will have to do a lot more, but it was still nice for a morning’s work. My only gripe is all the VG_(foo) business, but I guess every codebase has it’s quirks.

Posted by mike on Saturday December 18th, 2004, tagged with ,

Comments are closed.