Question about modifying gcc

Andrew Haley aph@redhat.com
Thu Jun 5 20:01:00 GMT 2008


Redirected to gcc-help.

dreese@vandals.uidaho.edu wrote:
> Could you please direct me to someone who would be willing and able to answer a few questions about some of the internal workings of the gcc compiler. 
> 
> I am attempting to modify the compiler to instrument function calls and returns. The end result that i am trying to achieve is to send the address of every called function to a memory mapped file prior to the call and after the call send an immediate value to that same file. The target architecture is x86.
> 
> Here is an example in pseudo assembly of what i want to accomplish.
> 
> 
> regular                          modified
> instruction                      instruction
> instruction                      instruction
>                                     mov $function-name, (eax)
> call function-name          call function-name
>                                     move $0x1000, (eax)
> instruction                      instruction
> instruction                      instruction
> 
> where eax is the address of the memory mapped file.
> 
> 
> The purpose of this is to collect information about calls and returns in order to build call graphs and operating tendencies of software systems. 
> 
> So far i have had little success.
> 
> I have been trying to change the machine description as well as the target description macros and function in order to get the desired functionality. I have been able to insert instruction into the compiled code, via output_asm_insn(), but not in the correct place. 

Have a look at the docs for the gcc option `-finstrument-functions'.

Andrew.



More information about the Gcc-help mailing list