аргументы — аспект функции управления трассировкой c ++ и входные выходные параметры

Я использую aspectc ++ для генерации потока управления программой.

trace.ah:

    #ifndef __trace_ah__
#define __trace_ah__

#include <cstdio>
// Control flow tracing example

aspect trace {
// print the function name before execution starts

pointcut virtual methods() = "% ...::%(...)";

advice execution (methods()) : before () {
cout << "entering: " << JoinPoint::signature() << endl;
// print input parameters**
}

advice execution(methods()) : after() {
// print output parameters**
cout << "leaving: " << JoinPoint::signature() << endl;
}
//prints return values of non void functions
advice execution("% ...::%(...)" && !"void ...::%(...)") : after()
{JoinPoint::Result res = *tjp->result();
cout << "leaving " << tjp->signature()<< " << returning value--" << res<<endl;
}
};
};

#endif

Вопрос:

1. Как распечатать переменные, которые передаются в качестве аргументов в функции?

2.Как распечатать значения входных параметров каждой функции?

2

Решение

#ifndef __trace_ah__
#define __trace_ah__

#include <cstdio>
#include <iostream>
using namespace std;

template <int I> struct ArgPrinter
{
template <class JP> static inline void work (JP &tjp) {
ArgPrinter<I - 1>::work (tjp);
cout << "Arg " << I << ": " << *tjp.template arg<I - 1> () << endl;
}
};

template <> struct ArgPrinter<0>
{
template <class JP> static inline void work (JP &tjp) {}
};

// Control flow tracing example

aspect trace {pointcut virtual methods() = "% ...::%(...)";

template <class JP> void print_args (JP &tjp)
{
ArgPrinter<JP::ARGS>::work (tjp);
}

advice execution (methods()) : before ()
{
cout << "entering: " << JoinPoint::signature() << endl;
tjp->arg(0);
print_args (*tjp);}

advice execution("% ...::%(...)" && !"void ...::%(...)") : after()
{
JoinPoint::Result res = *tjp->result();
cout << "leaving " << tjp->signature()<< " << returning value--" << res<<endl;
}};
#endif
1

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector