[aspectc-user] recording advice context

Mike Mortensen mmo at fc.hp.com
Wed Sep 7 17:51:04 CEST 2005


Hi,
This may be a really basic question about the JoinPoint API...
I am using before advice as a development aspect to trace all calls into 
a particular library function. 
I want to track the last call to a particular library call (because the 
library calls exit rather than throwing
an exception), but I'd also like to write out (for my own use) all 
calling contexts --
specifically the name of the static function or method that called the 
library call.

If the methods being called are all part of a class (otherClass), then I 
can write
out the signature of each method call in otherClass, and I can use __LINE__
and __FILE__ to quickly debug the exact call that triggered the exit:

    #include <iostream>
    using namespace std;


    aspect Action {
       advice call("% otherClass::%(...)") : before() {
          cerr << "   Track otherClass -- before calling " <<
    JoinPoint::signature()
               << " at line " << __LINE__ << " of file " << __FILE__
               << endl;
       }
    };

This advice prints out things like
    Track otherClass -- before calling unsigned int 
otherClass::NumPortsOnNet() const at line 11 of file Aspects.ah
so I know what methods are being called -- which is important -- but the 
__LINE__ and __FILE__ information
is embedded in Aspects.ah which is included in main.cc, so I don't get 
the 'context' or caller information.

Suppose calls to methods of otherClass exist in:
   main
   myClass::foo()
   myClass::bar()
   void f()
   void g()
Is there any way to print out the name of the calling function or 
method, rather than just what is being called
or trying to use __LINE__ and __FILE__?

Thanks,
Mike



More information about the aspectc-user mailing list