Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c

break

gdb

goto

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?

like image 765
John Carter Avatar asked Feb 04 '10 14:02

John Carter


People also ask

How do I set a break in gdb?

You can also set breakpoints on function names. To do this, just type "break [functionname]". gdb will stop your program just before that function is called. Breakpoints stay set when your program ends, so you do not have to reset them unless you quit gdb and restart it.

How do I skip iterations in gdb?

You can use the condition breakpoint. Show activity on this post. In C# for example you can do "continue" to skip iteration. Example of skipping numbers with mod 3 equal 0, so numbers 3, 9, 12, 15 ... will be skipped.

How do I stop gdb after continue?

You should interrupt the process that is attached by gdb. Do not interrupt gdb itself. Interrupt the process by either ctrl-c in the terminal in which the process was started or send the process the SIGINT by kill -2 procid. With procid the id of the process being attached.

What is a breakpoint in gdb?

A breakpoint makes your program stop whenever a certain point in the program is reached. For each breakpoint, you can add conditions to control in finer detail whether your program stops.


1 Answers

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.
like image 138
bala Avatar answered Oct 05 '22 19:10

bala