Subject: Re: C Hacker Question

From: avijit ghosh <[email-masked]>
Date: Fri, 28 Jun 2002 16:34:08 -0400 (EDT)

>Folks,

>Does anybody know a way to determine the name of the calling
>routine from C - Routine A calls Routine B, and B wishes to know
>the name of whatever routine called it...

>If it's a real hack, something which works on Linux (or Linux and SGI)
>would do the trick. Pointers to these kinds of programmer tricks
>are appreciated as well!

	This is a bit off the top of my head but what I would do is write 
a simple perl script (or perhaps you could just do it w/ defines) that 
appends to all your C calls __FUNCTION__ as the last argument. This is a 
gnu extension that tells you the name of the current routine. The same 
perl script would also append to each function declaration a   char 
*whoCalledMe). To make things easy use a define that does nothing for your 
perl script to snag the subroutines you want appended in this manner .

i.e

	DEBUGME(myfunction)(double x,double y, double z);

(so parse twice once for subroutine names and then for calls). Of course 
now your  code is dependent on a perl script (never good!) but hopefully 
this is for  debugging so you it'll only be embarrassing for yourself :)
You could probably make a few defines so as to leave the code in but 
compiled out at will as well as  for printing the caller subroutine name 
trivially.

There is probably an equivalent trick for fortran (or any other  language) 
that could be worked out.

	Best regards,
	-avi