I have following requirement:
- Adding text at the entry and exit point of any function.
- Not altering the source code, beside inserting from above (so no pre-processor or anything)
For example:
void fn(param-list)
{
    ENTRY_TEXT (param-list)
    //some code
    EXIT_TEXT
}
But not only in such a simple case, it'd also run with pre-processor directives!
Example:
void fn(param-list)
#ifdef __WIN__
{
  ENTRY_TEXT (param-list)
  //some windows code
  EXIT_TEXT
}
#else
{
    ENTRY_TEXT (param-list)
    //some any-os code
    if (condition)
    {
        return; //should become EXIT_TEXT
    }
    EXIT_TEXT
}
So my question is: Is there a proper way doing this?
I already tried some work with parsers used by compilers but since they all rely on running a pre-processor before parsing, they are useless to me.
Also some of the token generating parser, which do not need a pre-processor are somewhat useless because they generate a memory-mapping of tokens, which then leads to a complete new source code, instead of just inserting the text.
One thing I am working on is to try it with FLEX (or JFlex), if this is a valid option, I would appreciate some input on it. ;-)
EDIT: To clarify a little bit: The purpose is to allow something like a stack trace. I want to trace every function call, and in order to follow the call-hierachy, I need to place a macro at the entry-point of a function and at the exit point of a function. This builds a function-call trace. :-)
EDIT2: Compiler-specific options are not quite suitable since we have many different compilers to use, and many that are propably not well supported by any tools out there.
 
     
     
     
    