tags:

views:

64

answers:

1

Hi,

Using the instrument-functions flag in gcc, you can instrument the code to execute functions before and after each execution of a function. These functions are __cyg_profile_func_enter and __cyg_profile_func_exit with two parameters, the address of a current function; the second parameter for enter is the address of the call site and for exit the address from which it returns.

Is there a way to obtain the value which was actually returned by the instrumented function ?

+1  A: 

As far as I know, (and by no means quote me on this) in order to get the return value, using __cyg_profile_func_exit we need to set our optimisation flag to -O0, iirc, it doesn't work with degrees of optimisation higher than this due to the fact that -O0 stores the return value in ebx, and higher optimisation flags store the return value in eax; calling eip afterward. So, in order to avoid ebx getting killed by the instrumentation function, we save it when we enter the function, and restore it when we part.

I hope this helps, good luck.

amaterasu
and then i just look at the context of ebx ?
LB
Yes. With the -O0 flag set, right before ebx is popped you should get something similar to: mov 0xfffffffb(%ebp), %eax. Here, the return code copies the content of eax (our return value) into ebx. Simple enough to understand.
amaterasu
I didn't want to go so low... crap
LB