Reputation: 8087
I’m quite curious of how gdb implements "until" command.
I mean, I can understand how "finish" works, we know at the beginning and the end of a function, there’s code routine to operate ebp/esp register, so gdb can use this to execute to the end of a function.
But my question is, how does gdb know the end of a loop? If no debug symbol is provided, we know the loop might embed another inner loop, so depending on ecx register is not a solution. Then how does it know the end of a loop? The assembly code of "while" "do/while" and "for" could be different, not sure if there’s a pattern that "finish" command can look for.
Hope to see your explanations.
Upvotes: 1
Views: 1194
Reputation: 213859
how does gdb know the end of a loop?
It doesn't. From documentation:
until
Continue running until a source line past the current line, in the current stack
frame, is reached.
This command is used to avoid single stepping through a loop more than once.
It is like the next command, except that when until encounters a jump, it
automatically continues execution until the program counter is greater
than the address of the jump.
It's implemented pretty much exactly as described in the last statement above.
Upvotes: 2