How to skip multiple loop iterations in GDB?

Suppose I have a loop that will repeat 100 times, and I want to skip 50 iterations, but I want to keep clicking next from there to see each row.

I do not want to set a breakpoint after the loop, because in this way I will skip all iterations, and not just the number that I intend to.

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

PS I do not want to continue to press next from start to finish. This is time-consuming...

+10
source share
4 answers

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

Debugging with GDB

5.2 Continuation and pacing

continue [ignore-count]
c [ignore-count]
fg [ignore-count]
Summary of program execution at the address where your program was last stopped; Any breakpoints set at this address bypass. The optional argument ignore-count allows you to specify an additional number of times to ignore the breakpoint at this point; its effect is similar to that of ignoring (see the section Break conditions). The ignore-count argument only makes sense when your program is stopped due to a breakpoint. At other times, the argument to continue is ignored.

+15
source

You can use conditional breakpoints

 break <lineno> if i > 50 

where i is the loop index

+11
source

You can use a condition breakpoint.

syntax:

 b FileName.extension:lineNumber if varname condition 

example:

 b File.c:112 if i == 50 
0
source

In C #, for example, you can β€œcontinue” to skip the iteration. The example of skipping numbers with mod 3 is 0, so the numbers 3, 9, 12, 15 ... will be skipped.

 static void Main(string[] args) { for (int i = 1; i <= 50; i++) { if (i%3 == 0) { continue; } Console.WriteLine("{0}", i); } Console.ReadLine(); } 
-5
source

Source: https://habr.com/ru/post/979363/


All Articles