Kyle
Kyle

Reputation: 22035

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

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

Upvotes: 6

Views: 430

Answers (5)

AaronD
AaronD

Reputation: 1701

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.

Upvotes: 6

nanda
nanda

Reputation: 24788

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

Upvotes: 0

Andrew Eisenberg
Andrew Eisenberg

Reputation: 28737

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.

Upvotes: 0

franklins
franklins

Reputation: 3738

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

Upvotes: 0

Bozho
Bozho

Reputation: 597076

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"

Upvotes: 5

Related Questions