22

For example, I have a function NamespaceA::ClassB::FunctionC() in my program. I know I can ask GDB to break there, by "break NamespaceA::ClassB::FunctionC". But what should I do if I only want GDB to break there, after this function is called, say, 100 times?

I think a workaround solution is adding one more variable in the program, and then there is "break ... if cond" command in GDB i can use. But can i achieve the same thing without adding variables to my program?

Thank you.

Yang Chi
  • 432
  • 1
  • 3
  • 8
  • 1
    see related question under http://stackoverflow.com/questions/2956889/how-to-set-a-counter-for-a-gdb-breakpoint – Omar Feb 13 '14 at 10:02
  • Possible duplicate of [How to make a GDB breakpoint only break after the point is reached a given number times?](https://stackoverflow.com/questions/2956889/how-to-make-a-gdb-breakpoint-only-break-after-the-point-is-reached-a-given-numbe) – Ciro Santilli OurBigBook.com Sep 16 '17 at 08:47

1 Answers1

28
(gdb) continue 100

should do the trick

(gdb) help continue
Continue program being debugged, after signal or breakpoint.
 If proceeding from breakpoint, a number N may be used as an argument,
 which means to set the ignore count of that breakpoint to N – 1 (so that
 the breakpoint won’t break until the Nth time it is reached).
sehe
  • 374,641
  • 47
  • 450
  • 633
  • 24
    This assumes that you're already at the given breakpoint. You can also set the ignore count directly with `ignore `, where `n` is the number of the breakpoint to ignore `count` times. – Cascabel Oct 11 '11 at 23:27
  • 3
    @Jefromi IMHO your comment is worth to become another answer. – Melebius Dec 05 '17 at 14:00