3

文件 main.c:

#include <stdio.h>

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

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

(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 只打印监视变量的值并继续,因为它是一个嵌套的观察点。如果它是一个独立的观察点,则可以使用命令“继续”轻松完成(当我在 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”“设置确认关闭”,但无济于事

4

1 回答 1

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
于 2011-07-21T14:40:45.907 回答