0

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

4

1 回答 1

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
于 2012-10-11T15:31:12.897 回答