Accepted answer

use until command instead of next.

from gdb documentation:

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.

if you will use until instead of next, gdb will step over loops only once, which almost exactly what you want.

Related Query

More Query from same tag