Eclipse条件断点 - 仅在其他断点之后 [英] Eclipse conditional breakpoint - only after other breakpoint

查看:201
本文介绍了Eclipse条件断点 - 仅在其他断点之后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在调试一个执行大量方法调用的应用程序。例如,我想调试 methodA 。它被称为1000次。



但是,在我的主循环中,我只想在几个语句之后开始调试方法A.

  public void methodA()
{
//做一些令人讨厌的我想调试
}
public static void main(String [] args)
{
for(int i = 0; i <1000; i ++)
{
methodA();
}
methodB();
methodA();
}

我想开始打破 methodA 仅在 methodB 被调用之后。我真的不想改变我的代码(比如,插入一个 boolean 值,并使断点符合 boolean )。



在Eclipse中有可能这样吗?或者有更好的选择吗?

解决方案

A)只需使用hit count作为1000。



它的作用只有在methodA里面的for循环不在某种条件下。



B)使用条件



将breakpoint放在methodA.Refer图像中的第一个语句



[这里methodA ==测试,我把断点放在行号14]





右键单击断点,然后选择断点属性选项,并添加以下条件。

  StackTraceElement [] stacktrace = Thread.currentThread()。 getStackTrace(); 
StackTraceElement e = stacktrace [2];
return(e.getLineNumber()== 9);

这里9表示第二次调用methodA(或测试)的行号。找出相同的代码,并更改这个。



检查javadoc为了解更多详情。将您的评论/建议添加到此错误。


I'm debugging an application that does a lot of method calling. I want to, for example, debug methodA. It is called 1000 times.

But, in my main loop, I only want to start debugging method A after a few statements.

public void methodA()
{
    //does something nasty that I want to debug
}
public static void main( String[] args )
{
    for (int i=0; i<1000; i++)
    {
        methodA();
    }
    methodB();
    methodA();
}

I want to start breaking in methodA only after methodB is called. I don't really want to change my code (say, inserting a boolean value and making the breakpoint conditional on that boolean).

Is something like this possible in Eclipse? Or are there better options?

解决方案

A) Simply use hit count as 1000.

Its works only if the methodA inside for loop is NOT under some condition.

B) Using condition

Put the break point at the first statement inside methodA.Refer image

[Here methodA == test and I put break point at line number 14]

Right click on the breakpoint and select Breakpoint properties option and add the below condition.

StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();
StackTraceElement e = stacktrace[2];
return (e.getLineNumber() == 9);

Here 9 means the line number where second call to methodA(or test) is made.Find out the same in your code and change this.

Check the javadoc for StackTraceElement and instead of line number you can also use method name also. i.e you can break only when it is calling from the function xyz.

C) Wait for eclipse Oxygen (4.7)

In next version of eclipse JDT will provide trigger points on breakpoints. So you can say hit breakpoint y ONLY IF breakpoint x was hit before.

With this you can pause on a breakpoint ONLY on a given methods flow [stacktrace].

Ex: You can stop on a breakpoint only when call flow is:

methodA() --> methodB() --> methodC() --> methodD() NOT on

methodA() --> methodC() --> methodD() etc.

See this bug for more details. Add your comments/suggestion to this bug.

这篇关于Eclipse条件断点 - 仅在其他断点之后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆