I try to build profiler to some c project. I want that gcc plant some assembly instruction in all the function entries and function exit points in compile time. I try to search some guides in the web but without success. where can I learn how to do that?
thank in advance.
The prologue and epilogue are not a part of the assembly language itself; they represent a convention used by assembly language programmers, and compilers of many higher-level languages. They are fairly rigid, having the same form in each function. Function prologue and epilogue also sometimes contain code for buffer overflow protection .
Assembly - Logical Instructions. The processor instruction set provides the instructions AND, OR, XOR, TEST, and NOT Boolean logic, which tests, sets, and clears the bits according to the need of the program. The format for these instructions −. The first operand in all the cases could be either in register or in memory.
The prologue typically performs such tasks as: saves any registers that the function might use (that are required by the platform's standard to be preserved across function calls) allocates storage on the stack that the function might require for local variables.
Assembly language provides two instructions for stack operations: PUSH and POP. These instructions have syntaxes like − PUSH operand POP address/register The memory space reserved in the stack segment is used for implementing stack.
Apparently you can use the -finstrument-functions
flag to get gcc to generate instrumentation calls
void __cyg_profile_func_enter(void *func, void *callsite);
void __cyg_profile_func_exit(void *func, void *callsite);
at function entry and exit. I've never used this, but a quick search brings up information and examples here, here, here and here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With