LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Tracing function calls... How? (https://www.linuxquestions.org/questions/programming-9/tracing-function-calls-how-450785/)

ik_nitk 06-02-2006 12:32 AM

Tracing function calls... How?
 
In C++

if you write like this ,

class sample; // contructor prints function name entry line no
// destructor prints function return line no

foo(){
sample s("foo");
...//foo body
}

when we execute this it will print
"calling foo 1245"
"exiting foo 1260"

Now can we do the same thing in C by adding only a single line at the start of the function call.


~ik

graemef 06-02-2006 05:50 AM

You could add a println() or even a macro which will then print out some diagnostics; but maybe I don't properly understand your question.

ik_nitk 06-05-2006 05:53 AM

but maybe I don't properly understand your question
 
Quote:

Originally Posted by graemef
You could add a println() or even a macro which will then print out some diagnostics; but maybe I don't properly understand your question.

Basically , i want to call some trace function's when i enter into the functions and and when i come out of it by adding a single line after the function name.

example.
foo(){
sample("foo");
..
..
..
}

sample("foo") will print "foo" when the function is called and also returned.

basically constructors and destructors function.

i am not sure if it is really possible in C. But it is possible in C++.

~ik

graemef 06-05-2006 07:05 AM

I'm still uncertain because a constructor and destructor are linked to the life of a object not the life of a method (read function).


All times are GMT -5. The time now is 10:24 PM.