免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1310 | 回复: 3
打印 上一主题 下一主题

请教一个gdb的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-06-22 13:12 |只看该作者 |倒序浏览
根据网上的一篇文章在学习gdb时遇到了下面的问题,盼高手指教。
程序代码如下:
#include <iostream>;
using namespace std;
void my_print(char *my_string);
void my_print2(char *my_string);
int main(void)
{
        char my_string[]="Hello!";
        my_print(my_string);
        cout<<endl;
        my_print2(my_string);
}
void my_print(char *my_string)
{
        cout<<"The string in normal secquence is :  "
                 <<my_string;
}
void my_print2(char *my_string)
{
        char *string2;
        int size,i;
        int size2;
        size=strlen(my_string);
        size2=size-1;
        string2=(char *)malloc(size+1);
        for(i=0;i<size;i++)
                string2[size2-i]=my_string;
        string2[size]='\0';
        cout<<"The string printed backward is:      "
                 <<string2;
        cout<<endl;
}
编译时用的命令: g++ -g Hello.cpp
调试顺序如下:
        gdb a.out
        run
        list
        list
        list
        break 27
提示:
       Breakpoint 1, my_print2 (my_string=0xfeff13d0 "Hello!" at Hello.cpp:27
       27                      string2[size2-i]=my_string;

然后    run
        watch string2[size2-i]
提示:Hardware watchpoint 2: string2[size2 - i]
再执行:next
提示:warning: Could not remove hardware watchpoint 2.
Warning:
Could not insert hardware watchpoint 2.
Could not insert hardware breakpoints:
You may have requested too many hardware breakpoints/watchpoints.
而按照文章说的,输出应该有
                         Old value=
                         New value=
之类的输出才对。
我自己写的程序就很正常:
#include <iostream>;
using namespace std;
int main()
{
        int i=0;
        for(int j=0;j<200;j++)
                i+=1;
        cout<<i;
}

调试如下:
(gdb) break 7
Breakpoint 1 at 0x80486eb: file test.cpp, line 7.
(gdb) run
Starting program: /home/zha/workspace/Hello/a.out

Breakpoint 1, main () at test.cpp:7
7                       i+=1;
(gdb) watch i
Hardware watchpoint 2: i
(gdb) next
Hardware watchpoint 2: i

Old value = 0
New value = 1
main () at test.cpp:6
6               for(int j=0;j<200;j++)
(gdb)

哪位能给解释一下,谢谢!

论坛徽章:
0
2 [报告]
发表于 2005-06-22 17:55 |只看该作者

请教一个gdb的问题

不用理会那些警告,只管继续next下去看看

论坛徽章:
0
3 [报告]
发表于 2005-06-22 18:12 |只看该作者

请教一个gdb的问题

但是看不到string2[]值的变化呀,这才是我想要的。

论坛徽章:
0
4 [报告]
发表于 2005-06-22 20:48 |只看该作者

请教一个gdb的问题


  1. [zdai@localhost test]$ gdb
  2. GNU gdb Red Hat Linux (5.1-1)
  3. Copyright 2001 Free Software Foundation, Inc.
  4. GDB is free software, covered by the GNU General Public License, and you are
  5. welcome to change it and/or distribute copies of it under certain conditions.
  6. Type "show copying" to see the conditions.
  7. There is absolutely no warranty for GDB.  Type "show warranty" for details.
  8. This GDB was configured as "i386-redhat-linux".
  9. (gdb) file exit_free
  10. Reading symbols from exit_free...done.
  11. (gdb) list
  12. 1       init.c: No such file or directory.
  13.         in init.c
  14. (gdb)
复制代码

我怎么连list都不行啊,看代码也看不了请教了
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP