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

2019-03-17 08:29发布

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?

标签: c gdb goto break
4条回答
戒情不戒烟
2楼-- · 2019-03-17 09:05

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

查看更多
爷的心禁止访问
3楼-- · 2019-03-17 09:10

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

查看更多
何必那么认真
4楼-- · 2019-03-17 09:24

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.
查看更多
等我变得足够好
5楼-- · 2019-03-17 09:29

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.

查看更多
登录 后发表回答