Stories
Slash Boxes
Comments

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

acme (189)

acme
  (email not shown publicly)
http://www.astray.com/

Leon Brocard (aka acme) is an orange-loving Perl eurohacker with many varied contributions to the Perl community, including the GraphViz module on the CPAN. YAPC::Europe was all his fault. He is still looking for a Perl Monger group he can start which begins with the letter 'D'.

Journal of acme (189)

Friday April 01, 2005
02:20 AM

A new Perl debugger!

[ #23967 ]
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.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.