Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse debug stepping with AspectJ

I have Eclipse setup with "The AspectJ Development Tools" plugin. I'm trying to debug some code that uses AspectJ and step through it, but it is unable to match up the source lines since AspectJ has added extra stuff at compile time. No one else seems to be complaining about what seems like a major flaw (being unable to debug!), so I'm hoping I just need to tweak something to make it work. What am I doing wrong?

like image 730
Benjamin Avatar asked Feb 07 '13 22:02

Benjamin


2 Answers

Yes, this is a bug with AspectJ. Stepping through advice has the incorrect file attribute attached to it. The best workaround is to delegate to a proper method inside of your advice and the line numbers will be aligned.

like image 29
Andrew Eisenberg Avatar answered Oct 31 '22 02:10

Andrew Eisenberg


So far I have encountered the behaviour you described only with @Around advice. @Before or @After advices have never confused the debugger I use.

@Around is by default inlined in weaved classes (includes target class and the aspect itself). This is different from other advices I have tried. Inlining makes it difficult if not impossible for debugger to follow the flow.

You can disable inlining in AspectJ compiler, which will produce weaved classes in debugger friendly way. Disabled inlining may produce slower code and more weaved classes (auxiliary classes are created).

The maven way:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>aspectj-maven-plugin</artifactId>
    <version>1.7</version>
    <executions>
        <execution>
            <goals>
                <goal>compile</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <source>${java.compiler.source}</source>
        <target>${java.compiler.target}</target>
        <complianceLevel>${java.compiler.target}</complianceLevel>

        <!-- Avoid some optimizations that make debugger useless. -->
        <XnoInline>true</XnoInline>
    </configuration>
</plugin>
like image 80
Vlastimil Ovčáčík Avatar answered Oct 31 '22 01:10

Vlastimil Ovčáčík