GDB内存断点(Memory break)的使用举例

本博客(http://blog.csdn.net/livelylittlefish)贴出作者(三二一@小鱼)相关研究、学习内容所做的笔记,欢迎广大朋友指正!

 

GDB内存断点(Memory break)的使用举例

  •  

    本文是一篇使用GDB设置内存断点的例子。

     

    1. 源程序

     

    文件名:testMemBreak.c

    #include <stdio.h>

    #include <string.h>

     

    int main()

    {

        int i,j;

        char buf[256]={0};

        char* pp = buf;

     

        printf("buf addr= 0x%x/r/n",buf);

        for(i=0;i<16;i++)

        {

            printf("addr = 0x%x ~ 0x%x/r/n",pp+i*16,pp+i*16+15);

            for(j=0;j<16;j++)

                *(pp+i*16+j)=i*16+j;

        }

     

        printf("ASCII table:/n");

        for(i=0;i<16;i++)

        {

            for(j=0;j<16;j++)

                printf("%c  ", *(pp+i*16+j));

            printf("/n");

        }

       

        return 0;

     

    }

     

    即完成ASCII码的初始化并打印出来。

     

    要使用的GDB命令,如下。

    (gdb) help watch

    Set a watchpoint for an expression.

    A watchpoint stops execution of your program whenever the value of

    an expression changes.

    (gdb) help rwatch

    Set a read watchpoint for an expression.

    A watchpoint stops execution of your program whenever the value of

    an expression is read.

    (gdb) help awatch

    Set a watchpoint for an expression.

    A watchpoint stops execution of your program whenever the value of

    an expression is either read or written.

    (gdb)

     

    2. 调试过程

     

    2.1 设置断点并启动程序完成初始化

     

    启动程序对其进行初始化,并使用display自动显示buf的地址。

     

    $ gcc -g -o membreak testMemBreak.c

     

    $ gdb ./membreak.exe

    GNU gdb 6.3.50_2004-12-28-cvs (cygwin-special)

    Copyright 2004 Free Software Foundation, Inc.

    GDB is free software, covered by the GNU General Public License, and you are

    welcome to change it and/or distribute copies of it under certain conditions.

    Type "show copying" to see the conditions.

    There is absolutely no warranty for GDB.

  • 0
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值