7.3. Getting Graphical

Programmers can choose from several graphical interfaces to the Perl debugger. We'll describe two of the free alternatives.[4] We won't provide much detail describing their use since they are simply graphical layers on top of Perl's internal debugger; all you need to do is find the buttons corresponding to the commands just described.

[4] There are a number of commercial (i.e., not free) products offering GUI Perl debugger interfaces and other IDE functionality. We omitted them merely because we didn't want to appear biased toward or against any particular vendor by inadvertently leaving one out.

7.3.1. ddd

ddd, developed by Andreas Zeller, is a GNU graphical interface to many debuggers, including Perl's; obtain it from http://www.gnu.org/software/ddd/ddd.html. No Windows port currently exists, but it builds easily enough on Linux when you download the requisite RPMs or package files. In Figure 7-1, note the breakpoint, current statement pointer, and various displays.

Figure 7-1. ddd used as an interface to the Perl debugger


(The application is an object-oriented program for solving the “N Queens” problem: Print out all the possible ways of placing n queens on an n × n chessboard so that no one is attacked by another.)

7.3.2. ptkdb

ptkdb, developed by Andrew E. Page, is a free, Tk-based, graphical interface to the built-in perl debugger, with a clean and intuitive design. Obtain ptkdb from http://search.cpan.org/search?dist=Devel-ptkdb. It also requires PerlTk by Nick Ing-Simmons (http://search.cpan.org/search?dist=Bundle-Tk).

ptkdb is invoked as a debugger plugin, so to debug myprog.pl, type

perl -d:ptkdb myprog.pl

There is little we need to add to the description of ptkdb. In Figure 7-2, we see that the current line is highlighted, nonbreakable line numbers are struck through, and the tabbed panes on the right are for inspecting expressions, subroutines, and breakpoints. The appearance of the interface can be extensively customized.

Figure 7-2. The ptkdb interface


One key advantage of ptkdb is that it can be used to debug a Perl program used in a CGI process. We give examples of this in Chapter 13.

7.3.3. Emacs

More than a command line, less than a GUI, the free and insanely powerful GNU text editor includes quasi-graphical support for a simple but intuitive interface to the perl debugger via the cperl mode (see Chapter 3). To start a debug session in the active buffer, enter M-x perldb RET, and you'll get something like Figure 7-3, where one subwindow contains the source code, and the other is for interactions with the debugger.

Figure 7-3. The emacs interface to the Perl debugger via cperl-mode


The syntax highlighting is evident in the source code when viewed in color. (Keywords in blue, subroutine prototypes in heavy blue, comments in red, and double-quoted strings in gray; if you don't like any of those assignments, they are easy to change.)

Emacs is available with any Linux system and can be downloaded for virtually any platform from http://www.gnu.org/software/emacs/emacs.html.

Don't overlook the use of debuggers as a teaching tool. I often use ptkdb to monitor the evolution of a variable (scalar, array, hash) as a program executes. Such a demonstration allows a new programer to observe a variable's value and scope in various situations—which is quite useful when you are forced to explain the difference between lexical variables and package variables.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset