public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* How to create a plugin to instrument function calls
@ 2009-09-21 20:08 Paul Sery
  2009-09-22  0:15 ` Ian Lance Taylor
  0 siblings, 1 reply; 3+ messages in thread
From: Paul Sery @ 2009-09-21 20:08 UTC (permalink / raw)
  To: gcc-help

Hi,

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? 

I've got the basic plugin mechanics working under gcc 4.5 - i.e.,
dumb_plugin.c from testsuite - and would appreciate any suggestions about how
to proceed from here.

Regards,
Paul

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How to create a plugin to instrument function calls
  2009-09-21 20:08 How to create a plugin to instrument function calls Paul Sery
@ 2009-09-22  0:15 ` Ian Lance Taylor
  2009-09-22 18:05   ` How to create a plugin to instrument function calls? Paul Sery
  0 siblings, 1 reply; 3+ messages in thread
From: Ian Lance Taylor @ 2009-09-22  0:15 UTC (permalink / raw)
  To: Paul Sery; +Cc: gcc-help

"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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How to create a plugin to instrument function calls?
  2009-09-22  0:15 ` Ian Lance Taylor
@ 2009-09-22 18:05   ` Paul Sery
  0 siblings, 0 replies; 3+ messages in thread
From: Paul Sery @ 2009-09-22 18:05 UTC (permalink / raw)
  To: gcc-help

Ian Lance Taylor <iant@google.com> said:

> "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,
> > ...
> > 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.
> 
Ok, I'll go that route. Can I use the single function like the
finstrument-functions option uses?
  ...
  profile_function_entry_libfunc
    = init_one_libfunc ("__cyg_profile_func_enter");
  --->
  profile_function_entry_libfunc
    = init_one_libfunc ("__myfn");

or perhaps I should mimic the way the gcov option works?
   ...
   = build_function_type_list (void_type_node,...
   = build_fn_decl ("__gcov_interval_profiler",
   ...

Thanks,
Paul

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-09-22 18:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-21 20:08 How to create a plugin to instrument function calls Paul Sery
2009-09-22  0:15 ` Ian Lance Taylor
2009-09-22 18:05   ` How to create a plugin to instrument function calls? Paul Sery

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).