[aspectc-user] tracing object creation

Olaf Spinczyk os at aspectc.org
Sun Nov 15 11:33:53 CET 2020


Hi Darrel!

The advice affects the following join points:

construction("casa::%") && cflow(execution("% casa::%::%(...)"))

The first part, i.e. construction("casa::%"), selects the construction
of all objects whose class is a member of the namespace casa. If you
remove the second part (&& ...), you will see messages being printed
even for the global objects and also for the objects that are
instantiated by main.

The second part is only there, because that was my interpretation of the
desired behavior after reading your first email. Maybe it was a
misinterpretation and the simpler pointcut expression would do it for
your use case.

The "cflow(execution ..." part filters the selected join points (&&
operator). The advice will only match if the control flow came through a
function within the namespace casa, before the construction join point
was reached. In the example this is the bar method. The control flow
property is checked by the woven code at runtime.

If you are *only* interested in global/static objects (from namespace
casa), the following pointcut might contain the right filter:

construction("casa::%") && !cflow(execution("% main(...)"))

With that version, the construction advice is disabled when the
execution of main starts.

Hope this helps.

- Olaf

PS: Have you already been able to translate your code base with ag++?
Due to the subtle differences between the clang parser, which is
integrated in ac++, and the g++ parser there are sometimes problems. It
can also be tricky to integrate ag++ into build scripts, makefiles, etc.
1M lines of code sounds like this part might be not so easy.

Am 13.11.20 um 18:11 schrieb Darrell Schiebel:
> Thanks for the reply Olaf. I ran across AspectC++ because I was looking
> for a way to debug a static/global object initialization issue with a
> large (1M line) C++ application. What I was hoping for was a way to have
> output added to all class constructors within the namespace regardless
> of how their objects are instantiated (even though I only need output
> for the global/static objects).
> 
> I modified your example to add some global/static objects, but it's not
> clear to me why only the objects defined within C2 produce trace output.
> 
> Thanks again for your help,
> Darrell
> 
> //---------------8<------------------------casa.cc----------------------------
> 
> #include <iostream>
> 
> #include <string>
> 
> using namespace std;
> 
> 
> namespace casa {
> 
>     class C1 {
> 
>         std::string s_;
> 
>     public:
> 
>         C1(std::string s) : s_(s) { cout << "C1 ctor " << s_ << endl; }
> 
>     };
> 
>     class C2 {
> 
>         std::string s_;
> 
>         C1 _member;
> 
>     public:
> 
>         C2 (std::string s, int p) : s_(s), _member(s + "'") { cout <<
> "C2 ctor " << s_ << endl; }
> 
>         void bar () { cout << "in bar" << endl; C2 c2(s_ + "''",0); C1
> c1(s_ + "'''"); }
> 
>     };
> 
> }
> 
> 
> using namespace casa;
> 
> 
> C2 one("A",90);
> 
> C1 two("B");
> 
> C2 three("C",100);
> 
> 
> int main () {
> 
>     three.bar( );
> 
>     static C1 four("D");
> 
>     casa::C1 c1("E");
> 
>     casa::C2 c2("F",42);
> 
>     c2.bar();
> 
> }
> 
> 
> aspect TraceCasaConstruction {
> 
>     advice construction("casa::%") && cflow(execution("%
> casa::%::%(...)")) : before () {
> 
>         cout << JoinPoint::signature() << endl;
> 
>     }
> 
> };
> 
> 
> _______________________________________________
> aspectc-user mailing list
> aspectc-user at mail.aspectc.org
> https://www.aspectc.org/cgi-bin/mailman/listinfo/aspectc-user
> 


More information about the aspectc-user mailing list