Write your own debugger commands. Adding a command to the debugger (or modifying an existing one) by editing the debugger is a difficult job; to do this, you have to patch the debugger source in perl5db.pl and replace it. Sometimes you don't have the necessary privileges to do this, and given the complexity of the debugger, it's a difficult jobespecially because you can't debug the debugger. Yet modifying your tools the way you want them is important. Fortunately, Devel::Command module makes this much simpler. With Devel::Command, you write simple modules to define your commands, and the debugger finds them and loads them for you automatically. The HackWriting a command is simple. There are only a few things to remember:
A "hello, world" command looks like: package Devel::Command::HelloWorld; use base 'Devel::Command'; sub command { print DB::OUT "Hello world!\\n"; 1; } 1; Devel::Command defaults to using the command( ) as the actual command code. Run this by putting it somewhere in your @INC and then start the debugger: flatbox ~ $ perl -de0 Default die handler restored. Patching with Devel::Command::DBSub::DB_5_8 Loading DB routines from perl5db.pl version 1.07 Editor support available. Enter h or \Qh h' for help, or \Qman perldebug' for more help. main::(-e:1): 0 DB<1> cmds cmds helloworld DB<2> helloworld Hello world! DB<3> q flatbox ~ $ The message that begins Patching with... lets you know that Devel::Command has successfully activated. cmds lists the commands and typing helloworld runs your command. Overriding a debugger commandOverriding a command is simple: just return true if your command routine wants to handle the command or false if you don't. package Devel::Command::X; use base 'Devel::Command'; sub command { my ($cmd) = @_; if ($cmd =~ /x marks/) { print DB::OUT "Arrrrr....\\n"; return 1; } else { return 0; } } 1; Now the x command knows to be piratical when it sees a command beginning with x marks. flatbox ~ $ perl -de0 Default die handler restored. Patching with Devel::Command::DBSub::DB_5_8 Loading DB routines from perl5db.pl version 1.07 Editor support available. Enter h or \Qh h' for help, or \Qman perldebug' for more help. main::(-e:1): 0 DB<1> $x = [1,2,3] DB<2> x $x 0 ARRAY(0x804e2f4) 0 1 1 2 2 3 DB<3> x marks the spot Arrrrr.... DB<4> q flatbox ~ $ Running the HackCreate a module in the Devel::Command:: namespace. Install Devel::Command from CPAN, and then tell the debugger to load it by adding one line to your debugger initialization file, .perldb (or perldb.ini, for non-Unix systems): use Devel::Command; That's it. This makes the debugger automatically search @INC for modules in the Devel::Command:: namespace, load them, and install them as commands. By default, it picks a name for the command by downcasing the last namespace qualifier (so, for example, Devel::Command::My::DoStuff ends up as the dostuff command). Devel::Command also installs its own cmds command, which lists all commands that it found and loaded, and dynamically patches the debugger's command processing subroutine with a modified version which knows how to find the commands installed by Devel::Command. Hacking the HackTo develop tests while using the debugger, try the Devel::Command::Tdump module on CPAN. This module loads Test::More for you and lets you actually write tests and save them from the debugger. If you want to see drawings of your data structure in the debugger, Devel::Command::Viz and the graphviz package will let you do it. Install those, then use the viz command on a variable: flatbox ~ $ perl5.8.5 -de0 Patching with Devel::Command::DBSub::DB_5_8_5 Loading DB routines from perl5db.pl version 1.27 Editor support available. Enter h or \Qh h' for help, or \Qman perldebug' for more help. main::(-e:1): 0 DB<1> use WWW::Mechanize DB<2> $m = WWW::Mechanize->new( ) DB<3> viz $m You'll see a graphical depiction of the WWW::Mechanize object in a pop-up window. |