gdb watch 5 == i32Num变量变化到某个值时中断

root@ubuntu:/home/libz/share/project/gdb_test# gdb ./gdb_test.elf -q
Reading symbols from /home/libz/share/project/gdb_test/gdb_test.elf...done.
(gdb) break func
Breakpoint 1 at 0x8048946: file ./gdb_test.c, line 36.
(gdb) r
Starting program: /home/libz/share/project/gdb_test/gdb_test.elf
[Thread debugging using libthread_db enabled]
[New Thread 0xb7fecb70 (LWP 29620)]
[Switching to Thread 0xb7fecb70 (LWP 29620)]

Breakpoint 1, func () at ./gdb_test.c:36
36              pthread_mutex_lock(&g_mutex_thread);
(gdb) info breakpoints
Num     Type           Disp Enb Address    What
1       breakpoint     keep y   0x08048946 in func at ./gdb_test.c:36
        breakpoint already hit 1 time
(gdb) delete 1
(gdb) l
31      {
32          static INT32_T i32Num = 0;
33          static char    p[10] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j' };
34
35          while (1) {
36              pthread_mutex_lock(&g_mutex_thread);
37
38               printf("g_stPid = [%d] i32Num = [%d]\n", (UINT32_T)g_stPid, i32Num++);
39
40              pthread_mutex_unlock(&g_mutex_thread);
(gdb)
41              sleep(1);
42          }
43      }
44
45      void create_thread(void)
46      {
47          pthread_attr_t stAttr;
48          struct sched_param sched_proi;
49
50          memset(&sched_proi, 0x0, sizeof(sched_proi));
(gdb) s
__pthread_mutex_lock (mutex=0x804a0d4) at pthread_mutex_lock.c:47
47      pthread_mutex_lock.c: No such file or directory.
        in pthread_mutex_lock.c
(gdb) finish
Run till exit from #0  __pthread_mutex_lock (mutex=0x804a0d4) at pthread_mutex_lock.c:47
func () at ./gdb_test.c:38
38              printf("g_stPid = [%d] i32Num = [%d]\n", (UINT32_T)g_stPid, i32Num++);
Value returned is $1 = 0
(gdb) s
__printf (format=0x8048d90 "g_stPid = [%d] i32Num = [%d]\n") at printf.c:30
30      printf.c: No such file or directory.
        in printf.c
(gdb) finish
Run till exit from #0  __printf (format=0x8048d90 "g_stPid = [%d] i32Num = [%d]\n") at printf.c:30
g_stPid = [-1208038544] i32Num = [0]
func () at ./gdb_test.c:40
40              pthread_mutex_unlock(&g_mutex_thread);
Value returned is $2 = 37
(gdb) watch 5 == i32Num
Hardware watchpoint 2: 5 == i32Num

(gdb) c
Continuing.
g_stPid = [-1208038544] i32Num = [1]
g_stPid = [-1208038544] i32Num = [2]
g_stPid = [-1208038544] i32Num = [3]
Hardware watchpoint 2: 5 == i32Num

Old value = 0
New value = 1
0x08048961 in func () at ./gdb_test.c:38
38              printf("g_stPid = [%d] i32Num = [%d]\n", (UINT32_T)g_stPid, i32Num++);
(gdb) print i32Num
$3 = 5

(gdb)
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值