Hello.
I want to get function call depth, for example
int main()
{
int j=0;
for(j=0;j<10;j++)
printf("%i",d1(j));
return 0;
}
int d2(int i)
{
if(i<=1)return i;
else
return i*d1(i-1);
}
int d1(int i)
{
if(i%2==0)return d2(i/2);
return i;
}
Tree will look like:
main
->
d1
-->
d2
->
d1
->
d1
-->
d2
--->
d2
The main problem, that i mustn't be done with puting trigger function in every code part.
int d2(int i)
{trigger();
if(i<=1){trigger();return i;}
else
{trigger();
return i*d1(i-1);}
}
And should look like
int d2(int i)
{trigger();
if(i<=1);return i;
else
return i*d1(i-1);
}
I think to do it using stack address like(build own call stack and compare function addresses):
trigger()
{
int i=0;
if(current_thread.address[last_address]=>&i)
{
while(current_thread.address[last_address--]=>&i)current_thread.depth--;
current_thread.address[last_address]=&i;
}
else
{
current_thread.address[last_address+1]=&i;
current_thread.depth++;
}
}
One of the main purpose to do it without any profiling compilier extensions (libs,etc). Am I right doing such things?