in reply to Re: Debug recursion ?
in thread Debug recursion ?

Let's say a fibonacci function with big numbers , take Damien Conway's example from Perl Hacks , where he talks about Memoize .
If you were to debug the function and set a breakpoint after it , for example :
7:fibonacci(3,10); 8:print "Ok\n";
Presuming the fibonacci function is on line 7 , if you would continue till the 8-th line , the debugger would stop inside the deep recursion ( the same thing happens if you set a breakpoint and then continue till that line ) . How could we exit the function and continue code execution ?

Replies are listed 'Best First'.
Re^3: Debug recursion ?
by GrandFather (Saint) on Feb 24, 2007 at 21:52 UTC

    Your example is still not clear. However, if you have a breakpoint set inside the recursive function and want to stop breaking on it at some point simply remove the breakpoint. If you want to recurse to some depth then break you can typically set a "hit count" for the break point so that it doesn't fire until the line containing the breakpoint has been executed some specified number of times.

    Note too that it is also possible to set a breakpoint that fires when some specific condition is true.

    (This is based on the facilities provided by the Perl debugging in Komodo which I presume uses the standard Perl debugger under the hood.)


    DWIM is Perl's answer to Gödel
      My breakpoint is after the recursive function. But the debugger can't reach that point because of the deep recursion. Here is an example code :
      sub fact { my $n=shift; if($n==0 || $n==1) { return 1; } return $n*fact($n-1); } print fact(107); print "\nOk\n";
      Start the program under the debugger and issue the following command : c 10 ( this should run the debugger to the 10th line , the one with print "\nOk\n" ) Instead , i receive the following message "100 levels deep in subroutine calls!" and using r can't return from the function.

        So why didn't you say that in your initial post? If you provide crap information you will get crap answers - surely you don't expect anything else?

        How about now you post something representative of your real problem?

        At worst you may need to revert to using print statements to trace execution and state rather than using the debugger, but it is likely that there are better ways to tackle your problem. If you tell us what the actual problem is we can help with some appropriate techniques for solving it.


        DWIM is Perl's answer to Gödel

        Right. You're wishing for abnormal flow control. Either that "100 levels deep" call into being a fatal error and catch it or contrive to change $n so that the recursion stops. The latter is trivial in the debugger.

        ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊