stagemonitor / stagemonitor-mailinglist

GitHub issues abused as a mailing list
3 stars 0 forks source link

Stagemonitor instrumentation and debugging/breakpoints? #47

Open ryanrupp opened 7 years ago

ryanrupp commented 7 years ago

Hey all, During development I've noticed sometimes either breakpoints won't be hit as expected or lines will be off. Typically I'm using Eclipse although I've noticed this in IntelliJ as well. I actually originally thought this was maybe due to the use of Lombok in our project. However, I think I narrowed it down to the instrumentation Stagemonitor (version = 31.0) does as I can toggle stagemonitor.active to false and it will hit the breakpoint then rerun the app with it enabled and the breakpoint is missed. Has anyone else had this problem? Any IDE changes that can be made to have this work correctly or possibly change how the instrumentation is done? For now I'll probably just disable the instrumentation when I need to be able to step through code.

felixbarny commented 7 years ago

Hi, I've noticed that as well with IntelliJ. I thought it might be due to the feature in IntelliJ which compares the byte code of the class files to the actual executed byte code. But you say you also have the problem in Eclipse?

There are actually two issues I've noticed when debugging. The first issue occurs when code is executed via IntelliJ directly, for example when debugging unit tests. In that case code which is instrumented with the ProfilingTransformer and included in stagemonitor.instrument.include, break points do not work.

During remote debugging, break points actually work. But when the break point is set at the first line, IntelliJ says something like "variable information not available" when I press "step into" (F7), I'm inside the Profiler#start method. Then I can step out with [Shift] + [F8] and I can see the variable information. Another way is to just step over [F8] but that does not work if the method only has one line.

I think the reason for this behavior is the way Byte Buddy performs the byte code manipulation. In earlier Versions I did not notice these issues. @raphw, do you know something about this issue?

raphw commented 7 years ago

I would not know anything about this but it might be related to adding code after the first line number information added to code. You can disable this via the @OnMethodEnter annotation. Could you try that?

felixbarny commented 7 years ago

I've set @Advice.OnMethodEnter(prependLineNumber = false) on each OnMethodEnter annotation (the important ones in this case are org.stagemonitor.tracing.profiler.ProfilingTransformer and org.stagemonitor.tracing.AbstractTracingTransformer). Still, when I set a break point here the break point doesn't get hit.

When I comment out stagemonitor.instrument.include, the break point is hit as expected.

I've attached the corresponding class file after the byte code modifications: TracedTransformerTest.zip

raphw commented 7 years ago

The bytecode looks just as expected. The line number table is intact and line 64 points at the instruction right before the call to monitorMe so the break point should trigger.

I experience the same behavior and I think it is because of IntelliJ not mapping the break points correctly. Tools like JRebel do for example offer plugins to fix the bytecode/source code mismatch: https://zeroturnaround.com/software/jrebel/learn/faq/