function call

Hi,

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

Thanks

Reply to
Uday
Loading thread data ...

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.

Bill

Reply to
Bill Touchstone

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.

KIRAN

Reply to
k.mukkamala

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.