I’ve been using the perl debugger a lot more recently and I figure it’s worth noting down a few of the things I’m doing when using it.
The first thing to do is to make sure ReadLine is installed. A cpanm
Term::ReadLine::Perl Term::ReadKey sorts that out. That makes command history work as you’d expect which makes it much more useful.
Then to insert a breakpoint in my code I add a line,
$DB::single = 1;
I then start the debugger up using
PERLDB_OPTS=NonStop to make it run the program until a break point is hit.
If I get automatic breakpoints because of the recursion auto breakpoint
'100 levels deep in subroutine calls!' then I tweak
$DB::deep. This can be done simply by doing a
$DB::deep = 1000 on the debugger command line. Then I can simply restart the debugger using
c command is a really useful one. You can continue to a line in code so you can skip to the bit of code you are interested in really simply. Then you just navigate as usual using
When outputting the contents of a complex object it’s worth knowing that you can limit the number of levels the dump expands out. You do this by simply putting a number after the
x and before the variable name, i.e.
x 2 $var. 2 seems to be a good number to start with while you try to figure out where the information you want is.
The references for the debugger are,