防止gdb在观察点停止

时间:2011-07-21 12:23:09

标签: gdb watchpoint

file main.c:

#include <stdio.h>

int main()
{
    int i;
    for (i=0; i<30 ;i++) {
            printf ("%d\n", i);
    }
    return 0;
}

在gdb中,我通常设置一个断点,然后指定一个watchpoint作为要在该断点上执行的命令:

(gdb) break main
Breakpoint 1 at 0x4004b0: file main.c, line 6.
(gdb) command
Type commands for when breakpoint 2 is hit, one per line.
End with a line saying just "end".
>watch i
>end

每当监视变量发生变化时,执行就会停止,问题是没有办法(据我所知)告诉gdb只打印监视变量的值并继续,因为它是一个嵌套的观察点。如果它是一个独立的观察点,可以使用命令'continue'轻松完成(当我在范围内时,如果是main()):

(gdb) watch i
Hardware watchpoint 2: i
(gdb) command
Type commands for when breakpoint 2 is hit, one per line.
End with a line saying just "end".
>continue
>end

那么,有没有办法让gdb不停在嵌套的观察点上,只打印值变化?或者更好的是,指定要在嵌套监视/断点上执行的命令?

我在gdb中进一步尝试'设置投诉0''设置确认关闭'但无效

1 个答案:

答案 0 :(得分:2)

GDB没有嵌套观察点的概念。无论您在何处设置断点和观察点,所有断点和观察点都处于顶层。

这是你想要的:

(gdb) break main
Breakpoint 1 at 0x40052c: file t.c, line 6.
(gdb) commands
>watch i
>commands
 >c
 >end
>c
>end

这在断点1上设置命令列表:

watch i
continue

在观察点上创建单独的命令列表(创建时):

continue
相关问题