C语言 如何让 GDB 跳出循环?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2200556/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 04:23:24  来源:igfitidea点击:

How do I get GDB to break out of a loop?

cgdbgotobreak

提问by John Carter

I can tell GDB to return from a function immediately with return, and call a function with call myFunction.

我可以用 告诉 GDB 立即从函数返回return,并用 调用函数call myFunction

But how do I get it break out of the current loop? i.e. to act as if it's hit a break;statement.

但是我如何让它跳出当前循环?即表现得好像它命中了一个break;语句。

Is jump myfile.c:<linenumber>the way to do this?

jump myfile.c:<linenumber>这样做的方法吗?

采纳答案by sigjuice

jumplooks like what you want. See Continuing at a Different Address

jump看起来像你想要的。请参阅在不同地址继续

回答by bala

You can use untilto make the loop end.

您可以使用until使循环结束。

You should give it at the end of the loop.

你应该在循环结束时给它。

  • Useful if you no need step into iterate a loop.
  • 如果您不需要进入迭代循环,则很有用。

回答by sud03r

I do this:
1. do a source listing.
2. Set a breakpoint at the next line where loop ends.
3. Continue

我这样做:
1. 做一个源列表。
2. 在循环结束的下一行设置断点。
3. 继续

回答by Sukanto

One of the ways could be to set the condition of the loop to false. But this would mean that you would have to wait for the current iteration to finish.

其中一种方法是将循环的条件设置为 false。但这意味着您必须等待当前迭代完成。

So to summarize the steps would be:
1. Set a breakpoint at the last line of the loop
2. Continue
3. When breakpoint hits, set the loop condition variable to false.

所以总结一下步骤是:
1. 在循环的最后一行设置一个断点
2. 继续
3. 当断点命中时,将循环条件变量设置为 false。

It won't work as direct break statement though.

不过,它不能作为直接的 break 语句工作。