如果激活了另一个先前的断点,我想在IntelliJ Idea中设置一个仅处于活动状态的调试断点。 例如,我在第10行有一个断点 B1 ,在第20行有另一个断点 B2 。即使B2s条件为真,调试器也应该只在B1s条件为真时停止在B2s之前。
在Idea中是否可以这样?
更新
目前我正在使用此解决方法:
我希望有一种更清洁的方法:)
答案 0 :(得分:24)
您可以在View Breakpoints...
视图中执行此操作:
在您的情况下,您首先必须在 B1 上设置一个条件断点,这样当它被点击时,只会触发 B2 。
答案 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);
}