是否可以暂停在gdb下运行的程序来更改尚未命中的断点或添加新的断点?

时间:2012-10-11 15:02:01

标签: debugging gdb

我有一个长时间运行的程序需要一段时间才能到达断点。基于gdb的另一个实例,我意识到我想先停在某个地方检查一些东西,所以我想暂停一个正在去断点的gdb,插入另一个断点,然后恢复它..如果我做Ctrl + C中断了我的程序,我必须从头开始重启。有没有办法做到这一点?

1 个答案:

答案 0 :(得分:4)

  

如果我按Ctrl + C中断我的程序,我必须从头开始重启

它(通常)不会中断你的程序,它只应该中断GDB本身。如果您从那时起continue,该程序将继续而不接收SIGINT

示例:

int main()
{
  int i = 0;
  while (1) {
    sleep(1);
    i += 1;
  }
}

gdb ./a.out
(gdb) run
Starting program: /tmp/a.out 
^C
Program received signal SIGINT, Interrupt.
0x00007ffff7b03b10 in __nanosleep_nocancel () at ../sysdeps/unix/syscall-template.S:82
(gdb) bt
#0  0x00007ffff7b03b10 in __nanosleep_nocancel () at ../sysdeps/unix/syscall-template.S:82
#1  0x00007ffff7b039a0 in __sleep (seconds=<optimized out>) at ../sysdeps/unix/sysv/linux/sleep.c:138
#2  0x0000000000400542 in main () at t.c:5
(gdb) fr 2
#2  0x0000000000400542 in main () at t.c:5
5       sleep(1);
(gdb) print i
$1 = 1
(gdb) c
Continuing.
^C
Program received signal SIGINT, Interrupt.
0x00007ffff7b03b10 in __nanosleep_nocancel () at ../sysdeps/unix/syscall-template.S:82
(gdb) bt
#0  0x00007ffff7b03b10 in __nanosleep_nocancel () at ../sysdeps/unix/syscall-template.S:82
#1  0x00007ffff7b039a0 in __sleep (seconds=<optimized out>) at ../sysdeps/unix/sysv/linux/sleep.c:138
#2  0x0000000000400542 in main () at t.c:5
(gdb) fr 2
#2  0x0000000000400542 in main () at t.c:5
5       sleep(1);
(gdb) print i
$2 = 4
(gdb) q