调试循环
对于当前的一些项目,我正在使用几个非常大的数据结构(在 10K 元素的范围内)。为了能够访问列表中的这些数据,我需要使用循环和迭代器,当问题区域位于列表的后半部分时,这可能会很痛苦。
因此,我发现自己花了很多时间用手指按 Eclipse 调试器中的 F8 按钮来循环遍历迭代循环的每个元素。当必须多次浏览该特定部分才能了解代码为何以特定方式做出反应时,情况会变得更糟。
如果人们大致了解在遇到问题区域之前循环要执行多少次,是否有一种方法可以设置循环断点以执行到该点然后暂停?
For some current projects, I'm working with several data structures that are pretty large (in the area of 10K elements). To be able to access this data in lists, I need to use loops and iterators, which can be a pain when the problem area is in the latter half of the list.
So I find myself spending alot of time with my finger on the F8 button in Eclipse's debugger to loop through each element of an iterating loop. This gets worse when have to step through that particular section several times to get an idea why the code is reacting a particular way.
If one has a general idea how many times a loop is to execute before a problem area is hit, is there a way to set a loop breakpoint to execute up to that point then pause?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用条件断点。
http://wiki.eclipse.org/FAQ_How_do_I_set_a_conditional_breakpoint%3F
Use conditional breakpoints.
http://wiki.eclipse.org/FAQ_How_do_I_set_a_conditional_breakpoint%3F
我相信有更好的方法来做到这一点,但是您可以在循环中创建一个简单的代码块,仅在某个迭代中执行,并将断点放在其中。
I believe there's a better way to do this, but you can create a trivial block of code in the loop that only executes at a certain iteration, and put the breakpoint inside of it.
以此为例:
在打印行上设置一个断点,然后右键单击它并选择
Breakpoint Properties...
。从这里您可以设置触发断点的条件。这与 if 语句中的条件类似。如果您想在 i 等于 6000 时触发断点,请选中Conditional
框并尝试以下操作:Using this as an example:
Set a breakpoint on the print line, then right click on it and select
Breakpoint Properties...
. From here you can set a condition to trigger the breakpoint. This is the similar to a conditional you would have in an if-statement. If you wanted to trigger the breakpoint when i equals 6000, check theConditional
box and try this: