1

I'm running a program in gdb and I have a for loop that I want to run 32,000 times within that program. I don't want to finish the loop which would run a complete 159,000 times. There's a specific incident occurring on approximately the 32,000 iteration that I would like to examine further and entering (gdb) next 32,000 times will give me carpal tunnel. Any idea's?

1

You can put a counter in the loop and set a breakpoint based on the counter. For example, say you had this program:

#includes go here ;-)

int main(int argc, string argv[])
{   

for (int i=0; i<10000; i++)
    {
        printf("i=%i\n",i);
    }       
}

Now, let's say that the printf() is on line 10.

You start the program in gdb and set the following:

break 10 if i == 50

Next, you start the program as usual. It will run continuously until i == 50.

Here's a useful page:
https://sourceware.org/gdb/onlinedocs/gdb/Break-Commands.html

If this answers your question, please click on the check to accept it and remove it from the unanswered question pool. Let's keep up on forum maintenance. ;-)

  • That should do it, but could you explain or reference how to set a break point when the loop counter = 32,000? – Gibb Johnson Aug 6 '15 at 14:22
  • hi, @Cliff B! want to add more details? thanks! – Kareem Aug 6 '15 at 21:03
  • What, you didn't know the details, Kareem? ;-) – Cliff B Aug 6 '15 at 23:17
0

You can also use continue <n> to break only the Nth time the current breakpoint is hit, see also: https://stackoverflow.com/questions/2956889/how-to-make-a-gdb-breakpoint-only-break-after-the-point-is-reached-a-given-numbe/46251968#46251968

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .