gdb breakpoints

¿Cómo hacer que un punto de corte de GDB solo se rompa después de alcanzar el punto un número determinado de veces?



breakpoints (2)

Lea la sección 5.1.6 del manual de GDB. Lo que tienes que hacer es establecer primero un punto de interrupción, luego establecer un ''conteo de ignorar'' para ese número de punto de corte, por ejemplo, ignore 23 1000 .

Si no sabe cuántas veces ignorará el punto de interrupción y no desea contar manualmente, lo siguiente puede ayudar:

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

Tengo una función que se llama una gran cantidad de veces, y finalmente segfaults.

Sin embargo, no quiero establecer un punto de interrupción en esta función y parar después de cada llamada, porque estaré aquí por años.

He oído que puedo establecer un counter en GDB para un punto de interrupción, y cada vez que se golpea el punto de interrupción, el contador disminuye, y solo se activa cuando el counter = 0.

¿Es esto correcto y, de ser así, cómo lo hago? Por favor, proporcione el código gdb para establecer dicho punto de interrupción.


continue <n>

Este es un método conveniente que omite el último punto de inflexión hit n - 1 veces:

gdb -n -q tmp.out Reading symbols from tmp.out...done. (gdb) l 1 #include <stdio.h> 2 3 int main(void) { 4 int i = 0; 5 while (1) { 6 i++; 7 printf("%d/n", i); 8 } 9 } (gdb) start Temporary breakpoint 1 at 0x6a8: file tmp.c, line 4. Starting program: /home/ciro/bak/git/cpp-cheat/gdb/tmp.out Temporary breakpoint 1, main () at tmp.c:4 4 int i = 0; (gdb) b 6 Breakpoint 2 at 0x5555555546af: file tmp.c, line 6. (gdb) c Continuing. Breakpoint 2, main () at tmp.c:6 6 i++; (gdb) c 5 Will ignore next 4 crossings of breakpoint 2. Continuing. 1 2 3 4 5 Breakpoint 2, main () at tmp.c:6 6 i++; (gdb) p i $1 = 5 (gdb) (gdb) help c Continue program being debugged, after signal or breakpoint. Usage: continue [N] 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).