IntelliJ Idea(调试)条件断点依赖于其他断点

时间:2013-05-17 11:10:52

标签: debugging intellij-idea breakpoints conditional-breakpoint

如果激活了另一个先前的断点,我想在IntelliJ Idea中设置一个仅处于活动状态的调试断点。 例如,我在第10行有一个断点 B1 ,在第20行有另一个断点 B2 。即使B2s条件为真,调试器也应该只在B1s条件为真时停止在B2s之前。

在Idea中是否可以这样?

更新

目前我正在使用此解决方法:

  1. 设置两个断点
  2. 禁用断点#2
  3. 启动调试器,等到断点#1处于活动状态
  4. 激活断点#2
  5. 我希望有一种更清洁的方法:)

2 个答案:

答案 0 :(得分:24)

您可以在View Breakpoints...视图中执行此操作:

enter image description here

在您的情况下,您首先必须在 B1 上设置一个条件断点,这样当它被点击时,只会触发 B2

enter image description here

答案 1 :(得分:0)

当满足某些类中的某些条件时,用于调试特定类的另一种编程方法。

/*
 * 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);
}

需要条件设置断点的位置 enter image description here

要根据条件在何处停止 enter image description here