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

纵饮孤独 提交于 2019-12-03 08:16:53

问题


I can tell GDB to return from a function immediately with return, and call a function with 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.

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


回答1:


jump looks like what you want. See Continuing at a Different Address




回答2:


You can use - until to make the loop end.

You should give it at the end of the loop.

  • Useful if you no need step into iterate a loop.



回答3:


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




回答4:


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.

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.

It won't work as direct break statement though.



来源:https://stackoverflow.com/questions/2200556/how-do-i-get-gdb-to-break-out-of-a-loop

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!