[cfe-dev] source-to-source transformation to insert instrumentation calls

Ronan Keryell Ronan.Keryell at silkan.com
Mon Sep 24 09:57:17 PDT 2012


>>>>> On Mon, 24 Sep 2012 18:50:36 +0300, Dmitri Gribenko <gribozavr at gmail.com> said:

    Dmitri> On Mon, Sep 24, 2012 at 6:43 PM, Jan Smets <jan.smets at alcatel-lucent.com> wrote:
    >> That's OK. I'm aware that I won't be 100% accurate.

    Dmitri> OK, good to know.

    >> Now I just need to figure out a good location to insert the call!
    >> :)

    Dmitri> I think that there are cases where inserting instrumentation
    Dmitri> calls will require non-trivial rewriting.  For example:

    Dmitri> int f(int, int);
    Dmitri> int g(int *);
    Dmitri> int test(int *a) {
    Dmitri>    f(*a, g(a));
    Dmitri> }

    Dmitri> Function argument evaluation order is unspecified, so we can
    Dmitri> not simply insert an instrumentation call for *a before f()
    Dmitri> because *a can be evaluated after g(a), which can change *a.

    Dmitri> So we need to make an arbitrary decision ourselves and
    Dmitri> rewrite this to something like:

    Dmitri> int test(int *a) { int tmp1 = *a; int tmp2 = g(a); f(tmp1,
    Dmitri> tmp2); }

    Dmitri> I didn't give this much thought, but I suspect there are
    Dmitri> much more cases like this.

Yes, for example with side effect operators like ++ or -=, etc.

To deal with this kind of stuff in our own source-to-source compiler we
use the "," sequence operator to capture some values right from inside
the battle field.

For example you could compile this to:
int f(int, int);
int g(int *);
int test(int *a) {
   f((instrument_read(*a, 4), *a), (instrument_read(a, 4), g(a)));
}

That should work if the function formal argument evaluation order is
consistent for any call.

But, well, I guess we have enough work to deal with well-written
programs before dealing with all this wicked stuff... :-)
-- 
  Ronan KERYELL                            |\/  Phone:  +1 408 658 9453
  SILKAN Wild Systems                      |/)
  4962 El Camino Real #201                 K    Ronan.Keryell at silkan.com
  Los Altos, CA 94022                      |\   skype:keryell
  USA                                      | \  http://silkan.com



More information about the cfe-dev mailing list