[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Debug aspect

Looking at your zip the AccessingDeprecatedMethodTest.class isnât woven with the aspect, were you expecting that particular class to be woven?

The message âwoven classâ means âthis class has been through the weaverâ, not that it has been modified. Using something like the showWeaveInfo option will tell you what is actually getting woven.


I built your maven project for the aspect library then I applied the aspect to your testcode like this (removing the testng reference from the source):


ajc -classpath $CLASSPATH:/Users/aclement/.m2/repository/com/google/guava/guava/20.0/guava-20.0.jar -inpath ../aspect/target/aspect-0.0.1-SNAPSHOT.jar src/test/java/externalApp/AccessingDeprecatedMethodTest.java -d output -showWeaveInfo

Join point 'method-call(void com.ericsson.aspectlib.ClassWithDeprecatedMethod.aMethod())' in Type 'externalApp.AccessingDeprecatedMethodTest' (AccessingDeprecatedMethodTest.java:17) advised by before advice from 'com.ericsson.aspectlib.DeprecatedMethodLogger' (aspect-0.0.1-SNAPSHOT.jar!DeprecatedMethodLogger.class:25(from MyAspect.aj))

Now I know it was woven and if I look in the byte code I can see it:

javap -verbose -private AccessingDeprecatedMethodTest.class

  public void test();
    descriptor: ()V
    flags: ACC_PUBLIC
Error: unknown attribute
      org.aspectj.weaver.MethodDeclarationLineNumber: length = 0x8
       00 00 00 0F 00 00 00 F0
    Code:
      stack=4, locals=2, args_size=1
         0: new           #23                 // class com/ericsson/aspectlib/ClassWithDeprecatedMethod
         3: dup
         4: invokespecial #25                 // Method com/ericsson/aspectlib/ClassWithDeprecatedMethod."<init>":()V
         7: astore_1
         8: aload_1
         9: invokestatic  #56                 // Method com/ericsson/aspectlib/DeprecatedMethodLogger.aspectOf:()Lcom/ericsson/aspectlib/DeprecatedMethodLogger;
        12: getstatic     #58                 // Field ajc$tjp_0:Lorg/aspectj/lang/JoinPoint$StaticPart;
        15: getstatic     #60                 // Field ajc$tjp_1:Lorg/aspectj/lang/JoinPoint$StaticPart;
// HERE IS THE ADVICE CALL
        18: invokevirtual #64                 // Method com/ericsson/aspectlib/DeprecatedMethodLogger.ajc$before$com_ericsson_aspectlib_DeprecatedMethodLogger$1$b9499fc0:(Lorg/aspectj/lang/JoinPoint$StaticPart;Lorg/aspectj/lang/JoinPoint$StaticPart;)V
// HERE IS THE DEPRECATED METHOD CALL
        21: invokevirtual #26                 // Method com/ericsson/aspectlib/ClassWithDeprecatedMethod.aMethod:()V

So from my point of view sounds like debugging wasnât working because the class isnât woven?

cheers
Andy

On Aug 16, 2018, at 12:39 AM, Mikael Petterson <mikaelpetterson@xxxxxxxxxxx> wrote:

The zip file with the projects are accessible from here.


br,

//mike

 
 

FrÃn: aspectj-users-bounces@xxxxxxxxxxx <aspectj-users-bounces@xxxxxxxxxxx> fÃr Mikael Petterson <mikaelpetterson@xxxxxxxxxxx>
Skickat: den 14 augusti 2018 13:34
Till: Eric B; aspectj-users@xxxxxxxxxxx
Ãmne: Re: [aspectj-users] Debug aspect
 
Hi

I tried setting the inline compilation. See here:

<image.png>


But no difference. So I add my projects here as a zip if someone is interested.

br,

//mike



 
 

FrÃn: aspectj-users-bounces@xxxxxxxxxxx <aspectj-users-bounces@xxxxxxxxxxx> fÃr Eric B <ebenzacar@xxxxxxxxx>
Skickat: den 14 augusti 2018 11:35
Till: aspectj-users@xxxxxxxxxxx
Ãmne: Re: [aspectj-users] Debug aspect
 
Depending on your aspect, ajc may try to compile in inline in your class.  I'm not sure what conditions the compiler checks for inline compilation.  The surest way is to use a decompiler to check the output class file and see if you aspect has been inlined or not.  If it has, there is an experimental flag you can set in your plugin definition XnoInline (https://www.mojohaus.org/aspectj-maven-plugin/compile-mojo.html#XnoInline).  

Additionally, if I remember correctly, there is also a setting in ellipse ajdt that configures the same.

Thanks,

Eric



On Tue, Aug 14, 2018, 6:58 AM Mikael Petterson, <mikaelpetterson@xxxxxxxxxxx> wrote:
Just adding a picture of my setup.


 
 

FrÃn: aspectj-users-bounces@xxxxxxxxxxx <aspectj-users-bounces@xxxxxxxxxxx> fÃr Mikael Petterson <mikaelpetterson@xxxxxxxxxxx>
Skickat: den 14 augusti 2018 08:46
Till: aspectj-users@xxxxxxxxxxx
Ãmne: [aspectj-users] Debug aspect
 
Hi,

I have an application A in Eclipse that uses another library  that has an aspect implemented. Purpose of of aspect is to see when application A
calls deprecated methods in the library.

Both application A and library are java maven projects in Eclipse. Application A has a dependency to the library and I can see that in Eclipse. So I have the source 
available for both projects. In eclipse the library is also a aspect project so I can see when it builds it output saying "woven class".

What I want to accomplish is , when I run a class in application A that calls a deprecated method in the library, I want the debugger to halt in my aspect.

Here is where I set my breakpoint:

pointcut deprecated() :
        @annotation(Deprecated) && (call(public * *(..)) || call(*.new(..)));

    pointcut beta() :
        @annotation(com.google.common.annotations.Beta);

    pointcut deprecatedMethods() :
        deprecated() && !beta();

before() : deprecatedMethods() {
        DeprecatedMethodData deprecatedMethodData = new DeprecatedMethodData();
        System.out.println(
                "Deprecated method " + thisJoinPoint.getSignature() +
                        " called by " + thisEnclosingJoinPointStaticPart.getSignature());
        deprecatedMethodData.setDeprecatedClassName(thisJoinPoint.getSignature().toString());
        deprecatedMethodData.setCallingClassName(thisEnclosingJoinPointStaticPart.getSignature().toString());
        deprecatedMethodData.setAccess(Access.EXTERNAL);
        deprecatedMethodData.setUser(JavaProperties.USER);
        deprecatedMethodData.setUserDir(JavaProperties.USER_DIR);
        deprecationDataList.add(deprecatedMethodData);


But there is no halt on:

  DeprecatedMethodData deprecatedMethodData = new DeprecatedMethodData();

where I put my breakpoint on.

Any ideas what I am lacking?

br,

//mike


 
 
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-users
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-users