Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!lll-crg!hoptoad!tim From: tim@hoptoad.uucp (Tim Maroney) Newsgroups: comp.lang.c,comp.unix.wizards Subject: Re: who called a C routine - get it from the stack frame Message-ID: <1436@hoptoad.uucp> Date: Sat, 6-Dec-86 13:25:51 EST Article-I.D.: hoptoad.1436 Posted: Sat Dec 6 13:25:51 1986 Date-Received: Sun, 7-Dec-86 03:37:27 EST References: <810@hropus.UUCP> <961@cuuxb.UUCP> Reply-To: tim@hoptoad.UUCP (Tim Maroney) Distribution: comp Organization: Centram Systems, Berkeley Lines: 22 Xref: mnetor comp.lang.c:280 comp.unix.wizards:272 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@lll-crg (arpa)