Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: ubun2os on July 13, 2012, 01:33:21 pm

Title: debugging and tracing Recursive functions
Post by: ubun2os on July 13, 2012, 01:33:21 pm
i want trace recursive functions and i used Call stack for this idea. for example for the following code:
Code
#include <iostream>

using namespace std;
long power(int , int );
int main()
{
    cout<<power(2,3)<<endl;
    return 0;
}
//a power b as recursive
long power(int a , int b)
{
    if (b==0) return 1;
    return a*power(a,b-1);
}
i run program until line [ if (b==0) return 1;] with F4 key. when cursor go to next line(i.e [    return a*power(a,b-1);   ] ), i use step into that function appear in call stack but when return from stack (for any call) does not show me any return value.
in VS, in call stack had return value when return from function and stack.

you how to trace recursive functions ?
please help me.
Title: Re: debugging and tracing Recursive functions
Post by: oBFusCATed on July 13, 2012, 02:50:06 pm
Simplest way is to modify you function to store the result in a variable.
Title: Re: debugging and tracing Recursive functions
Post by: killerbot on July 13, 2012, 02:55:36 pm
I think it would be very good to show such things, I have no clue if gdb can tell you the return value (i assume it can), this is a feature I have been missing since for a very long time since I abandoned VC. And it is just not recursive methods, it could be you ca nhave a stetment like .. return someOtherMethod();

How hard is it to have this in place, the return value could be printed out either int watch window, or in the debug pane at the bottom.

Title: Re: debugging and tracing Recursive functions
Post by: oBFusCATed on July 13, 2012, 03:48:40 pm
How hard is it to have this in place, the return value could be printed out either int watch window, or in the debug pane at the bottom.
As far as I can see there is no command that prints it, but the finish/step and the like commands print it as part of their output.
I don't think it is an easy feature to add. :(
Title: Re: debugging and tracing Recursive functions
Post by: Radek on July 14, 2012, 04:12:56 pm
If you can see the contents of something more than a named variable then it is always an extra of a particular debugger. Don't count on it an patch your code as oBFusCATed has said. At least, for debugging purposes. As far as your code is concerned, the return value is an anonymous place on the stack. Either the debugger itself (not the GUI interface) allows you to see its contents or you have no chance - there is no "handle" to the place. Moreover, the return value can be passed in a register and used immediately, so that there is no place on the stack at all.