| Packages Used |
|
ptkdb: http://www.perl.com/CPAN/authors/id/A/AE/AEPAGE/
|
Many modern programming languages have debuggers, which let you examine the internals of your program as it runs. You can query the contents of variables to see how they change, or monitor how often a subroutine is called. My debugger, ptkdb, is a visual debugger. It lets you examine a variable's contents by moving your cursor over it, and it lets you set breakpoints with the click of a mouse. (A breakpoint is a position in your program where the debugger stops execution and lets you inspect your program's data structures.)
There are other visual debuggers for Perl. SolutionSoft and ActiveState each make one, but they're only for Windows, and they're not free, like ptkdb. Because ptkdb is written in Perl/Tk, it works on all flavors of Unix as well as Windows. Figure 1 shows ptkdb in action.
Figure 1
perl -d myprogram.pl
Or, to enter the debugger directly without a program at all,
perl -de 0
This is handy if you just want to execute a series of Perl statements without creating an actual program.
When you run a program with the -d switch, Perl stops at the first line of code and displays a prompt. You can find out all of the options by typing h for help. Perl's debugger might be all you ever need, but if you want the convenience of a graphical debugger, you can install ptkdb.
perl Makefile.PL
make
make test
make install
Or, you can use the install_ptkdb.pl program, which uses a Perl/Tk user interface to guide you through the process.
If you're unable to install ptkdb into your system's Perl library, you can run ptkdb from the directory where you invoke Perl:
cd myprogramdir
mkdir Devel
cp ptkdb.pm Devel
perl -d:ptkdb myprogram.pl
perl -d:ptkdb myprogram.pl
The ptkdb window will appear and the first executable line of your program will be highlighted. At this point the debugger has stopped the program and is waiting for your command. If you use #!/usr/bin/perl (or an equivalent) to invoke your Perl program, you can add the -d:ptkdb immediately afterwards to invoke the debugger from inside the program.
Figure 1
Figure 3
Figure 4
If you're using the X window system, you can customize fonts and colors with X resources. This includes fonts and colors; see your system's xrdb documentation for instructions. Windows users can now add X resources if their version of Perl/Tk is 800.012 or higher. Fonts can be selected with the xfontsel utility.
For example, say you wish to change the font that the code is displayed in. Open the .Xdefaults or .Xresources file in your $ENV{'HOME'} directory and add the following line: ptkdb.frame2.frame1.rotext.font: fixed. (Change fixed to whatever font specification you would like to use.) Other fonts can be set individually, or you can use ptkdb*font to specify all of them. The documentation contains a commented example section of .Xdefaults that you can use as a guide.
In order to use ptkdb with your web server you have to have Perl/Tk and ptkdb installed in the same place that your server is getting its Perl libraries from, which isn't always the case in some installations. If all else fails, you can always create your own private installation of Perl (called, say, myperl), Perl/Tk, and ptkdb - about 18 meg in all. If you are going to be debugging on a different workstation than the web server using X, make sure that the web server has permissions to open XWindows on your workstation; typically this just requires you to type xhost +webserverName.
At the top of your CGI program you probably have a line such as this:
#!/myperlPath/perl
Change it to:
#!/myperlPath/perl -d:ptkdb
If you're on a different workstation than the web server you'll have to add this subroutine to the beginning of your CGI file:
sub BEGIN {
$ENV{'DISPLAY'} = 'myWorkStation:0.0';
}
This subroutine will be executed before the debugger is invoked, setting the display to your workstation for the ptkdb debugging window to appear. Once all of this is set up, open the web page that invokes your CGI program. It will take a few seconds for the debugger to load and bring up the window. When the window opens on your workstation, you're ready to debug.
The current plan is to allow version 1.10X to mature and stabilize. Bugs will be fixed and minor incremental improvements added. Version 1.2 will provide listings of lexical variables, better Perl/Tk application debugging, and perhaps actions or watchpoints, if enough people ask for them. Once these have been added, tested, and deployed, ptkdb 1.2 may find its way into the Perl/Tk distribution, if the Perl/Tk group is willing.
Version 2.0 is being planned: a top to bottom rewrite of the entire system. The goal is to let third parties add independent modules to ptkdb. This would open up the ptkdb project to people who wish to contribute in a way that won't chain ptkdb to the success or failure of their individual efforts.
__END__