gdb-watch

watch  -- 监视变量值

源程序:

/********************************************************
                include
 *******************************************************/
#include <stdio.h>
#include <string.h>

/*******************************************************
                define
 *******************************************************/
#define MAX_NAME_LEN    (15)

typedef unsigned char BYTE_T;
typedef int           INT32_T;
typedef unsigned int  UINT32_T;

INT32_T g_i32WatchNum = 0;

BYTE_T  g_pu8Str[15] = "global char";

/********************************************************/

int main(int argc, char *argv[])
{
    printf("%s\n", g_pu8Str);
    printf("start watch valiable\n");
    memcpy(g_pu8Str, "ppp\n", sizeof("ppp\n"));
    printf("%s\n", g_pu8Str);
    memcpy(g_pu8Str, "bbb\n", sizeof("bbb\n"));
    printf("geb_test\n");
    getchar();
}


编译:

gcc -g ./gdb_test.c

调试:

root@ubuntu:/home/commander/project/gdb_test# clear

root@ubuntu:/home/commander/project/gdb_test# gdb ./a.out
GNU gdb (Ubuntu/Linaro 7.3-0ubuntu2) 7.3-2011.08
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /home/commander/project/gdb_test/a.out...done.
(gdb) watch g_pu8Str
Watchpoint 1: g_pu8Str
(gdb) r
Starting program: /home/commander/project/gdb_test/a.out
global char
start watch valiable
Watchpoint 1: g_pu8Str

Old value = "global char\000\000\000"                                                                   --------------  断点触发,旧值global char
New value = "ppp\nal char\000\000\000"                                                               -------------- 断点触发后,更新的值"ppp\nal char\0
0x08048443 in main (argc=1, argv=0xbffff734) at ./gdb_test.c:26                    -------------- 断点于 gdb_test.c文件26行
26        memcpy(g_pu8Str, "ppp\n", sizeof("ppp\n"));
(gdb)

(gdb)
(gdb)
(gdb) c                                                                                                                         -------------- 继续执行 continue
Continuing.
Watchpoint 1: g_pu8Str                                                                                          ---------------再次中断于第一个监视的变量,访问触发 watchpoint 1:g_pu8Str

Old value = "ppp\nal char\000\000\000"                                                           
New value = "ppp\n\000l char\000\000\000"
main (argc=1, argv=0xbffff734) at ./gdb_test.c:27
27        printf("%s\n", g_pu8Str);
(gdb)                                                                                                                         ----------------直接回车,相当于继续输入continue命令
Continuing.
ppp


Watchpoint 1: g_pu8Str

Old value = "ppp\n\000l char\000\000\000"                                                    ----------------g_pu8Str变量值更改,断点
New value = "bbb\n\000l char\000\000\000"
0x08048464 in main (argc=1, argv=0xbffff734) at ./gdb_test.c:28
28        memcpy(g_pu8Str, "bbb\n", sizeof("bbb\n"));
(gdb)
Continuing.
geb_test


[Inferior 1 (process 2981) exited with code 012]
(gdb) l                                                                                                                    ----------------源代码列出      
23    {
24        printf("%s\n", g_pu8Str);
25        printf("start watch valiable\n");
26        memcpy(g_pu8Str, "ppp\n", sizeof("ppp\n"));
27        printf("%s\n", g_pu8Str);
28        memcpy(g_pu8Str, "bbb\n", sizeof("bbb\n"));
29        printf("geb_test\n");
30        getchar();
31    }
(gdb)




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值