Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I plant assembly instructions in the prologue and epilogue of function via gcc

Tags:

c

gcc

embedded

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.

like image 297
user2066340 Avatar asked Feb 13 '13 09:02

user2066340


People also ask

What is the function prologue and epilogue in assembly language?

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 .

What is Assembly-logical instructions?

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.

What does a prologue do in C++?

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.

What are the instructions for stack operations in assembly language?

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.


1 Answers

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.

like image 177
Michael Avatar answered Sep 24 '22 05:09

Michael