无法断定Eclipse中代码块的最后一个语句 [英] Can't breakpoint the last statement of a code block in Eclipse

查看:151
本文介绍了无法断定Eclipse中代码块的最后一个语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

if (true) {
    String a = "foo";
    String b = "bar";
}

如果我在中设置断点String a = foo; eclipse将停止,我可以在变量窗口中查看 a 的值。但是我不能超过第二个声明,它只是留下代码块,我从来没有看到 b 的值。

If I set a breakpoint at String a = "foo"; eclipse will stop, and I can step over and see the value of a inside the variables window. But I can't step over the 2nd statement, it just leaves the code block and I never see the value of b.

这迫使我在 String b =bar; 之后添加一个noop语句,所以我可以看到什么 b 包含。我也不能在关闭} 添加断点,我认为这可能是相关的问题。

This forces me to add a noop statement after String b = "bar"; just so I can see what b contains. I also can't add a breakpoint on the closing } which I think are maybe related issues.

我知道Visual Studio允许这样做,所以有一种在Eclipse中这样做的方法?

I know Visual Studio allows this, so is there a way to do this in Eclipse?

推荐答案

设置断点在任何块是不可能的(没有字节码黑客)。

To set a breakpoint at the end of an arbitrary block is not possible (without byte-code hacking).

如果它是一个方法体,那么它可能:您可以设置一个方法断点。通过双击方法定义行来执行此操作:

If it is a method body, then it is possible: you can set a Method breakpoint. Do this by double-clicking on the method definition line:

注意小箭头),然后在断点视图中,选择断点来查看显示属性中的条目退出选项勾选框:

(notice the little arrow?) and then in the breakpoints view, select the breakpoint to see both an Entry and an Exit option tick-box in the displayed properties:

小箭头表示,默认情况下,我们在条目上设置了一个断点。

The little arrow indicates that, by default, we have set a breakpoint on entry to the method.

现在选择退出(并取消选择条目),您将在断点视图中看到这一点:

Now select Exit (and deselect Entry) and you will see this in the breakpoints view:

>有一个不同的小箭头,表示一个退出断点。

(There is a different little arrow, indicating an exit breakpoint.)

现在在这个小破坏者上运行调试器调试为Java应用程序'),它将在方法的退出括号上停止

Now run the debugger on this little breaker ('Debug As a Java Application') and it will stop on the exit brace of the method:

和局部变量(仅<$ c在这种情况下,$ c> a 现在在变量视图中可见(使用正确的值):

and the local variables (only a in this case) are now visible (with the correct values) in the Variables view:

值得注意的是这种类型的断点陷阱方法退出,但是这种情况发生 - 甚至,例如,如果我们通过抛出异常退出。

It is worth noticing that this type of breakpoint traps method exit however this happens -- even, for example, if we exit by throwing an exception.

这篇关于无法断定Eclipse中代码块的最后一个语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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