Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 909
Kyle Avatar asked Jan 13 '11 21:01

Kyle


People also ask

How do you do a conditional breakpoint in eclipse?

First, set a breakpoint at a given location. Then, use the context menu on the breakpoint in the left editor margin or in the Breakpoints view in the Debug perspective, and select the breakpoint’s properties. In the dialog box, check Enable Condition, and enter an arbitrary Java condition, such as list.

Which command is used to continue the program until the next breakpoint occurs?

continue (shorthand: c ) will resume execution until the next breakpoint is hit or the program exits. finish will run until the current function call completes and stop there.


2 Answers

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.

like image 103
AaronD Avatar answered Oct 02 '22 17:10

AaronD


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"

like image 41
Bozho Avatar answered Oct 02 '22 16:10

Bozho