Author Topic: debugging and tracing Recursive functions  (Read 13971 times)

Offline ubun2os

  • Single posting newcomer
  • *
  • Posts: 7
debugging and tracing Recursive functions
« 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.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: debugging and tracing Recursive functions
« Reply #1 on: July 13, 2012, 02:50:06 pm »
Simplest way is to modify you function to store the result in a variable.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5490
Re: debugging and tracing Recursive functions
« Reply #2 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.


Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: debugging and tracing Recursive functions
« Reply #3 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. :(
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Radek

  • Multiple posting newcomer
  • *
  • Posts: 104
Re: debugging and tracing Recursive functions
« Reply #4 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.