I have a function that is called some large number of times, and eventually segfaults. However, I don't want to set a breakpoint at this function and stop after every time it's called, because I will be here for years. I've heard that I can set a counter
in GDB for a breakpoint, and each time the breakpoint is hit, the counter is decremented, and only gets triggered when the counter
= 0. Is this accurate, and if so how do I do it? Please give the gdb code for setting such a breakpoint.
views:
112answers:
1
+5
A:
Read section 5.1.6 of the GDB manual. What you have to do is first set a breakpoint, then set an 'ignore count' for that breakpoint number, e.g. ignore 23 1000
.
If you don't know how many times to ignore the breakpoint, and don't want to count manually, the following may help:
ignore 23 1000000 # set ignore count very high.
run # the program will SIGSEGV before reaching the ignore count.
# Once it stops with SIGSEGV:
info break 23 # tells you how many times the breakpoint has been hit,
# which is exactly the count you want
Kilian Foth
2010-06-02 10:58:14
+1: Nice trick!
Chris
2010-06-02 23:27:16