who called a C routine - get it from the stack frame

Tim Maroney tim at hoptoad.uucp
Sun Dec 7 04:25:51 AEST 1986


There is a portable and clean way to implement a routine finding out the
address of its caller in a few lines of code.  It involves no assembly
language or machine assumptions.  Simply pass the address of the calling
routine as an argument to the routine that needs the address.

foo()
{
	nmuser(foo);
}

nmuser(f)
int (*f)();
{
	/* whatever you are doing using nm */
}

This can be fooled, but an assembly-language caller can easily fool the
other scheme as well by putting a spurious return address on the stack.
-- 
Tim Maroney, Electronic Village Idiot
{ihnp4,sun,well,ptsfa,lll-crg,frog}!hoptoad!tim (uucp)
hoptoad!tim at lll-crg (arpa)



More information about the Comp.unix.wizards mailing list