Simple config for the perl debugger

I’ve been using a config file ($HOME/.perldb) for some time now. While it’s not the biggest file in the world it automates settings that I’m far too lazy to type every time I fire the beast up.

.perldb

$DB::deep=1000 ;
sub afterinit { push @DB::typeahead, "{{v" unless $DB::already_curly_curly_v++; } ;
parse_options('dumpDepth=2 NonStop=1') ;

The Explanation

$DB::deep=1000

This increases the limit for the recursion limit from 100 - a level that’s so low I seemed to be hitting it all the time

sub afterinit { … }

I like ‘v’ as a way of seeing where I’m at in the code, with some context. I hate typing it myself every time the debugger returns to the prompt.

This small piece of voodoo simply pushes the command ‘{{v’ onto the list of things to do when the debugger has finished initialising. ‘{{’ is “Add to the list of debugger commands to run before each prompt” and ‘v’ is “View window around line”.

Until recently the command was just

sub afterinit { push @DB::typeahead, "{{v" } ;

This was annoying if you used ‘R’ to restart the script you were debugging as you’d call ‘{{v’ again and force an extra ‘v’ at every prompt. This would increase every time you used ‘R’.

The variable is forced into the DB:: namespace otherwise you’d increment a value scoped to the afterinit() sub.

parse_options(‘dumpDepth=2 NonStop=1’)

Set a couple of useful options:

  • dumpDepth=2 limits the depth of variables shown if you use ‘x’ or similar on a variable. Especially useful if you’re forever accidentally examining DBIx::Class objects.
  • NonStop=1 saves you from having to type ‘c’ after everything has initialised so that your program will run. Useful if you drop in $DB::single = 1 statements as your initial breakpoint in the source.

6 Comments

I like that 'v' on every step a lot! Thanks for the tip

sub afterinit { push @$DB::pretype, 'v' }

This worked for me:


sub afterinit { push @$DB::pretype, 'v' unless grep { /v/ } @$DB::pretype; } ;

Leave a comment

About Chisel

user-pic I blog about Perl.