Eclipse debug stepping with AspectJ

こ雲淡風輕ζ 提交于 2020-01-03 18:42:34

问题


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?


回答1:


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.




回答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>


来源:https://stackoverflow.com/questions/14762142/eclipse-debug-stepping-with-aspectj

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!