Benjamin
Benjamin

Reputation: 737

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?

Upvotes: 5

Views: 3884

Answers (2)

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>

Upvotes: 3

Andrew Eisenberg
Andrew Eisenberg

Reputation: 28737

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.

Upvotes: 2

Related Questions