Set a watch point on the counter:
(gdb) watch var
And make that watchpoint conditional:
(gdb) cond <watchpoint_number> var>=value
If you want to log to a file:
(gdb) set logging file <filename>
(gdb) set logging on
By default gdb logs to gdb.txt
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…