Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to skip a number of iterations of a loop in GDB?

Suppose I have a loop that will iterate 100 times and I want to skip 50 iterations but I want to continue pressing next from there on to see each line.

I don't want to set a breakpoint after the loop, because this way I'll skip all iterations and not only the number I intend to.

Is there a way to do this in GDB? How?

P.S. I don't want keep pressing next from start to finish. It's time consuming...

like image 788
Gabriel Avatar asked Dec 09 '14 20:12

Gabriel


People also ask

How do I skip iterations in gdb?

The optional argument ignore-count allows you to specify a further number of times to ignore a breakpoint at this location; its effect is like that of ignore (see section Break conditions). The argument ignore-count is meaningful only when your program stopped due to a breakpoint.

What does jump do in gdb?

Description. This command jumps the program counter to the specified location. The debugger resumes program execution at that point unless it encounters a breakpoint there.

How do you stop an infinite loop in gdb?

Diagnose the infinite loop. Start calc from within gdb using the run command. It will go into an infinite loop. Press Ctrl-C (like before) to stop your program.


2 Answers

Set a breakpoint in the loop and then call c 50 to continue 50 times

Debugging with GDB

5.2 Continuing and stepping

continue [ignore-count]
c [ignore-count]
fg [ignore-count]
Resume program execution, at the address where your program last stopped; any breakpoints set at that address are bypassed. The optional argument ignore-count allows you to specify a further number of times to ignore a breakpoint at this location; its effect is like that of ignore (see section Break conditions). The argument ignore-count is meaningful only when your program stopped due to a breakpoint. At other times, the argument to continue is ignored.

like image 65
helloV Avatar answered Nov 01 '22 17:11

helloV


You could use conditional break points

break <lineno> if i > 50

where i is the loop index

like image 26
Uku Loskit Avatar answered Nov 01 '22 17:11

Uku Loskit