function instrumentation

Ian Lance Taylor iant@google.com
Fri Jan 27 16:55:00 GMT 2012


ratheesh kannoth <ratheesh.ksz@gmail.com> writes:

> I would like to instrument cpp file using finstrument functions. I
> have written all the files and build script.
> I noticed that  - the moment i add   iostream header file into
> test.cpp file , the program segmentaion faults.

> void __cyg_profile_func_enter (void *func,  void *caller)
> {
>      helloworld() ;
> }

> int   helloworld ()
> {
>   std::cout << "hello " ;
> }

The compiler inserts a call to your profiling function before every
function.  Your profiling function calls std::cout::operator<<.  That
function inlined into your code from <iostream.h>, and the compiler
inserts a call to the profiling function at the start of it.  Thus you
have an infinite recursion and your program crashes when it overruns the
stack.

Ian



More information about the Gcc-help mailing list