调试循环

发布于 2024-09-30 08:48:00 字数 260 浏览 0 评论 0原文

对于当前的一些项目,我正在使用几个非常大的数据结构(在 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 技术交流群。

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

发布评论

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

评论(3

农村范ル 2024-10-07 08:48:00

我相信有更好的方法来做到这一点,但是您可以在循环中创建一个简单的代码块,仅在某个迭代中执行,并将断点放在其中。

if (loopIndex == 1000) {
  int number = 14;            //Break here
}

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.

if (loopIndex == 1000) {
  int number = 14;            //Break here
}
妳是的陽光 2024-10-07 08:48:00

以此为例:

for(int i=0;i<10000;i++){
    System.out.println(i);
}

在打印行上设置一个断点,然后右键单击它并选择Breakpoint Properties...。从这里您可以设置触发断点的条件。这与 if 语句中的条件类似。如果您想在 i 等于 6000 时触发断点,请选中 Conditional 框并尝试以下操作:

Using this as an example:

for(int i=0;i<10000;i++){
    System.out.println(i);
}

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 the Conditional box and try this: enter image description here

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