Function Instrumentation

Venetis Ioannis venetis@ceid.upatras.gr
Sat Jun 17 02:20:00 GMT 2000


>   I noticed the "-finstrument-functions" flag, and I was wondering if
it's
> currently working (on Linux x86 platforms).  Test programs I compile
(with
> dummy __cyg_profile_func_enter/exit routines) pretty much always seem to
> core dump.  Is there somewhere I could get more information?
>   Thanks a lot!
> --John Zedlewski

This is because you have the __cyg_profile_func_enter() and
__cyg_profile_func_exit() functions in the same source file with other
functions of your program. When you compile the source with the
-finstrument-functions flag these 2 functions will be also instrumented,
which means that they will be called recursevily and you will get a stack
overflow and of course a core. You have 2 options to solve this :

1) Put these 2 functions in a seperate source file, compile this file
   without the -finstrument-functions flag and link together all the
   object files.

2) A better way is to declare these 2 functions like this :

void  __attribute__((__no_instrument_function__))
__cyg_profile_func_enter(void *this_fn, void *call_site)
{
 printf("func_enter() : this_fn = %p, call_site = %p\n",
 this_fn, call_site);
} 

and:

void __attribute__((__no_instrument_function__))
__cyg_profile_func_exit(void *this_fn, void *call_site)
{
 printf("func_exit()  : this_fn = %p, call_site = %p\n",
 this_fn, call_site);
} 

gcc will not create calls to the instrumentation functions for all the
functions which have the no_instrument_function attribute. With this, you
can leave the profiling functions in the same source file with all other
functions you have.

Hope this helps.

Ioannis E. Venetis



More information about the Gcc mailing list