Friday, March 18, 2011

Perl debugging

I use and love the perl debugger, it can do lots of nice and useful things, and is very useful to experiment with perl ad-hoc to help un-muddy waters. When I use a new library and I'm not sure about the data-structures or the exact contents of return values I can break the code at the right place, try some Data::Dumper helped print statements and formulate new code that helps me complete the code section.


But sometimes I find myself working in code where a dozen or more variables hold various values that need to go in a dozen places. If I've used the wrong one in one place I'm of course screwed. WTF, which variable held the right variant of the value? Working on router configurations I find I start with "interface FastEthernet0/1.346" and after a call or two the name has been exploded into "FastEthernet0/1.346", "fa", "fa0/1", "fa0/1.346", "346", and half a dozen of other variables holds various facts about the interface. And then the right name must be used in the right SQL queries. I hate having to type all the "p" statements to figure out which value to use where.

This made me deam of the Turbo Pascal 5-6 IDE I've used on MS-DOS back in the 1980ies. It had a watch variable window pane with continous updates. I often run perldb inside emacs to make some modes of debugging smoother, and the Emacs debugger mode supports watch variables - BUT only with gdb as debugger. After some googeling I found "pdkdb". It's a TK based GUI debugger for perl. It looks rather clunky and reminiscent of X programs of the early 1990ies but it has the watch variable window pane and convenient step over/step into/return/run buttons to control program execution. Lines can be made breakpoints by clicking on the line number. And if you mouse over a variable name there is a popup showing the contents of that variable. Excellent!

$ perl -d:ptkdb ./tester

Project page at sourceforge.