This is a reduced example of the structure of my code:
void increment(int j);
int main()
{
int i = 0;
while(1) {
i = increment(i);
}
return 0;
The problem is that finish seems to stop abort the commands set for the first breakpoint after it.
This is expected behavior: any command that resumes the inferior (being debugged) process (as finish does) also stops the execution of canned command sequence.
Update:
See also this GDB bug report.
Is there a way to tell GDB to print i right after any increment call?
Yes:
increment routine using disas command. Find ret instruction at the end of it (there will only be one).break *0xNNNNN syntax.Attach a command to that breakpoint:
command N
print $rax # or $eax if you are on 32-bit x86 platform
continue
end
Voila: you should get values being returned from increment() printed (just before being returned).