A new Perl debugger!

acme on 2005-04-01T06:20:17

In my previous journal entry, I talked about amusing comments or bits of code I found in the Perl debugger. Now, you might wonder what sort of insane person would look inside perl5db.pl for fun? Well, I blame obra. Not only did he mention that someone should write a new debugger for Perl, he also told me this while I had a laptop to hand and he handed me a beer.

What's wrong with the existing Perl debugger, you ask? Well, it's a bit, errr "crufty". It's grown organically, is quite huge, doesn't have a test suite, and contains amusing comments. For some reason, I was dreaming of an object oriented interface to debugging a program, which would make writing debugger front-ends easy.

So, like any good little extreme programmer, I sat down and wrote a few tests before writing any code:

my $ebug = Devel::ebug->new;
$ebug->program("t/calc_oo.pl");
$ebug->load;
is($ebug->line, 7);
is($ebug->filename, 't/calc_oo.pl');
$ebug->step;
is($ebug->line, 8);
is($ebug->filename, 't/calc_oo.pl');
$ebug->next;
is($ebug->line, 9);
is($ebug->filename, 't/calc_oo.pl');
$ebug->run;
is($ebug->finished, 1);

Well, there were more tests. I mean, there's quite a few things you might want to do in a debugger, like set break points (with conditions), set watch points (conditions sans a line number), inspect variables, evaluate code, return from subroutine and more.

So I sat up late into the night, hacked on Perl code, and a few hours later had a new Perl debugger with tests and documentation. I reckon autrijus' energy must be rubbing off onto me.

And then I wondered what kind of interface you might want. I mean, having a console interface to a debugger, but it's not really exciting and I hate having to remember that "b code.pl 6 $x > 7" sets a break point at line 6 of code.pl where it'll only stop if $x > 7. So then I thought about GUIs, and I played a little bit with Curses::UI speccing out an interface, but I decided it wasn't quite flexible enough. Gtk2 might well be the way to go, but I thought that we all have web browsers, and with JavaScript thesedays we have the technology to make nice rich web interfaces. Thus I designed a sample web interface which shows off the main features a debugger would have.

So I threw a few modules together and built that very web app that you see in the screenshot above. Actually, I spent more time making "s" keystrokes automatically "step" using JavaScript than I spent building the web application. I guess I should brush up on my Ajax skills.

Ok, so it doesn't do everything you might want a debugger to do, but I did manage to build a complete Perl debugger in a few hours, which has a nice OO interface, and a web frontend. Neat, huh?

Of course, what's really scary is that this isn't an April Fool's joke. It's actually on CPAN as Devel::ebug. Patches welcome. Enjoy.


Looks Great!

malte on 2005-04-01T10:30:15

This looks really great. How are the possibilities of hooking this one into a running CGI or even mod_perl process?

Re:Looks Great!

acme on 2005-04-01T11:25:36

It's absolutely possible.

Re:Looks Great!

malte on 2005-04-01T18:16:12

Would it work this way:

I tell a CGI script to run under -d:ebug. Then the debugger tells me about the secret and port number, which enables me in turn to connect to that debugging session.

This method doesnt seem to be directly supported by the module, but I am probably missing the point.

AWESOME

davebaker on 2005-04-01T17:19:40

Can I buy you another beer? :)

THANKS!

Re:AWESOME

acme on 2005-04-02T00:25:10

Sure. Mine's a foamy one.