Re: Debug recursion ?
by Zaxo (Archbishop) on Feb 24, 2007 at 19:15 UTC
|
One way would be to set the exit condition by hand.
You could get a specific answer if you showed us your code.
| [reply] |
|
|
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 ? | [reply] [d/l] |
|
|
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
| [reply] |
|
|
|
|
|
|
Re: Debug recursion ?
by ysth (Canon) on Feb 25, 2007 at 03:36 UTC
|
What do you mean by "return from the recursive function"? Do you mean just leave the debugger prompt and resume execution? If so, use "c", not "r".
| [reply] |
|
|
I don't know how to make this any clearer.
Assume this general example : you debug code and the code reaches a subroutine call. Next the debugger enters the subroutine code , and shows you the subroutine body , one instruction/statement at a time. If you don't want to go through the subroutine , you can press r , and the code continues it's execution after the subroutine call. That's the same thing I need help with the deep recursion subroutine call.
| [reply] |
|
|
If you don't want to go through the subroutine , you can press r , and the code continues it's execution after the subroutine call.
I'm not sure if you are confused in how you are presenting it or confused in your understanding. r makes the code resume execution right where it was, but without the debugger in single-step mode, reverting to single-step mode in the current function's caller. Or that's what it's supposed to do; as you noticed, it doesn't
seem to work correctly when the debugger breaks with "100 levels deep...".
You've tried to clarify what r does; but I was asking for more information about what you are trying to do.
Try removing any function calls from your return statements; in your example, make it
$n *= fact($n-1);
return $n;
(without doing this, r doesn't do anything helpful, even without the deep calls) then use r repeatedly until you are out of dumvar:: and back into your code.
| [reply] [d/l] |
|
|
|
|