[aspectc-user] tracing object creation

Darrell Schiebel darrell at schiebel.us
Fri Nov 13 18:11:07 CET 2020


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;

    }

};
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.aspectc.org/pipermail/aspectc-user/attachments/20201113/52f6175e/attachment.htm>


More information about the aspectc-user mailing list