文件 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”和“设置确认关闭”,但无济于事