This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: How to create a plugin to instrument function calls
- From: Ian Lance Taylor <iant at google dot com>
- To: "Paul Sery" <pgsery at swcp dot com>
- Cc: <gcc-help at gcc dot gnu dot org>
- Date: Mon, 21 Sep 2009 17:15:16 -0700
- Subject: Re: How to create a plugin to instrument function calls
- References: <twig.1253563710.54334@swcp.com>
"Paul Sery" <pgsery@swcp.com> writes:
> I want to create a plugin that inserts custom code before function calls. The
> plugin would mimic the way fprofile-arcs instruments function calls, but not
> other structures. For instance, I'd like to modify the following code,
>
> ..
> void main(...) {
> f1();
> f2();
> }
>
> as follows,
>
> ..
> void main(...) {
> _mystuff('f1');
> f1();
> _mystuff('f2');
> f2();
> }
>
> I think/guess the best place for this to occur is in the assembler, like
> finstrument-functions?
The assembler is an OK place to hack things which change the function
prologue or epilogue. It sounds like you want to change the actual body
of the function, which is quite different. I would suggest working at
the GIMPLE level instead, and modifying function calls there.
Ian