gdb watchpoint为什么a--,还不会触发
1 #include<stdio.h> 2 void printNum(int a) 3 { 4 printf("printNum\n"); 5 while(a > 0) 6 { 7 printf("%d\n",a); 8 a--; 9 } 10 } 11 void printNum2(int a,int num) 12 { 13 printf("printNum\n"); 14 while(a > num && a>0) 15 { 16 printf("%d\n",a); 17 a--; 18 } 19 } 20 int div(int a,int b) 21 { 22 printf("a=%d,b=%d\n",a,b); 23 int temp = a/b; 24 return temp; 25 } 26 int main(int argc,char *argv[]) 27 { 28 printNum2(12,5); 29 printNum(10); 30 div(10,0); 31 return 0; 32 }
gdb watchpoint 看a。为什么a--,还不会触发。
答:
watchpoint不应该用run吗
一行一行的执行肯定停止啊
这就是个条件断点
watchpoint就是条件断点,当然是run了,条件满足就暂停
n一行一行没有意义啊
---------------------------------------------------
关于gdb的watchpoint再说一点
watchpoint不能检测内核区变量,比如网络协议栈,数据库链接,文件io
因为gdb是运行在用户区的,所以不能监控内核区变量
---------------------------------------------------
例子《gdb的watchpoint在系统调用中被修改似乎不会被触发》
https://blog.csdn.net/imred/article/details/82563599
-----------------------------------------------------
实际打印
(gdb) n
printNum
14 while(a > num && a>0)
(gdb) c
Continuing.
12
Hardware watchpoint 2: a
Old value = 12
New value = 11
printNum2 (a=11, num=5) at test.cpp:14
14 while(a > num && a>0)
(gdb) c
Continuing.
11
Hardware watchpoint 2: a
Old value = 11
New value = 10
printNum2 (a=10, num=5) at test.cpp:14
14 while(a > num && a>0)
(gdb) c
Continuing.
10
Hardware watchpoint 2: a
Old value = 10
New value = 9
printNum2 (a=9, num=5) at test.cpp:14
14 while(a > num && a>0)
(gdb)
-----------------------------------------------------
问2:watchpoint如果监视一个结构体,有指针,是深监视还是浅监视?
待解。