IntelliJ Idea (debugging) conditional breakpoint dependent on other breakpoints
Asked Answered
B

2

27

I want to set a debug breakpoint in IntelliJ Idea that is only active, if another previous breakpoint was activated. For example i have a breakpoint B1 on line 10, and another breakpoint B2 on line 20. Even if B2s condition is true, the debugger should only halt if B1s condition was true before B2s.

Is something like this possible in Idea?

Update:

Currently i'm working with this workaround:

  1. set the two breakpoints
  2. disable breakpoint #2
  3. start the debugger, wait until breakpoint #1 is active
  4. activate breakpoint #2

I hope there is a cleaner way to do this :)

Brom answered 17/5, 2013 at 11:10 Comment(1)
Other advanced Breakpoint Settings in IDEALowly
P
38

You can do that in the View Breakpoints... view:

enter image description here

In your case you will first have to set a conditional breakpoint on B1 so that when it is hit then and only then B2 will be triggered.

enter image description here

Plagiary answered 17/5, 2013 at 11:37 Comment(5)
I overlooked this menu entry the whole time, sometimes i did'nt see the wood for the trees :)Brom
too bad they have buried this menu and made it hard to find. Favorites > Breakpoints > Right + Click on Breakpoint > Edit Breakpoint > MoreAlvinalvina
FWIW, You can get to it in IntelliJ 2017.1 by right-clicking a breakpoint and then clicking the 'more' on the bottom left of the popup.Wheelsman
You can assign a shortcut for this or just use the default Ctrl+Shift+F8 to see all your bps in one shot.Loftin
This is awesome. Did not even know this were a thing.Ratify
C
0

An alternate programmatic approach to debug specific classes when some condition in some class is met.

/*
 * Breakpoint helper, stops based on a shared state
 *  STOP variable
 *
 * Everything in here should be chainable
 *  to allow adding to breakpoints
 */
public final class DEBUG {

/*
 * global state controlling if we should
 *   stop anywhere
 */
public static volatile boolean STOP = false;

public static volatile List<Object> REFS = new ArrayList<>();

/**
 * add object references when conditions meet
 * for debugging later
 */
public static boolean ADD_REF(Object obj) {
    return ADD_REF(obj, () -> true);
}

public static boolean ADD_REF(Object obj, Supplier<Boolean> condition) {
    if (condition.get()) {
        REFS.add(obj);
        return true;
    }
    return false;
}

/*
 * STOPs on meeting condition
 *  also RETURNS if we should STOP
 *
 * This should be set when a main condition is satisfied
 *      and can be done as part of a breakpoint as well
 */
public static boolean STOP(Supplier<Boolean> condition) {
    if (condition.get()) {
        STOP = true;
        return true;
    }
    return false;
}

public static boolean STOP() {
    return STOP(() -> true);
}

Where you want a condition to set the breakpoint enter image description here

Where you want to stop based on a condition enter image description here

Clark answered 10/4, 2020 at 7:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.