Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/3/84; site ariel.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxt!houxm!whuxl!whuxlm!akgua!akguc!mtunh!mtuni!mtune!ariel!neal From: neal@ariel.UUCP (NEAL T. NUCKOLLS) Newsgroups: net.unix-wizards Subject: need virtual text address Message-ID: <1099@ariel.UUCP> Date: Tue, 11-Mar-86 13:47:59 EST Article-I.D.: ariel.1099 Posted: Tue Mar 11 13:47:59 1986 Date-Received: Sat, 15-Mar-86 04:01:29 EST Distribution: net Organization: AT&T-ISL, Holmdel, NJ Lines: 49 Here's an interesting little problem I thought someone out there might have solved before: I'm implementing a general purpose trace (debug) function which will be called with several arguments (like printf) and print these to stderr. Naturally, I'd like the function name printed along with the message and, naturally, I'd like not to have to explicitly pass the function name as in: foo() { mytrace("foo", ...); } An interesting scheme to obtain the function names at runtime is to use a virtual text address to lookup in a table of previously sorted function name/value pairs obtained from the a.out symbol table. But I need the address. Various methods of obtaining an address haven't quite worked out: 1. #define trace(...) somelabel: mytrace(..., somelabel) Nice idea but you get multiply defined "somelabel"'s. Need a unique string on each cpp macro expansion. 2. #define trace(...) {somelabel: mytrace(..., somelabel);} Unfortunately, the lexical scope of a label is global to the entire function - not just the block. 3. #define trace(...) __LINE__: mytrace(..., __LINE__) I though I'd had something here but __LINE__ expands to a purely numeric string and does not begin with an alphabetic. This idea might still work if I could somehow prefix __LINE__ with a character... 4. Lots of nonportable "solutions" like asm("mov pc, r11") or having the called function look in its call frame for the return address - but I don't want to resort to this. Basically, I need a virtual address anywhere within the current active function for this address-->function_name translation scheme to work. Any ideas on this theme? Actual problem: The same thing but from within the kernel. Please reply via mail. Thanks. Neal Nuckolls ATT-IS, MT-1A405 [NAC]!ariel!neal