【问题标题】:IntelliJ Idea (debugging) conditional breakpoint dependent on other breakpointsIntelliJ Idea(调试)条件断点依赖于其他断点
【发布时间】:2013-05-17 11:10:52
【问题描述】:

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

Idea 中是否可以实现这样的操作?

更新:

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

  1. 设置两个断点
  2. 禁用断点#2
  3. 启动调试器,等到断点 #1 处于活动状态
  4. 激活断点 #2

我希望有一种更清洁的方法来做到这一点:)

【问题讨论】:

标签: debugging intellij-idea breakpoints conditional-breakpoint


【解决方案1】:

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

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

【讨论】:

  • 我一直忽略这个菜单项,有时我没有看到树木的树林:)
  • 太糟糕了,他们把这个菜单埋了,很难找到。收藏夹 > 断点 > 右键 + 单击断点 > 编辑断点 > 更多
  • FWIW,您可以在 IntelliJ 2017.1 中通过右键单击断点然后单击弹出窗口左下方的“更多”来访问它。
  • 您可以为此分配一个快捷方式,或者使用默认的 Ctrl+Shift+F8 一次性查看所有 bps。
  • 这太棒了。甚至不知道这是一个东西
【解决方案2】:

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

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

你想在哪里设置断点的条件

根据条件您要停止的位置

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-29
    • 2015-08-23
    • 2011-09-28
    相关资源
    最近更新 更多