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


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

Sin embargo, no quiero establecer un punto de interrupción en esta función y detener después de cada vez que se llama, porque estaré aquí durante 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 se decrementa, y solo se activa cuando el counter = 0.

¿Es esto exacto, y si es así, cómo lo hago? Por favor, dar el código gdb por establecer tal punto de interrupción.

2 answers

Lea la sección 5.1.6 del manual del BGF. Lo que tiene que hacer es primero establecer un punto de interrupción, luego establecer un 'recuento de ignorados' para ese número de punto de interrupción, por ejemplo, ignore 23 1000.

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

  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
 134
Author: Kilian Foth,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-10-06 23:01:50

continue <n>

Este es un método conveniente que omite el último punto de interrupción del golpe 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).
 4
Author: Ciro Santilli 新疆改造中心 六四事件 法轮功,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-12-16 12:05:16