main.c
typedef struct
{
int iW;
int iH;
int iX;
int iY;
}BOX_ST;
int sum(const int a, const int b)
{
int c = a + b;
return c;
}
BOX_ST stBox;
int main()
{
for (int i = 0; i < 10000; ++i)
{
stBox.iW = i;
stBox.iH = i;
stBox.iX = i;
stBox.iY = i;
}
return 0;
}
gdb自动化脚本
功能:当某个表达式成立时观察给定变量的数值
示例:当stBox.iW的值是66时,打印stBox.iH的旧值和新值
tom@ubuntu:~/dvp$ cat ./gdbcmd_watchif.txt
watch stBox.iH if stBox.iW == 66
tom@ubuntu:~/dvp$
gdb自动化脚本使用
tom@ubuntu:~/dvp$ cc -g -o0 main.c -o a.out
tom@ubuntu:~/dvp$ gdb ./a.out -x ./gdbcmd_watchif.txt
Reading symbols from ./a.out...done.
Hardware watchpoint 1: stBox.iH
(gdb) info b
Num Type Disp Enb Address What
1 hw watchpoint keep y