need virtual text address
NEAL T. NUCKOLLS
neal at ariel.UUCP
Wed Mar 12 04:47:59 AEST 1986
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
More information about the Comp.unix.wizards
mailing list