如何在Eclipse中使用条件断点?

发布于 2024-12-01 13:35:32 字数 315 浏览 1 评论 0原文

我想知道如何在 Eclipse 中放置条件断点。我有这样的代码:

public static void doForAllTabs(String[] tablist){
    for(int i = 0; i<tablist.length;i++){
-->        doIt(tablist[i]);
    }
}

现在我想在带有箭头的行上放置一个断点,但希望它仅在以下情况下触发:

tablist[i].equalsIgnoreCase("LEADDELEGATES");

I want to know how to place a conditional breakpoint in Eclipse. I have a code like:

public static void doForAllTabs(String[] tablist){
    for(int i = 0; i<tablist.length;i++){
-->        doIt(tablist[i]);
    }
}

Now I want to put a breakpoint on the line with the arrow but want it to trigger only if:

tablist[i].equalsIgnoreCase("LEADDELEGATES");

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

今天小雨转甜 2024-12-08 13:35:32

设置断点。
右键单击边缘的断点图像,然后选择断点属性

在此处输入图像描述

配置您认为合适的条件:

在此处输入图像描述

Put your breakpoint.
Right-click the breakpoint image on the margin and choose Breakpoint Properties:

enter image description here

Configure condition as you see fit:

enter image description here

摇划花蜜的午后 2024-12-08 13:35:32

doIt(tablist[i]); 行上创建一个普通断点

右键单击​​ ->;属性

检查“有条件”

输入 tablist[i].equalsIgnoreCase("LEADDELEGATES")

Make a normal breakpoint on the doIt(tablist[i]); line

Right-click -> Properties

Check 'Conditional'

Enter tablist[i].equalsIgnoreCase("LEADDELEGATES")

他夏了夏天 2024-12-08 13:35:32

1. 创建一个类

public class Test {

 public static void main(String[] args) {
    // TODO Auto-generated method stub
     String s[] = {"app","amm","abb","akk","all"};
     doForAllTabs(s);

 }
 public static void doForAllTabs(String[] tablist){
     for(int i = 0; i<tablist.length;i++){
         System.out.println(tablist[i]);
    }
  }
}

2. 右键单击左侧 System.out.println( tablist[i]); 在 Eclipse 中
--> 选择切换断点

3. 右键单击 切换点 < strong>--> 选择 断点属性

4. 检查 条件< /strong> 复选框 --> 写入 tablist[i].equalsIgnoreCase("amm") 在文本字段 --> 点击 确定

5. 右键单击课程 -- > 调试为 --> Java 应用程序

1. Create a class

public class Test {

 public static void main(String[] args) {
    // TODO Auto-generated method stub
     String s[] = {"app","amm","abb","akk","all"};
     doForAllTabs(s);

 }
 public static void doForAllTabs(String[] tablist){
     for(int i = 0; i<tablist.length;i++){
         System.out.println(tablist[i]);
    }
  }
}

2. Right click on left side of System.out.println(tablist[i]); in Eclipse
--> select Toggle Breakpoint

3. Right click on toggle point --> select Breakpoint properties

4. Check the Conditional Check Box --> write tablist[i].equalsIgnoreCase("amm") in text field --> Click on OK

5. Right click on class --> Debug As --> Java Application

公布 2024-12-08 13:35:32

来自 Eclipsepedia 关于如何设置条件断点:

首先,在给定位置设置断点。然后,使用上下文
编辑器左侧边距或断点中断点上的菜单
在“调试”透视图中查看,然后选择断点的属性。
在对话框中勾选Enable Condition,然后输入任意Java
条件,例如list.size()==0。现在,每次断点都是
达到时,在断点上下文中计算表达式
执行,断点要么被忽略,要么被尊重,具体取决于
关于表达式的结果。

条件也可以用其他断点来表示
属性,例如命中数。

From Eclipsepedia on how to set a conditional breakpoint:

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.size()==0. Now, each time the breakpoint is
reached, the expression is evaluated in the context of the breakpoint
execution, and the breakpoint is either ignored or honored, depending
on the outcome of the expression.

Conditions can also be expressed in terms of other breakpoint
attributes, such as hit count.

花开浅夏 2024-12-08 13:35:32

您需要遵循一些简单的步骤来触发条件断点。

步骤 1 - 将断点放在断点条件为 True 时要运行的行上(现在问题是在哪里放置断点条件)

步骤 2 - 放置断点后,只需右键单击放置在的小断点图像上代码的左边距。

步骤3-点击后你会发现一些选项,点击断点属性。

步骤 4- 单击后,您将找到复选框,即“条件”,只需选中它

步骤 5- 将出现文本框“启用”,您需要在其中写入条件,只有当条件成立时,才会执行有断点的行

希望你发现我的答案有用

There are Simple step which you need to follow to trigger the conditional breakpoint.

Step 1- Put the breakpoint on that line which you want to be run when the breakpoint condition falls True (Now the question arises where to put the breakpoint condition)

Step 2- After putting the breakpoint simply right click on the small breakpoint image placed on the left margin of your code.

Step 3- After clicking you will find an some options click on the breakpoint properties.

Step 4- After clicking you will find checkbox i.e Conditions, simply check it

Step 5- There will be text box Enable in which you need to write the condition upon which the line which has breakpoint will have been executed only when the condition falls true

Hope you find my Answer usefull

凑诗 2024-12-08 13:35:32

一种可能更方便的方法是:在想要断点的地方编写一个 if 语句并在其内容中设置断点。

if(tablist[i].equalsIgnoreCase("LEADDELEGATES")) {
-->    int breakpoint = 0; //don't do anything
}

(断点由箭头表示)

这样,断点仅在条件为真时才会触发。如果没有那么多弹出窗口,这可能会更容易。

A way that might be more convenient: where you want a breakpoint, write a if statement and set a breakpoint in its contents.

if(tablist[i].equalsIgnoreCase("LEADDELEGATES")) {
-->    int breakpoint = 0; //don't do anything
}

(the breakpoint is represented by the arrow)

This way, the breakpoint only triggers if your condition is true. This could potentially be easier without that many pop-ups.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文