I am using gdb-7.0.1 and I think I have detected a bug in a certain section of my code, which
has a for
loop. The for
loop looks like
for (int i=0 ; i< end ; ++i )
{
//Code here.
}
Here end
is a very large integer. The code does not crash at the first iteration, and seems to crash somewhere at iteration number end/2
.
Since I want to understand the behaviour of the code at iteration number end/2
, just stepping
and nexting
from i=0
till I reach this iteration point, is unfeasible.
Is there a way to tell gdb
to continue through a for loop till i
gets the value end/2
and then wait for the user to manually step through iteration number end/2
?
I am using gcc-4.5.2
on Ubuntu Linux
Here's a tutorial on conditional breakpoints with gdb.
I'm guessing you didn't know the term for this, otherwise it would have been easy to google.
When you set the breakpoint it'll give you a breakpoint number (for the moment, let's assume it's 1). You'll then make that breakpoint conditional, something like:
condition 1 i==end/2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With