function call

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View

is there any method to find who called a particular function at runtime?(may
be some kind of printing address.then mapping from file!!)


Re: function call
The way I do it is to use a wrapper function call with a macro.

#define doit(a) wrapper( (a), __FILE__, __LINE__ )

doit( int arg )
    // do something

wrapper_doit( int arg, char *where1, int where2 )
    printf( "%s %d\n", where1, where2 );
    doit( arg );

All calls to doit will be rerouted to wrapper_doit and will printout the
file and line number where the call is.


Re: function call
You can use the gcc function "void * __builtin_return_address (unsigned
int level)" function. The with level 0 it returns the address where the
function that used __builtin_return_address returns to. For e.g., f1()
called f2() and f3() and f3() called __builtin_return_address then with
level 0 it returns the address of the next instruction in f2() after
f3() call.


Site Timeline