开发者

In Eclipse, is there a way to disable a breakpoint until another breakpoint is hit first?

开发者 https://www.devze.com 2023-02-04 11:23 出处:网络
In Eclipse, is there a way to disable a breakpoint开发者_如何学编程 until another breakpoint is hit first?This is a big hack, but it is a functional workaround:

In Eclipse, is there a way to disable a breakpoint开发者_如何学编程 until another breakpoint is hit first?


This is a big hack, but it is a functional workaround:

Call the 'trigger' location breakpoint 1 and the target location breakpoint 2. We want breakpoint 2 to fire if-and-only-if execution has passed breakpoint 1.

Set conditional breakpoints at each.

For breakpoint 1, set the condition as System.setProperty("breaknow", "breaknow") == "". This condition will never be true, but will set a system property which we can read at breakpoint 2.

For breakpoint 2, set the condition as System.clearProperty("breaknow") != null. This condition will trigger when the system property is set, and also clear it (so we can repeat if needed).

As I said, it's a hack, but it seems to work. I submitted an Eclipse enhancement request to implement linking or chaining breakpoints as a native feature (https://bugs.eclipse.org/bugs/show_bug.cgi?id=390590). Unfortunately, I don't have bandwidth to implement it myself, but perhaps we'll get support for a cleaner solution someday.

One caveat (which applies to all conditional breakpoints, not just to this trick): From my experience, it appears that a setting a conditional breakpoint prevents the JIT from compiling the method of interest, running it in interpreted mode instead. Or perhaps, it allows the first C1 JIT stage but prevents the second-stage C2 compiler from optimizing?

In either case, you should be aware that the method you’re debugging will run considerably slower with a conditional breakpoint in place. This isn’t usually a problem, but when debugging very tight inner loops, I’ve found it better to fall back to the (sloppy) if (x) { // Do somthing useless and set a breakpoint here} method.


No. But you can have conditional breakpoints. I guess that hitting the other breakpoint indicates some change of state.

So, Right click the breakpoint -> Breakpoint properties -> check "conditional"


If you know the condition at which the other break point will be hit, then you can add that condition to the new breakpoint.


Conditional breakpoints are one possibility, and you can also set a Hit Count so that the breakpoint is only triggered after being hit the specified number of times.

But no, there is no way to do what you are asking.


Another idea is to disable your breakpoint and enable it once the other breakpoint is hit.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号