views:

160

answers:

2

I'm working with a big, old, messy, bloated framework. It regularly goes well over 100 levels deep in subroutine calls. The Perl debugger sees fit to stop and inform me of this fact... over and over again.

Package::Stash::name(/usr/local/perl/5.10.1/lib/site_perl/5.10.1/Package/Stash.pm:21):
21:     return $_[0]->{package};
100 levels deep in subroutine calls!
  DB<1> 

How do I make the Perl debugger not care about how big the stack is?

Thanks.

+19  A: 

Add the line:

$DB::deep = 500; # or more if necessary

to the start of your program.

The following program runs to completion in the debugger:

use strict;
use warnings;
sub f($) {
        my $x = shift;
        print "$x\n";
        if ($x < 200) {
                f(1 + $x);
        }
}
$DB::deep = 500;
f(1);

outputting:

198
199
200
Debugged program terminated.  Use q to quit or R to restart,
  use o inhibit_exit to avoid stopping after program termination,
  h q, h R or h o to get additional info.
  DB<1> _

Without the $DB::deep = 500; line, it stops at 100, the same as yours:

97
98
99
main::f(qq.pl:4):               my $x = shift;
100 levels deep in subroutine calls!
  DB<1> _

That's been tested successfully up to a stack depth of 50,000 (use 50000 in the if statement and set $DB::deep to 50001). If your stack depth is greater than that, I suspect you should be re-engineering rather than debugging :-)

By the way, if you don't want to touch the code at all, you can change that value in the debugger before running your code - just enter $Db::deep=500; before you enter c to run the code, or just set it in your .perldb file:

BEGIN {$DB::deep = 500;}
paxdiablo
Oooh, undocumented global variable! I see its mentioned in perldebguts but not DB.pm where it should be. I'll patch that in, thanks. Do you know if there's a way to control this in the `.perldb` configuration file?
Schwern
@Schwern, see the update. I tried putting the assignment into a `BEGIN` section in the `.perldb` file and it seemed to work fine. And the quote from `man perldebug`: "Note that any variables and functions that are not documented in this document (or in perldebguts) are considered for internal use only, and as such are subject to change without notice." - I take that to read that stuff mentioned in `perldebguts` is okay to use as well.
paxdiablo
+2  A: 

Schwern: as noted in the comments to the "best answer", it's definitely part of a poorly documented system. However, if you really want to help out here, take a look at DB::Pluggable and my DB::Pluggable::Dumper plugin for it. There's tons of great work which can be done to make the debugger almost fun to work with.

Ovid